From 0f16575eee89c6ca658beceb138eee94ace2f5c8 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Thu, 24 Jun 2021 08:50:48 -0700 Subject: [PATCH] fix: stop window.open from hanging when prevented (#29851) --- lib/browser/guest-window-proxy.ts | 1 + spec-main/guest-window-manager-spec.ts | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/lib/browser/guest-window-proxy.ts b/lib/browser/guest-window-proxy.ts index ed9e7e780c4c..1d0fe47f8bea 100644 --- a/lib/browser/guest-window-proxy.ts +++ b/lib/browser/guest-window-proxy.ts @@ -76,6 +76,7 @@ ipcMainInternal.on( const referrer: Electron.Referrer = { url: '', policy: 'strict-origin-when-cross-origin' }; const browserWindowOptions = event.sender._callWindowOpenHandler(event, { url, frameName, features, disposition: 'new-window', referrer }); if (event.defaultPrevented) { + event.returnValue = null; return; } const guest = openGuestWindow({ diff --git a/spec-main/guest-window-manager-spec.ts b/spec-main/guest-window-manager-spec.ts index fa6ce39ff88b..c76e65c0b148 100644 --- a/spec-main/guest-window-manager-spec.ts +++ b/spec-main/guest-window-manager-spec.ts @@ -263,6 +263,12 @@ describe('webContents.setWindowOpenHandler', () => { browserWindow.webContents.executeJavaScript("window.open('about:blank', '', 'show=no') && true"); }); + + it('does not hang parent window when denying window.open', async () => { + browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'deny' })); + browserWindow.webContents.executeJavaScript("window.open('https://127.0.0.1')"); + expect(await browserWindow.webContents.executeJavaScript('42')).to.equal(42); + }); }); } });