Created
July 4, 2018 09:37
-
-
Save Gvozd/2cec0c8c510a707854e439fb15c561b0 to your computer and use it in GitHub Desktop.
Facebook, OAuth login. Correct opener in window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mainWindow = new BrowserWindow({ | |
webPreferences: { | |
nativeWindowOpen: true,// window.open return Window object(like in regular browsers), not BrowserWindowProxy | |
affinity: 'main-window'// main window, and addition windows should work in one process | |
} | |
}); | |
mainWindow.webContents.on('new-window', function (e, url, frameName, disposition, options) { | |
// hook on new opened window | |
// at now new window in mainWindow renderer process. | |
// Also, this will automatically get an option `nodeIntegration=false`(not override to true, like in iframe's) - like in regular browsers | |
options.webPreferences.affinity = 'main-window'; | |
}); |
This worked(in your example, prevention is forgotten):
mainWindow.webContents.on('new-window', function (e, url, frameName, disposition, options) {
options.webPreferences.affinity = 'main-window';
Object.assign(options, {
width: 100,
height: 500
})
// not really need uncomment next lines. not sure, but navigation(in child window) may break, or something else
// e.newGuest = new BrowserWindow(options)
// e.preventDefault();
});
I also want to note that the workaround works only in the electron@2
In my last tests, this solution not actually worked at electron@3-4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It will be great if you could add the new window implementation inside the 'new-window' event handler.
It seems like the above code is not working.