Repository navigation
Closed
Labels
Description
Electron v5.0.0-beta.6 will likely break every single page application / SPA that uses routing as it's uncommon to trigger the routing only after the page loading event has been fired. See workaround in additional Information section below.
Issue Details
- Electron Version:
- 5.0.0-beta.6 +
- Operating System:
- any (tested on linux)
- Last Known Working Electron version:
- 4.1.1
Expected Behavior
Page loading completes without errors even if that's a SPA.
Actual Behavior
window.location.hash = '123'called on page:
{ Error: ERR_ABORTED (-3) loading 'file:////dev/temp/electron-loadurl-issue/page.html#123'
at rejectAndCleanup (//dev/temp/electron-loadurl-issue/node_modules/electron/dist/resources/electron.asar/browser/navigation-controller.js:72:21)
at WebContents.navigationListener (//dev/temp/electron-loadurl-issue/node_modules/electron/dist/resources/electron.asar/browser/navigation-controller.js:93:20)
at WebContents.emit (events.js:193:15)
errno: -3,
code: 'ERR_ABORTED',
url:
'file:////dev/temp/electron-loadurl-issue/page.html#123' }
history.pushState({}, "title", "url")called on page:
{ Error: ERR_ABORTED (-3) loading 'file:////dev/temp/electron-loadurl-issue/url'
at rejectAndCleanup (//dev/temp/electron-loadurl-issue/node_modules/electron/dist/resources/electron.asar/browser/navigation-controller.js:72:21)
at WebContents.navigationListener (//dev/temp/electron-loadurl-issue/node_modules/electron/dist/resources/electron.asar/browser/navigation-controller.js:93:20)
at WebContents.emit (events.js:193:15)
errno: -3,
code: 'ERR_ABORTED',
url: 'file:////dev/temp/electron-loadurl-issue/url' }
To Reproduce
- main.js:
const path = require("path");
const url = require("url");
const {app, BrowserWindow} = require("electron");
app.on("ready", async () => {
const browserWindow = new BrowserWindow();
browserWindow.webContents.on("did-start-navigation", (event, url) => {
console.log("did-start-navigation", {url});
});
try {
await browserWindow.loadURL(
url.format({
protocol: "file",
slashes: true,
pathname: path.join(__dirname, "page.html")
})
);
} catch (e) {
console.error(e);
}
// "loadFile" gives the same result
// try {
// await browserWindow.loadFile(
// path.join(__dirname, "page.html"),
// );
// } catch (e) {
// console.error(e);
// }
});- page.html:
<!DOCTYPE html>
<html>
<body>
<script>
window.location.hash = '123';
// history.pushState({}, "title", "url"); // second case
</script>
</body>
</html>Screenshots
N/A
Additional Information
The workaround is changing the hash / history state afte page got loaded:
<!DOCTYPE html>
<html>
<script>
function onload() {
window.location.hash = '123';
// history.pushState({}, "title", "url"); // second case
}
</script>
<body onload="onload">
</body>
</html>See relater PR #15855 and code line https://github.com/electron/electron/pull/15855/files#diff-fc5b6704bed639bfab5927de1eccbcc3R85
CC @nornagon
Reacted by Masaru Irisawa 入澤 賢
Activity
[-]loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if window.location.hash or history.pushState called on the page[/-][+]loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if window.location.hash or history.pushState called on the page befor page loaded[/+][-]loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if window.location.hash or history.pushState called on the page befor page loaded[/-][+]loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if location.hash or history.pushState called on the page before page loaded[/+]MarshallOfSound commentedon Mar 28, 2019
Hey @vladimiry
This is currently the expected behavior, the promise that
loadURLreturns will be rejected if the renderer for whatever reason fails to completely load that URL.If you navigate before the page has completed loading you have aborted that load, hence the
ERR_ABORTEDrejection.vladimiry commentedon Mar 29, 2019
@MarshallOfSound I still believe such logic is going to break a lot of SPA apps, but I got it that it's expected behavior. There are a few points I'd like you to consider:
MarshallOfSound commentedon Mar 29, 2019
@vladimirkononov
How can it break apps? This feature was only just introduced in
5.0.0, it didn't exist in any other state before that version.vladimiry commentedon Mar 29, 2019
@MarshallOfSound Single page applications often use routing based on either html5 history api (push state thing) or url hash. Normally SPA doesn't wait for the full page loading but starts working asap which means html5 hitstory or url hash might be changed before page got fully loaded and it doesn't mean that a new page starts loading but it's only the client side url change. This is actually how I noticed the problem in action. See applied workaround here
https://github.com/vladimiry/ElectronMail/blob/0fb48fa16fe4dcf0370a9004c4556f0716941377/src/web/src/environments/production/bootstrap-app.ts#L10 as an example.
Correct. I started trying v5 beta in action and I open issues if I face bugs or blockers (this one, for example, got successfully fixed). I think it's better to handle the apparent issue before final v5 release gets published.
I think at least making the error message more detailed would be a good idea.
cyphercodes commentedon May 1, 2019
This is also blocking loading dataURL like so:
vladimiry commentedon May 1, 2019
I will just repeat. Calling
history.pushStateor changing thelocation.hashvalue does trigger reloading the page, so the loaded page remains the same. This is whyexpected behaviordoes not look good for me.cyphercodes commentedon May 30, 2019
This is still happening even after 5.0.2
web: get back immediate bootstrapping
web: get back immediate bootstrapping
preslavsh commentedon Sep 23, 2019
Still happening in 6.0.9. I not sure what the proper behavior should be, but it causes pain when I want to load angular hash route from electron. My case is notification window should open hash route on the main window.
vladimiry commentedon Sep 23, 2019
@preslavsh you could try bootstrapping the Angular app in
window.addEventListener("load"handler, ugly workaround though.web: get back immediate bootstrapping