Skip to content

Commit

Permalink
fix: child window may have opener removed (electron#38910)
Browse files Browse the repository at this point in the history
  • Loading branch information
zcbenz authored and MrHuangJser committed Dec 11, 2023
1 parent 3b05fd6 commit a501761
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shell/renderer/electron_render_frame_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void ElectronRenderFrameObserver::DidClearWindowObject() {
// Check DidInstallConditionalFeatures below for the background.
auto* web_frame =
static_cast<blink::WebLocalFrameImpl*>(render_frame_->GetWebFrame());
if (has_delayed_node_initialization_ && web_frame->Opener() &&
if (has_delayed_node_initialization_ &&
!web_frame->IsOnInitialEmptyDocument()) {
v8::Isolate* isolate = blink::MainThreadIsolate();
v8::HandleScope handle_scope(isolate);
Expand Down
17 changes: 17 additions & 0 deletions spec/chromium-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,23 @@ describe('chromium features', () => {
expect(eventData).to.equal('size: 350 450');
});

it('loads preload script after setting opener to null', async () => {
const w = new BrowserWindow({ show: false });
w.webContents.setWindowOpenHandler(() => ({
action: 'allow',
overrideBrowserWindowOptions: {
webPreferences: {
preload: path.join(fixturesPath, 'module', 'preload.js')
}
}
}));
w.loadURL('about:blank');
w.webContents.executeJavaScript('window.child = window.open(); child.opener = null');
const [, { webContents }] = await once(app, 'browser-window-created');
const [,, message] = await once(webContents, 'console-message');
expect(message).to.equal('{"require":"function","module":"undefined","process":"object","Buffer":"function"}');
});

it('disables the <webview> tag when it is disabled on the parent window', async () => {
const windowUrl = url.pathToFileURL(path.join(fixturesPath, 'pages', 'window-opener-no-webview-tag.html'));
windowUrl.searchParams.set('p', `${fixturesPath}/pages/window-opener-webview.html`);
Expand Down

0 comments on commit a501761

Please sign in to comment.