feat: add global renderer-process-crashed event (#17315)
This commit is contained in:
parent
a8698d092b
commit
6072da239d
4 changed files with 36 additions and 4 deletions
|
@ -352,6 +352,16 @@ Returns:
|
|||
|
||||
Emitted when the gpu process crashes or is killed.
|
||||
|
||||
### Event: 'renderer-process-crashed'
|
||||
|
||||
Returns:
|
||||
|
||||
* `event` Event
|
||||
* `webContents` [WebContents](web-contents.md)
|
||||
* `killed` Boolean
|
||||
|
||||
Emitted when the renderer process of `webContents` crashes or is killed.
|
||||
|
||||
### Event: 'accessibility-support-changed' _macOS_ _Windows_
|
||||
|
||||
Returns:
|
||||
|
|
|
@ -431,6 +431,10 @@ WebContents.prototype._init = function () {
|
|||
})
|
||||
}
|
||||
|
||||
this.on('crashed', (event, ...args) => {
|
||||
app.emit('renderer-process-crashed', event, this, ...args)
|
||||
})
|
||||
|
||||
deprecate.event(this, 'did-get-response-details', '-did-get-response-details')
|
||||
deprecate.event(this, 'did-get-redirect-request', '-did-get-redirect-request')
|
||||
|
||||
|
|
|
@ -379,6 +379,22 @@ describe('app module', () => {
|
|||
w = new BrowserWindow({ show: false })
|
||||
})
|
||||
|
||||
it('should emit renderer-process-crashed event when renderer crashes', async () => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
}
|
||||
})
|
||||
await w.loadURL('about:blank')
|
||||
|
||||
const promise = emittedOnce(app, 'renderer-process-crashed')
|
||||
w.webContents.executeJavaScript('process.crash()')
|
||||
|
||||
const [, webContents] = await promise
|
||||
expect(webContents).to.equal(w.webContents)
|
||||
})
|
||||
|
||||
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
|
||||
w = new BrowserWindow({
|
||||
show: false,
|
||||
|
|
|
@ -110,10 +110,12 @@ app.on('window-all-closed', function () {
|
|||
app.quit()
|
||||
})
|
||||
|
||||
app.on('web-contents-created', (event, contents) => {
|
||||
contents.on('crashed', (event, killed) => {
|
||||
console.log(`webContents ${contents.id} crashed: ${contents.getURL()} (killed=${killed})`)
|
||||
app.on('gpu-process-crashed', (event, killed) => {
|
||||
console.log(`GPU process crashed (killed=${killed})`)
|
||||
})
|
||||
|
||||
app.on('renderer-process-crashed', (event, contents, killed) => {
|
||||
console.log(`webContents ${contents.id} crashed: ${contents.getURL()} (killed=${killed})`)
|
||||
})
|
||||
|
||||
app.on('ready', function () {
|
||||
|
|
Loading…
Add table
Reference in a new issue