[Bug]: window.document is not accessible when child window creation is overriden #43740
Closed
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 a bug report that matches the one I want to file, without success.
Electron Version
33.0.0-nightly.20240808
What operating system(s) are you using?
macOS
Operating System Version
macOS 14.6.1
What arch are you using?
arm64 (including Apple Silicon)
Last Known Working Electron version
No response
Reproduction steps
- Start following app:
const {app, BrowserWindow, BrowserView} = require('electron')
app.once('ready', async () => {
window = new BrowserWindow({
width: 800,
height: 600,
show: true
})
window.webContents.setWindowOpenHandler(({ url }) => {
console.log(`open window: ${url}`);
return {
action: 'allow',
createWindow: (options) => {
const child = new BrowserWindow({
webContents: options?.webContents,
webPreferences: options?.webPreferences
});
return child.webContents;
}
}
});
await window.webContents.loadURL('https://www.example.com');
});
- Open devtools window
- Execute:
let win = window.open('about:blank')
Expected Behavior
win.document can be accessed
Actual Behavior
win.document can't be accessed: it fails with error:
Uncaught SecurityError: Failed to read a named property 'document' from 'Window': Blocked a frame with origin "https://www.example.com" from accessing a cross-origin frame.
Testcase Gist URL
No response
Additional Information
win.document
can be accessed when child window creation is not overriden by WebContents::setWindowOpenHandler
.
No response