Skip to content

Commit 8eee4f2

Browse files
authored
fix: BrowserView crash when 'beforeunload' prevented (electron#37205)
fix: crash when beforeunload prevented
1 parent 4d6f230 commit 8eee4f2

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

shell/browser/api/electron_api_browser_window.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ BrowserWindow::~BrowserWindow() {
112112
api_web_contents_->RemoveObserver(this);
113113
// Destroy the WebContents.
114114
OnCloseContents();
115-
api_web_contents_->Destroy();
116115
}
117116
}
118117

@@ -140,6 +139,7 @@ void BrowserWindow::WebContentsDestroyed() {
140139

141140
void BrowserWindow::OnCloseContents() {
142141
BaseWindow::ResetBrowserViews();
142+
api_web_contents_->Destroy();
143143
}
144144

145145
void BrowserWindow::OnRendererResponsive(content::RenderProcessHost*) {

shell/browser/api/electron_api_web_contents.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,9 @@ void WebContents::CloseContents(content::WebContents* source) {
12221222
for (ExtendedWebContentsObserver& observer : observers_)
12231223
observer.OnCloseContents();
12241224

1225-
Destroy();
1225+
// If there are observers, OnCloseContents will call Destroy()
1226+
if (observers_.empty())
1227+
Destroy();
12261228
}
12271229

12281230
void WebContents::ActivateContents(content::WebContents* source) {

0 commit comments

Comments
 (0)