diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc
index b84ac0725056..5f4d985f8b72 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 000000000000..cbaaf2339d1c
--- /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 000000000000..6aba8425967b
--- /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 000000000000..1402bea99b19
--- /dev/null
+++ b/spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+ Document
+
+
+
+ webview page
+
+
+
+