Skip to content

Commit

Permalink
fix: crash when beforeunload prevented
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Feb 13, 2023
1 parent 8b3e498 commit 8bd3f01
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,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 8bd3f01

Please sign in to comment.