-
Notifications
You must be signed in to change notification settings - Fork 15k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: webview crash when removing in close event
- Loading branch information
1 parent
52fe76c
commit d446610
Showing
5 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 29 additions & 0 deletions
29
spec/fixtures/crash-cases/webview-remove-on-wc-close/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 changes: 19 additions & 0 deletions
19
spec/fixtures/crash-cases/webview-remove-on-wc-close/webview.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |