Closed magne4000 closed 5 years ago
Origin chrome-extension
is now a secure origin in the renderer
Blocked by https://github.com/electron/electron/issues/17989 (workaround for https://github.com/electron/electron/issues/18032).
Tried to hook with an event listener like this:
const hookWindowOpen = (webContents) => {
webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
event.preventDefault()
Object.assign(options, {
show: false,
width: 600,
height: 800,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, '../renderer/init.js')
}
})
console.log(options);
const win = new BrowserWindow(options);
win.once('ready-to-show', () => {
win.show()
console.log(url)
win.webContents.loadURL('https://github.com')
})
event.newGuest = win;
})
}
app.on('web-contents-created', function (event, webContents) {
hookWindowOpen(webContents)
})
the window.opener
stay null after navigation and preloads doesn't load. Really related to the process model IMO.
BrowserWindow
Try with the main browser window instead of the webview
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
webviewTag: true,
contextIsolation: false,
nativeWindowOpen: true,
}
});
mainWindow.loadURL('https://mail.google.com');
}
...
It's the same behavior than our webview:
window.open('https://mail.google.com')
, opener available but not preloadswindow.open('https://github.com')
, opener not accessible and preloads loadednewGuest
on new-open
mainWindow.webContents.on('new-window', (event, url, frameName, disposition, options, additionalFeatures) => {
...
})
The options include the embedder through options.webContents
which is the reference for window.opener
.
In all case, if we create an orphan
browser window, the opener is null and preloads are loaded.
setup: the opener is webview with domain mail.google.com
new-open
event for loading mail.google.com
: the opener is available but preloads are missingnew-open
event for loading github.com
: the opener is null but preloads are loaded new-open
event for loading mail.google.com
then navigate to GitHub.com
then back to mail.google.com
: the opener is null and preloads are loaded
Diff description
window.opener
reference with native window open (https://github.com/electron/electron/issues/18032)