Skip to content

Commit

Permalink
fix: crash on close window when webContents destroyed (#31644)
Browse files Browse the repository at this point in the history
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
  • Loading branch information
trop[bot] and codebytere committed Nov 1, 2021
1 parent bcf04f5 commit 30b9d15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ void BrowserWindow::OnCloseButtonClicked(bool* prevent_default) {
ScheduleUnresponsiveEvent(5000);

// Already closed by renderer.
if (!web_contents())
if (!web_contents() || !api_web_contents_)
return;

// Required to make beforeunload handler work.
Expand Down
5 changes: 5 additions & 0 deletions spec-main/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ describe('BrowserWindow module', () => {
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 () => {
await w.loadFile(path.join(fixtures, 'api', 'unload.html'));
const closed = emittedOnce(w, 'closed');
Expand Down

0 comments on commit 30b9d15

Please sign in to comment.