From 521108e2a52a9449323e7493355ae9b32523f105 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Wed, 9 Apr 2025 15:35:30 +0200 Subject: [PATCH] fix: crash on parent window close and focur/blur (#46559) --- shell/browser/api/electron_api_browser_window.cc | 4 ++-- spec/api-browser-window-spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index eb30d2fea804..8d92652b033e 100644 --- a/shell/browser/api/electron_api_browser_window.cc +++ b/shell/browser/api/electron_api_browser_window.cc @@ -219,14 +219,14 @@ void BrowserWindow::CloseImmediately() { } void BrowserWindow::Focus() { - if (api_web_contents_->IsOffScreen()) + if (api_web_contents_ && api_web_contents_->IsOffScreen()) FocusOnWebView(); else BaseWindow::Focus(); } void BrowserWindow::Blur() { - if (api_web_contents_->IsOffScreen()) + if (api_web_contents_ && api_web_contents_->IsOffScreen()) BlurWebView(); else BaseWindow::Blur(); diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index a1d90f628e21..2e6c7a799550 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -4930,6 +4930,18 @@ describe('BrowserWindow module', () => { expect(w.getChildWindows().length).to.equal(0); }); + it('can handle parent window close with focus or blur events', (done) => { + const w = new BrowserWindow({ show: false }); + const c = new BrowserWindow({ show: false, parent: w }); + + c.on('closed', () => { + w.focus(); + done(); + }); + + w.close(); + }); + ifit(process.platform === 'darwin')('only shows the intended window when a child with siblings is shown', async () => { const w = new BrowserWindow({ show: false }); const childOne = new BrowserWindow({ show: false, parent: w });