fix: webview crash when removing in close event (#38996)

This commit is contained in:
Shelley Vohr 2023-07-06 10:20:34 +02:00 committed by GitHub
parent 5a77c75753
commit c7a64ab994
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 1 deletions

View 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();
});
});
});