diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index 02a3aa0cdd2d4..6d7c361e1ee58 100644 --- a/shell/browser/api/electron_api_browser_window.cc +++ b/shell/browser/api/electron_api_browser_window.cc @@ -112,7 +112,6 @@ BrowserWindow::~BrowserWindow() { api_web_contents_->RemoveObserver(this); // Destroy the WebContents. OnCloseContents(); - api_web_contents_->Destroy(); } } @@ -140,6 +139,7 @@ void BrowserWindow::WebContentsDestroyed() { void BrowserWindow::OnCloseContents() { BaseWindow::ResetBrowserViews(); + api_web_contents_->Destroy(); } void BrowserWindow::OnRendererResponsive(content::RenderProcessHost*) { diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index b84ac07250562..5f4d985f8b727 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1297,7 +1297,9 @@ void WebContents::CloseContents(content::WebContents* source) { for (ExtendedWebContentsObserver& observer : observers_) observer.OnCloseContents(); - Destroy(); + // This is handled by the embedder frame. + if (!IsGuest()) + Destroy(); } void WebContents::ActivateContents(content::WebContents* source) { diff --git a/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html b/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html new file mode 100644 index 0000000000000..cbaaf2339d1c7 --- /dev/null +++ b/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html @@ -0,0 +1,32 @@ + + + + + + + Document + + + + + + + + + + diff --git a/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js b/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js new file mode 100644 index 0000000000000..6aba8425967b5 --- /dev/null +++ b/spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js @@ -0,0 +1,29 @@ +const { app, BrowserWindow } = require('electron'); + +app.whenReady().then(() => { + const win = new BrowserWindow({ + webPreferences: { + webviewTag: true + } + }); + + win.loadFile('index.html'); + + win.webContents.on('did-attach-webview', (event, contents) => { + contents.on('render-process-gone', () => { + process.exit(1); + }); + + contents.on('destroyed', () => { + process.exit(0); + }); + + contents.on('did-finish-load', () => { + win.webContents.executeJavaScript('document.querySelector(\'.close-btn\').click()'); + }); + + contents.on('will-prevent-unload', event => { + event.preventDefault(); + }); + }); +}); diff --git a/spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html b/spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html new file mode 100644 index 0000000000000..1402bea99b196 --- /dev/null +++ b/spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html @@ -0,0 +1,19 @@ + + + + + + + Document + + + +

webview page

+ + + +