-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support the setWindowOpenHandler API in Electron 12+ #92
Comments
Hello Mitch! I added to the About your question, the
app.on('web-contents-created', (createEvent, contents) => {
contents.on('new-window', newEvent => {
console.log("Blocked by 'new-window'")
newEvent.preventDefault();
});
contents.on('will-navigate', newEvent => {
console.log("Blocked by 'will-navigate'")
newEvent.preventDefault()
});
contents.setWindowOpenHandler(({ url }) => {
if (url.startsWith("https://doyensec.com/")) {
setImmediate(() => {
shell.openExternal(url);
});
return { action: 'allow' }
} else {
console.log("Blocked by 'setWindowOpenHandler'")
return { action: 'deny' }
}
})
});
Originally posted by @phosphore in electron/electron#27967 (comment) |
I'm still getting an error flagged in 1.9.1 from
|
This should now be resolved with v1.10. The issue was solved in ElectroNG since its early releases, but now I've ported it to electronegativity. |
@phosphore This still seems to produce a warning (see the above PR), am I doing something wrong? Our usage of |
No, it LGTM. Could you try again with the latest d0d4445? Thanks for catching that. |
Thanks for the quick response, looks like it's fixed! |
Is your feature request related to a problem? Please describe.
Electron 12 has a new API to capture and prevent window creation,
webContents.setWindowOpenHandler
. See: https://www.electronjs.org/docs/tutorial/security#how-10.The existing
new-window
event has been deprecated.Describe the solution you'd like
LIMIT_NAVIGATION_JS_CHECK
should detect the presence of the new handler API and treat it the same way as thenew-window
event, assuming it is an appropriate alternative (or addition).Describe alternatives you've considered
It's possible to continue using the deprecated event. It is not entirely clear to me how these APIs interact when used together, or whether they are completely interchangeable .
The text was updated successfully, but these errors were encountered: