Skip to content

[Bug]: clicking on a link before loadURL has resolved causes the promise to reject, even if the link navigation was prevented #28338

Closed as not planned

Description

@pushkin-

Preflight Checklist

Electron Version

12.0.1, 11.2.1

What operating system are you using?

Windows

Operating System Version

Windows 10 v1909

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

I expect that calling preventDefault in the will-navigate handler will prevent us from attempting the navigation

Actual Behavior

This doesn't seem to happen if we're in the middle of a loadURL call

Testcase Gist URL

No response

this issue may very well be a dupe of this one and related to this one though I'm not calling loadURL twice.

I'm experiencing an issue in my app where if there's network delay, I make a loadURL and click a link on the main page before loadURL has finished, we get an ERR_ABORTED error. From reading in other issues, this is expected when a navigation happens in the middle of a navigation.

So I attempted to solve this by canceling the navigation in the will-navigate handler when the main window's webcontents are still loading (isLoadingMainFrame()), however, this doesn't solve the crash. The navigation is prevented, but WebContents::did-start-navigation has already fired for whatever reason (I'd expect it to fire after will-navigate), and we get the crash

  1. add network delay. What I did was start Fiddler, Rules -> Performance -> Simulate Modem speeds
  2. start main.js
  3. Click a link (like the "Sign Up" link)
  4. observe crash:

image

main.js:

(async () => {
	const { app, BrowserWindow, dialog } = require("electron");
	app.on("window-all-closed", async () => {
		app.quit();
	});

	await app.whenReady();
	const mainWindow = new BrowserWindow();
	mainWindow.webContents.on("will-navigate", (e) => {
		if (mainWindow.webContents.isLoadingMainFrame()) {
			e.preventDefault();
		}
	});
	try {
		await mainWindow.loadURL("https://github.com/");
	}
	catch (e) {
		dialog.showErrorBox("Error", e.message);
	}
})();

Activity

  1. nornagon commented on Mar 22, 2021

    @nornagon
    Contributor

    Here's a Fiddle version using an in-process server that responds slowly: https://gist.github.com/0926377bbb9d14cd9319f8d26698e543

    This is somewhat intentional: we explicitly listen to did-start-navigation and cancel the promise with ERR_ABORTED in navigation-controller.ts:

    this.webContents.on('did-start-navigation', navigationListener);

    Both will-navigate and did-start-navigation are pretty direct exposures of the underlying Chromium callbacks. Perhaps we should be hooking something other than did-start-navigation in loadURL to reject the promise if the page is navigated away before finishing the load?

    side note, i'm changing the title here to reflect that this is a rejected promise rather than a crash per se.

  2. changed the title [-][Bug]: clicking on a link before loadURL has resolved causes a crash[/-] [+][Bug]: clicking on a link before loadURL has resolved causes a rejection, even if the link navigation was prevented[/+] on Mar 22, 2021
  3. changed the title [-][Bug]: clicking on a link before loadURL has resolved causes a rejection, even if the link navigation was prevented[/-] [+][Bug]: clicking on a link before loadURL has resolved causes the promise to reject, even if the link navigation was prevented[/+] on Mar 22, 2021
  4. 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!

  5. pushkin- commented on Oct 7, 2022

    @pushkin-
    Author

    repros in Electron 21

  6. github-actions commented on Jan 10, 2023

    @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. pushkin- commented on Jan 12, 2023

    @pushkin-
    Author

    repros in v22

  8. github-actions commented on Apr 14, 2023

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

  9. pushkin- commented on Apr 14, 2023

    @pushkin-
    Author

    bump

  10. github-actions commented on Jul 14, 2023

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

  11. pushkin- commented on Jul 14, 2023

    @pushkin-
    Author

    bump

  12. electron-issue-triage commented on Oct 14, 2023

    @electron-issue-triage

    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!

  13. pushkin- commented on Oct 16, 2023

    @pushkin-
    Author

    my original gist repros in v27. The gist by nornagon stopped being repro-able for several versions already for a reason I didn't dig into.

  14. electron-issue-triage commented on Jan 15, 2024

    @electron-issue-triage

    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!

  15. electron-issue-triage commented on Feb 15, 2024

    @electron-issue-triage

    This issue has been closed due to inactivity, and will not be monitored. If this is a bug and you can reproduce this issue on a supported version of Electron please open a new issue and include instructions for reproducing the issue.

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