Skip to content

[Bug]: BrowserWindow#loadURL() throw an error when I load same page with different location hash #28208

Closed

Description

@eternalharvest

Preflight Checklist

Electron Version

11.2.3

What operating system are you using?

Other (specify below)

Operating System Version

Windows10 Pro Version 1909 (Build 18363.1440), MacOS Big Sur 11.2.3 (20D91), Probably not depend on OS

What arch are you using?

Other (specify below)

Last Known Working Electron version

N/A

Expected Behavior

BrowserWindow#loadURL() must finish without throwing any error

Actual Behavior

BrowserWindow#loadURL() throw an error as below when load same page with different location hash

Error: ERR_FAILED (-2) loading 'asset:///test.html#section2'
    at rejectAndCleanup (electron/js2c/browser_init.js:205:1493)
    at Object.stopLoadingListener (electron/js2c/browser_init.js:205:1868)
    at Object.emit (events.js:327:22) {
  errno: -2,
  code: 'ERR_FAILED',
  url: 'asset:///test.html#section2'
}

Testcase Gist URL

https://gist.github.com/eternalharvest/e6b26f8e20d3ebf6048bd50ef8c3eb63

It is not mentioned in the official document, it seems there is option reloadIgnoringCache.
And when I call loadURL method with option which reloadIgnoringCache set to true, It seems this error is not happen.

// this code works correct (error is not happen)
mainWindow.loadURL('asset:///test.html#section2', { reloadIgnoringCache: true })
    .then(() => console.log('ok'))
    .catch(console.error);

Related Issues

Activity

  1. nornagon commented on Jun 29, 2021

    @nornagon
    Contributor

    Ah, I think this is because the loadURL promise handling expects either did-finish-load or did-fail-load to have been emitted before did-stop-loading is emitted, which doesn't happen for in-page navigations. We should be able to detect the in-page nature of the navigation and avoid emitting the error.

    Relevant code:

    const stopLoadingListener = () => {
    // By the time we get here, either 'finish' or 'fail' should have fired
    // if the navigation occurred. However, in some situations (e.g. when
    // attempting to load a page with a bad scheme), loading will stop
    // without emitting finish or fail. In this case, we reject the promise
    // with a generic failure.
    // TODO(jeremy): enumerate all the cases in which this can happen. If
    // the only one is with a bad scheme, perhaps ERR_INVALID_ARGUMENT
    // would be more appropriate.
    rejectAndCleanup(-2, 'ERR_FAILED', url);
    };

  2. gpetrov commented on Oct 15, 2021

    @gpetrov

    @nornagon As an additional case, this error seems to happen if the page code has an onbeforeunload event handler that blocks the unload. Then the same 'GUEST_VIEW_MANAGER_CALL': Error: ERR_FAILED (-2) happens and the loadURL fails.

  3. lzdyes commented on Feb 10, 2022

    @lzdyes

    Can this problem be fixed?

  4. Rodeoclash commented on May 18, 2022

    @Rodeoclash

    I was tearing my hair out today with this bug getting Electron to play nicely with Keycloak. Does anybody have a workaround?

  5. Rodeoclash commented on May 18, 2022

    @Rodeoclash

    One very crude workaround is to trigger a reload from the main thread after the attempted redirect. This will at least load the intended page with the anchors on it.

  6. github-actions commented on Oct 6, 2022

    @github-actions
    Contributor

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  7. nbabanov commented on Oct 7, 2022

    @nbabanov

    I've just ran into the same error...
    @MarshallOfSound Could you please have a look?

    I reproduce it with Electron v16.2.3.

    1. Open a page with a webview
    2. Fire a loadURL() with the same url of the loaded page + an anchor and voila.

    At least please make those errors catch-able in the place where loadURL() was called.

  8. RecuencoJones commented on Oct 27, 2025

    @RecuencoJones

    Instead of calling browserWindow.webContents.reloadIgnoringCache() after getting ERR_FAILED (-2) I'm using browserWindow.webContents.session.clearCache() before browserWindow.loadURL() and it seems to work fine.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions