为什么 Chrome(在 Electron 内部)会突然重定向到 chrome-error://chromewebdata?

我的电子应用程序随机重定向到 chrome-error://chromewebdata,我不知道为什么.控制台等没有错误.

My electron app is randomly redirecting to chrome-error://chromewebdata, and I've no idea why. There's no errors in the console, etc.

当 Electron 应用程序第一次启动时,窗口打开,它从我的应用程序重定向到该 URL,我看到一个空白的空白屏幕.无需用户交互,只需在应用启动时进行.

When the Electron app first starts, the window opens, and it redirects away from my application to that URL and I see an empty blank white screen. No user interaction is necessary, it just happens when the app starts.

如果我打开 devtools,我可以看到 window.location.href 包含 chrome-error://chromewebdata 而不是 http://localhost:9080(Electron 应用程序使用 localhost URL 运行).

If I open devtools, I can see that window.location.href contains chrome-error://chromewebdata instead of http://localhost:9080 (the Electron app runs using a localhost URL).

我尝试删除 ~/Library/Application Support/my-app-name 的本地 Electron/Chrome 数据文件夹并重新开始,但没有成功.

I tried deleting the local Electron/Chrome data folder at ~/Library/Application Support/my-app-name and starting over, but no luck.

Chrome(在 Electron 中?)可以决定重定向到 chrome-error://chromewebdata 的原因是什么?

What are reasons that Chrome (in Electron?) can decide to redirect to chrome-error://chromewebdata?

推荐答案

由于某种原因,您的代码试图导航到无效(不存在)的 URL,然后导致 window.location.hrefchrome-error://chromewebdata.

For some reason, your code is trying to navigate to an invalid (non-existing) URL, which then results in window.location.href being chrome-error://chromewebdata.

重申一下:没有直接重定向到 chrome-error://chromewebdata,而是重定向到不存在或无法访问的 URL.

To reiterate: there is no direct redirection to chrome-error://chromewebdata, but instead to a URL that doesn't exist or is not reachable.

检查您的代码是否会导致此导航(可能是重定向).检查 DevTools 中的 Network 选项卡非常有用,确保选中Preserve log".这应该可以说明到底发生了什么.

Check if your code causes this navigation (possibly a redirect). It is very useful to inspect the Network tab in DevTools, making sure that "Preserve log" is checked. This should give some indication about what exactly is happening.

相关文章