Skip to content

Commit

Permalink
fix: BrowserView crash when 'beforeunload' prevented (electron#37205)
Browse files Browse the repository at this point in the history
fix: crash when beforeunload prevented
  • Loading branch information
codebytere authored and gecko19 committed Mar 15, 2023
1 parent 36982df commit 0899d3f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shell/browser/api/electron_api_browser_window.cc
Expand Up @@ -112,7 +112,6 @@ BrowserWindow::~BrowserWindow() {
api_web_contents_->RemoveObserver(this);
// Destroy the WebContents.
OnCloseContents();
api_web_contents_->Destroy();
}
}

Expand Down Expand Up @@ -140,6 +139,7 @@ void BrowserWindow::WebContentsDestroyed() {

void BrowserWindow::OnCloseContents() {
BaseWindow::ResetBrowserViews();
api_web_contents_->Destroy();
}

void BrowserWindow::OnRendererResponsive(content::RenderProcessHost*) {
Expand Down
4 changes: 3 additions & 1 deletion shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1223,7 +1223,9 @@ void WebContents::CloseContents(content::WebContents* source) {
for (ExtendedWebContentsObserver& observer : observers_)
observer.OnCloseContents();

Destroy();
// If there are observers, OnCloseContents will call Destroy()
if (observers_.empty())
Destroy();
}

void WebContents::ActivateContents(content::WebContents* source) {
Expand Down

0 comments on commit 0899d3f

Please sign in to comment.