fix: crash on window.close() with webContents on blur (#47953)

fix: crash on window.close with WebContentsView on blur

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-08-04 15:42:55 +02:00 committed by GitHub
commit 61ba91a254
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 8 deletions

View file

@ -167,6 +167,26 @@ describe('WebContentsView', () => {
});
});
it('does not crash when closed via window.close()', async () => {
const bw = new BrowserWindow();
const wcv = new WebContentsView();
await bw.loadURL('data:text/html,<h1>Main Window</h1>');
bw.contentView.addChildView(wcv);
const dto = new Promise<boolean>((resolve) => {
wcv.webContents.on('blur', () => {
const devToolsOpen = wcv.webContents.isDevToolsOpened();
resolve(devToolsOpen);
});
});
wcv.webContents.loadURL('data:text/html,<script>window.close()</script>');
const open = await dto;
expect(open).to.be.false();
});
it('can be fullscreened', async () => {
const w = new BaseWindow();
const v = new WebContentsView();