diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index eb30d2fea8..8d92652b03 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 e464117fc1..2a6f58fb94 100755 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -4929,6 +4929,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 });