fix: crash on close window when webContents destroyed (#31620)
This commit is contained in:
parent
a6e5ff3607
commit
20b4813cf8
2 changed files with 6 additions and 1 deletions
|
@ -254,7 +254,7 @@ void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
|
||||||
ScheduleUnresponsiveEvent(5000);
|
ScheduleUnresponsiveEvent(5000);
|
||||||
|
|
||||||
// Already closed by renderer.
|
// Already closed by renderer.
|
||||||
if (!web_contents())
|
if (!web_contents() || !api_web_contents_)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Required to make beforeunload handler work.
|
// Required to make beforeunload handler work.
|
||||||
|
|
|
@ -110,6 +110,11 @@ describe('BrowserWindow module', () => {
|
||||||
await closed;
|
await closed;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not crash if called after webContents is destroyed', () => {
|
||||||
|
w.webContents.destroy();
|
||||||
|
w.webContents.on('destroyed', () => w.close());
|
||||||
|
});
|
||||||
|
|
||||||
it('should emit unload handler', async () => {
|
it('should emit unload handler', async () => {
|
||||||
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
|
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
|
||||||
const closed = emittedOnce(w, 'closed');
|
const closed = emittedOnce(w, 'closed');
|
||||||
|
|
Loading…
Reference in a new issue