Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add app render-process-gone event #24315

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/api/app.md
Expand Up @@ -369,6 +369,25 @@ Returns:

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

#### Event: 'render-process-gone'

Returns:

* `event` Event
* `webContents` [WebContents](web-contents.md)
* `details` Object
* `reason` String - The reason the render process is gone. Possible values:
* `clean-exit` - Process exited with an exit code of zero
* `abnormal-exit` - Process exited with a non-zero exit code
* `killed` - Process was sent a SIGTERM or otherwise killed externally
* `crashed` - Process crashed
* `oom` - Process ran out of memory
* `launch-failure` - Process never successfully launched
* `integrity-failure` - Windows code integrity checks failed

Emitted when the renderer process unexpectedly dissapears. This is normally
because it was crashed or killed.

### Event: 'accessibility-support-changed' _macOS_ _Windows_

Returns:
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/api/web-contents.js
Expand Up @@ -500,6 +500,10 @@ WebContents.prototype._init = function () {
app.emit('renderer-process-crashed', event, this, ...args);
});

this.on('render-process-gone', (event, ...args) => {
app.emit('render-process-gone', event, this, ...args);
});

// The devtools requests the webContents to reload.
this.on('devtools-reload-page', function () {
this.reload();
Expand Down
19 changes: 19 additions & 0 deletions spec-main/api-app-spec.ts
Expand Up @@ -423,6 +423,25 @@ describe('app module', () => {
expect(webContents).to.equal(w.webContents);
});

it('should emit render-process-gone event when renderer crashes', async function () {
// FIXME: re-enable this test on win32.
if (process.platform === 'win32') { return this.skip(); }
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
});
await w.loadURL('about:blank');

const promise = emittedOnce(app, 'render-process-gone');
w.webContents.executeJavaScript('process.crash()');

const [, webContents, details] = await promise;
expect(webContents).to.equal(w.webContents);
expect(details.reason).to.be.oneOf(['crashed', 'abnormal-exit']);
});

ifdescribe(features.isDesktopCapturerEnabled())('desktopCapturer module filtering', () => {
it('should emit desktop-capturer-get-sources event when desktopCapturer.getSources() is invoked', async () => {
w = new BrowserWindow({
Expand Down