fix: webview crash when removing in close event (#38996)
This commit is contained in:
parent
5a77c75753
commit
c7a64ab994
4 changed files with 83 additions and 1 deletions
|
@ -1297,6 +1297,8 @@ void WebContents::CloseContents(content::WebContents* source) {
|
|||
for (ExtendedWebContentsObserver& observer : observers_)
|
||||
observer.OnCloseContents();
|
||||
|
||||
// This is handled by the embedder frame.
|
||||
if (!IsGuest())
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
|
32
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html
vendored
Normal file
32
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
.webview {
|
||||
border: 1px solid black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<button class="close-btn">close webview</button>
|
||||
<webview class="webview" src="./webview.html"></webview>
|
||||
<script>
|
||||
const close = document.querySelector('.close-btn')
|
||||
const webview = document.querySelector('.webview')
|
||||
|
||||
webview.addEventListener('close', () => {
|
||||
webview.parentNode.removeChild(webview)
|
||||
})
|
||||
|
||||
close.addEventListener('click', () => {
|
||||
webview.executeJavaScript('window.close()', true)
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
29
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js
vendored
Normal file
29
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js
vendored
Normal file
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
19
spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html
vendored
Normal file
19
spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>webview page</h1>
|
||||
<script>
|
||||
window.addEventListener('beforeunload', event => {
|
||||
event.returnValue = 'test'
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue