Skip to content

Instantly share code, notes, and snippets.

@Gvozd
Created July 4, 2018 09:37
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gvozd/2cec0c8c510a707854e439fb15c561b0 to your computer and use it in GitHub Desktop.
Save Gvozd/2cec0c8c510a707854e439fb15c561b0 to your computer and use it in GitHub Desktop.
Facebook, OAuth login. Correct opener in window
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';
});
@sanoopjose
Copy link

It will be great if you could add the new window implementation inside the 'new-window' event handler.

mainWindow.webContents.on('new-window', function (e, url, frameName, disposition, options) {
  options.webPreferences.affinity = 'main-window';
Object.assign(options, {
      width: 100,
      height: 100
    })
    e.newGuest = new BrowserWindow(options)
});

It seems like the above code is not working.

@Gvozd
Copy link
Author

Gvozd commented Feb 11, 2019

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