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

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

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions