From 09669f9d215ceb96d7f02f9085d7906e27c2b301 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 27 Jun 2023 06:04:54 +0900 Subject: [PATCH] fix: child window may have opener removed (#38910) --- .../renderer/electron_render_frame_observer.cc | 2 +- spec/chromium-spec.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/shell/renderer/electron_render_frame_observer.cc b/shell/renderer/electron_render_frame_observer.cc index 11fedbf35e1..f96362f9d2b 100644 --- a/shell/renderer/electron_render_frame_observer.cc +++ b/shell/renderer/electron_render_frame_observer.cc @@ -63,7 +63,7 @@ void ElectronRenderFrameObserver::DidClearWindowObject() { // Check DidInstallConditionalFeatures below for the background. auto* web_frame = static_cast(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); diff --git a/spec/chromium-spec.ts b/spec/chromium-spec.ts index 06fd360ab5a..c0756428474 100644 --- a/spec/chromium-spec.ts +++ b/spec/chromium-spec.ts @@ -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 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`);