electron
electron copied to clipboard
[Bug]: will-navigate doesn't fire when navigating to about: URLs
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 start
ing, in the devtools, run location = "https://google.com"
. Notice that we log it.
Then run location = "about:blank"
. Notice, that there's no log.
this is also an issue with Electron 7.1.2
Still a problem in Electron 10.1.2
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 Can you use onBeforeRequest
to cancel the request to about:blank?
@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
Note that it's not just about:blank
, but also about:
, about:anything
The issue still occurs in 16.0.4. gist: https://gist.github.com/rzhao271/db5a33e5b332bc5f292f049be6c404a1
Bump: This is still an issue as of Electron v20.0.0.
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: This is still an issue as of Electron v22.0.0.
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
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 with v25.4.0
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
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
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