Skip to content

Commit b812e78

Browse files
trop[bot]miniak
andauthored
feat: add app render-process-gone event (electron#24314)
Co-authored-by: Milan Burda <milan.burda@gmail.com>
1 parent b080dab commit b812e78

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

docs/api/app.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,25 @@ Returns:
368368

369369
Emitted when the renderer process of `webContents` crashes or is killed.
370370

371+
#### Event: 'render-process-gone'
372+
373+
Returns:
374+
375+
* `event` Event
376+
* `webContents` [WebContents](web-contents.md)
377+
* `details` Object
378+
* `reason` String - The reason the render process is gone. Possible values:
379+
* `clean-exit` - Process exited with an exit code of zero
380+
* `abnormal-exit` - Process exited with a non-zero exit code
381+
* `killed` - Process was sent a SIGTERM or otherwise killed externally
382+
* `crashed` - Process crashed
383+
* `oom` - Process ran out of memory
384+
* `launch-failure` - Process never successfully launched
385+
* `integrity-failure` - Windows code integrity checks failed
386+
387+
Emitted when the renderer process unexpectedly dissapears. This is normally
388+
because it was crashed or killed.
389+
371390
### Event: 'accessibility-support-changed' _macOS_ _Windows_
372391

373392
Returns:

lib/browser/api/web-contents.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ WebContents.prototype._init = function () {
389389
app.emit('renderer-process-crashed', event, this, ...args);
390390
});
391391

392+
this.on('render-process-gone', (event, ...args) => {
393+
app.emit('render-process-gone', event, this, ...args);
394+
});
395+
392396
// The devtools requests the webContents to reload.
393397
this.on('devtools-reload-page', function () {
394398
this.reload();

spec-main/api-app-spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,25 @@ describe('app module', () => {
427427
expect(webContents).to.equal(w.webContents)
428428
})
429429

430+
it('should emit render-process-gone event when renderer crashes', async function () {
431+
// FIXME: re-enable this test on win32.
432+
if (process.platform === 'win32') { return this.skip(); }
433+
w = new BrowserWindow({
434+
show: false,
435+
webPreferences: {
436+
nodeIntegration: true
437+
}
438+
});
439+
await w.loadURL('about:blank');
440+
441+
const promise = emittedOnce(app, 'render-process-gone');
442+
w.webContents.executeJavaScript('process.crash()');
443+
444+
const [, webContents, details] = await promise;
445+
expect(webContents).to.equal(w.webContents);
446+
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
447+
});
448+
430449
ifdescribe(features.isDesktopCapturerEnabled())('desktopCapturer module filtering', () => {
431450
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
432451
w = new BrowserWindow({

0 commit comments

Comments
 (0)