fix: stop window.open from hanging when prevented (#29851)

This commit is contained in:
Jeremy Rose 2021-06-24 08:50:48 -07:00 committed by GitHub
parent 9de8e676dd
commit 0f16575eee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View file

@ -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({

View file

@ -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);
});
});
}
});