Repository navigation
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
- Electron Version: 4.0.4
- Operating System: Windows 10
- Last Known Working Electron version:: 1.8.8
Expected Behavior
I create a BrowserWindow with nativeWindowOpen set to true. It points to a page with a webview that is navigated to a site. I call window.open("somesite") from that page, and the new window's window.opener property is set.
Actual Behavior
window.opener is null
To Reproduce
main.js:
const { app, BrowserWindow } = require('electron')
function createWindow() {
const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
nativeWindowOpen: true
}
});
mainWindow.webContents.once("did-finish-load", () => {
mainWindow.webContents.send("loadUrl");
});
mainWindow.loadFile('index.html')
app.on("browser-window-created", (event, window) => {
window.webContents.on("did-finish-load", () => {
window.webContents.openDevTools();
});
});
}
app.on('ready', createWindow)
app.on('window-all-closed', app.quit);
index.html:
<body>
<webview id="w" src="about:blank;" allowpopups></webview>
<script>
require('./renderer.js');
</script>
</body>
renderer.js:
const { ipcRenderer } = require("electron");
const webview = document.getElementById("w");
ipcRenderer.once("loadUrl", () => {
webview.openDevTools();
webview.loadURL("https://google.com");
});
However, if I load the URL on a setTimeout:
ipcRenderer.once("loadUrl", () => {
webview.openDevTools();
setTimeout(() => {
webview.loadURL("https://google.com");
}, 1000);
});
window.opener is set correctly when I open windows...
What is going on here? Why does navigating the webview inside of a setTimeout work, but not when navigating it when the webcontents have finished loading. It looks like Electron needs a little more time to set everything up correctly.
I'll also note that logging win.opener from the window that opens the new window shows an opener. Logging it from the new window doesn't:
Main window:
var w = window.open("https://google.com");
w.opener // correct
Window I just launched:
window.opener // null
Additional info:
Replacing webview with BrowserView appears to resolve the issue. However, there is a peculiar inconsistency it seems between BrowserView and regular Chrome. If I navigate my BrowserView to an http google.com, and open an https google.com window, window.opener is null, but I can't reproduce that behavior from Chrome when I open an https site from an http one.
If I navigate my BrowserView to an https site and open an https window from there, window.opener is set.
Side note: As can be seen from the Last Working Electron version bullet point, this used to work for me (when I was on 1.7; tested on 1.8.8 and works there too). I believe I started seeing this issue when I cleared the cache.
Activity
maxerbox commentedon Apr 19, 2019
There is another issue (maybe related?) with window.open, it is returning a null object. I went through this with:
pushkin- commentedon Apr 19, 2019
Huh, looks like setting the
srcof the webview toabout:blank;is causing the issue. Rather, initially setting it to a non-https site breaks this.webview.srctohttps://google.comloadURL("https://google.com")(without thesetTimeout)window.openeris correctly set!codebytere commentedon Jun 7, 2019
Closed by #18173