Skip to content

[Bug]: window.document is not accessible when child window creation is overriden #43740

Closed
@CezaryKulakowski

Description

Preflight Checklist

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

  1. 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');
});
  1. Open devtools window
  2. 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

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions