Skip to content

loadURL / loadFile calls throw "ERR_ABORTED (-3) error" if location.hash or history.pushState called on the page before page loaded #17526

Closed

Description

@vladimiry

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

Activity

  1. changed the title [-]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[/+] on Mar 25, 2019
  2. changed the title [-]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[/+] on Mar 25, 2019
  3. MarshallOfSound commented on Mar 28, 2019

    @MarshallOfSound
    Member

    Hey @vladimiry

    This is currently the expected behavior, the promise that loadURL returns 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_ABORTED rejection.

  4. vladimiry commented on Mar 29, 2019

    @vladimiry
    Author

    @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:

    • Changing the hash or push state is not really navigation, the new page loading process is not involved but only the url gets changed, ie changing the hash or push state is completely happening on the client side (browser side in term of server-client scenario).
    • The currently shown error is vague, I had to look into the sources in order to understand why exactly page loading got aborted.
  5. MarshallOfSound commented on Mar 29, 2019

    @MarshallOfSound
    Member

    @vladimirkononov

    I still believe such logic is going to break a lot of SPA apps

    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.

  6. vladimiry commented on Mar 29, 2019

    @vladimiry
    Author

    @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.

    This feature was only just introduced in 5.0.0

    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.

  7. cyphercodes commented on May 1, 2019

    @cyphercodes

    This is also blocking loading dataURL like so:

    browserWindow.webContents.loadURL('data:text/html;charset=utf-8,' + encodeURIComponent(html), {
          baseURLForDataURL: httpHost,
    });
    
  8. vladimiry commented on May 1, 2019

    @vladimiry
    Author

    If you navigate before the page has completed loading you have aborted that load, hence the ERR_ABORTED rejection.

    I will just repeat. Calling history.pushState or changing the location.hash value does trigger reloading the page, so the loaded page remains the same. This is why expected behavior does not look good for me.

  9. cyphercodes commented on May 30, 2019

    @cyphercodes

    This is also blocking loading dataURL like so:

    browserWindow.webContents.loadURL('data:text/html;charset=utf-8,' + encodeURIComponent(html), {
          baseURLForDataURL: httpHost,
    });
    

    This is still happening even after 5.0.2

  10. preslavsh commented on Sep 23, 2019

    @preslavsh

    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.

  11. vladimiry commented on Sep 23, 2019

    @vladimiry
    Author

    @preslavsh you could try bootstrapping the Angular app in window.addEventListener("load" handler, ugly workaround though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions