electron icon indicating copy to clipboard operation
electron copied to clipboard

[Bug]: will-navigate doesn't fire when navigating to about: URLs

Open pushkin- opened this issue 5 years ago • 22 comments

Preflight Checklist

  • [x] I have read the Contributing Guidelines for this project.
  • [x] I agree to follow the Code of Conduct that this project adheres to.
  • [x] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: 5.0.7
  • Operating System: Windows 10

Expected Behavior

Based on the documentation, I expect that navigating to "about:blank" will trigger the webcontent's will-navigate event.

Actual Behavior

will-navigate does not get triggered.

The docs make no mention of "about:blank" being an exception, and so I expect that will-navigate should get emitted when navigating to it.

Either this is a documentation error, or it's a bug with will-navigate.

To Reproduce

const { app, BrowserWindow, BrowserView } = require('electron')

async function onReady() {
	const mainWindow = new BrowserWindow();
	const view = new BrowserView();
	view.webContents.addListener("will-navigate", (e, url) => {
		console.log("navigating to: " + url);
	});
	mainWindow.setBrowserView(view);
	await view.webContents.loadURL("https://google.com");
	view.webContents.openDevTools();
}

app.on('ready', onReady)

After npm starting, in the devtools, run location = "https://google.com". Notice that we log it.

Then run location = "about:blank". Notice, that there's no log.

pushkin- avatar Nov 14 '19 23:11 pushkin-

this is also an issue with Electron 7.1.2

pushkin- avatar Dec 10 '19 00:12 pushkin-

Still a problem in Electron 10.1.2

pushkin- avatar Sep 17 '20 16:09 pushkin-

Still a problem in Electron v11.3.0, and a fairly annoying one: I include links from external content in my app, and intercept them using will-navigate and new-window to allow HTTP links only and to redirect them to the system browser. It seems that about:blank ignores all that, and somehow some about:blank links are occasionally sneaking into some of the content I render.

If anybody clicks such a link, instead of either being blocked or opening in the system browser (both pretty reasonable) it blanks the entire app. As far as I can tell there's no other event or workaround for this available at present, so there's nothing I can do to protect against this at the Electron level.

pimterry avatar Mar 25 '21 15:03 pimterry

@pimterry Can you use onBeforeRequest to cancel the request to about:blank?

pushkin- avatar Mar 25 '21 15:03 pushkin-

@pushkin- no, that doesn't work either, it doesn't fire (presumably because there's no actual HTTP request involved).

That's with this code:

    session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
        console.log("before request to", details.url);
        callback({});
    });

It logs every other request the app makes, but no request to about:blank

pimterry avatar Mar 25 '21 16:03 pimterry

Note that it's not just about:blank, but also about:, about:anything

mckravchyk avatar Nov 11 '21 07:11 mckravchyk

The issue still occurs in 16.0.4. gist: https://gist.github.com/rzhao271/db5a33e5b332bc5f292f049be6c404a1

rzhao271 avatar Jan 06 '22 19:01 rzhao271

Bump: This is still an issue as of Electron v20.0.0.

CodeSmith32 avatar Sep 12 '22 13:09 CodeSmith32

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!

github-actions[bot] avatar Jan 10 '23 02:01 github-actions[bot]

Bump: This is still an issue as of Electron v22.0.0.

CodeSmith32 avatar Jan 10 '23 13:01 CodeSmith32

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!

github-actions[bot] avatar May 08 '23 01:05 github-actions[bot]

bump

pushkin- avatar May 09 '23 15:05 pushkin-

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!

github-actions[bot] avatar Aug 09 '23 01:08 github-actions[bot]

repros with v25.4.0

pushkin- avatar Aug 09 '23 15:08 pushkin-

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!

repros in v27

pushkin- avatar Nov 09 '23 14:11 pushkin-

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!

repros in v28 and v29-beta8

pushkin- avatar Feb 09 '24 15:02 pushkin-

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!

bump

pushkin- avatar May 11 '24 18:05 pushkin-