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

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • 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.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 3
  • Comments: 18 (5 by maintainers)

Most upvoted comments

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.