mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: child window may have opener removed (#38932)
* fix: child window may have opener removed Co-authored-by: Cheng Zhao <zcbenz@gmail.com> * Update chromium-spec.ts --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Cheng Zhao <zcbenz@gmail.com>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -8,7 +8,7 @@ import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as url from 'url';
|
||||
import * as ChildProcess from 'child_process';
|
||||
import { EventEmitter } from 'events';
|
||||
import { EventEmitter, once } from 'events';
|
||||
import { promisify } from 'util';
|
||||
import { ifit, ifdescribe, defer, delay, itremote } from './lib/spec-helpers';
|
||||
import { AddressInfo } from 'net';
|
||||
@@ -1147,6 +1147,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`);
|
||||
|
||||
Reference in New Issue
Block a user