From 657e88b1731d4b0bb83558961a74f7ecd05f94f0 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Wed, 18 Oct 2023 12:05:41 +0200 Subject: [PATCH] chore: remove deprecated `crashed` and `renderer-process-crashed` events (#40115) --- docs/api/app.md | 15 --------------- docs/api/web-contents.md | 14 -------------- docs/api/webview-tag.md | 8 -------- docs/breaking-changes.md | 30 ++++++++++++++++++++++++++++++ lib/browser/api/app.ts | 4 ---- lib/browser/api/web-contents.ts | 4 ---- lib/browser/web-view-events.ts | 1 - spec/api-app-spec.ts | 22 ---------------------- spec/api-web-contents-spec.ts | 25 ------------------------- spec/ts-smoke/electron/main.ts | 6 ++++++ 10 files changed, 36 insertions(+), 93 deletions(-) diff --git a/docs/api/app.md b/docs/api/app.md index 41a47273cc94..bc69f3fdc4b2 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -391,21 +391,6 @@ which contains more information about why the child process disappeared. It isn't always because it crashed. The `killed` boolean can be replaced by checking `reason === 'killed'` when you switch to that event. -### Event: 'renderer-process-crashed' _Deprecated_ - -Returns: - -* `event` Event -* `webContents` [WebContents](web-contents.md) -* `killed` boolean - -Emitted when the renderer process of `webContents` crashes or is killed. - -**Deprecated:** This event is superceded by the `render-process-gone` event -which contains more information about why the render process disappeared. It -isn't always because it crashed. The `killed` boolean can be replaced by -checking `reason === 'killed'` when you switch to that event. - ### Event: 'render-process-gone' Returns: diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index d1d419f2ce48..a127f35c61bf 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -460,20 +460,6 @@ win.webContents.on('will-prevent-unload', (event) => { **Note:** This will be emitted for `BrowserViews` but will _not_ be respected - this is because we have chosen not to tie the `BrowserView` lifecycle to its owning BrowserWindow should one exist per the [specification](https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event). -#### Event: 'crashed' _Deprecated_ - -Returns: - -* `event` Event -* `killed` boolean - -Emitted when the renderer process crashes or is killed. - -**Deprecated:** This event is superceded by the `render-process-gone` event -which contains more information about why the render process disappeared. It -isn't always because it crashed. The `killed` boolean can be replaced by -checking `reason === 'killed'` when you switch to that event. - #### Event: 'render-process-gone' Returns: diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 1c3ea20d13f9..f65edec4254c 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -986,14 +986,6 @@ ipcRenderer.on('ping', () => { }) ``` -### Event: 'crashed' _Deprecated_ - -Fired when the renderer process crashes or is killed. - -**Deprecated:** This event is superceded by the `render-process-gone` event -which contains more information about why the render process disappeared. It -isn't always because it crashed. - ### Event: 'render-process-gone' Returns: diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md index 7e03b06102ae..8636e4bedc2f 100644 --- a/docs/breaking-changes.md +++ b/docs/breaking-changes.md @@ -12,6 +12,36 @@ This document uses the following convention to categorize breaking changes: * **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release. * **Removed:** An API or feature was removed, and is no longer supported by Electron. +## Planned Breaking API Changes (29.0) + +### Removed: `renderer-process-crashed` event on `app` + +The `renderer-process-crashed` event on `app` has been removed. +Use the new `render-process-gone` event instead. + +```js +// Removed +app.on('renderer-process-crashed', (event, webContents, killed) => { /* ... */ }) + +// Replace with +app.on('render-process-gone', (event, webContents, details) => { /* ... */ }) +``` + +### Removed: `crashed` event on `WebContents` and `` + +The `crashed` events on `WebContents` and `` have been removed. +Use the new `render-process-gone` event instead. + +```js +// Removed +win.webContents.on('crashed', (event, killed) => { /* ... */ }) +webview.addEventListener('crashed', (event) => { /* ... */ }) + +// Replace with +win.webContents.on('render-process-gone', (event, details) => { /* ... */ }) +webview.addEventListener('render-process-gone', (event) => { /* ... */ }) +``` + ## Planned Breaking API Changes (28.0) ### Behavior Changed: `WebContents.backgroundThrottling` set to false affects all `WebContents` in the host `BrowserWindow` diff --git a/lib/browser/api/app.ts b/lib/browser/api/app.ts index 5d7ce57880b7..3127166de799 100644 --- a/lib/browser/api/app.ts +++ b/lib/browser/api/app.ts @@ -118,7 +118,3 @@ deprecate.event(app, 'gpu-process-crashed', 'child-process-gone', () => { // the old event is still emitted by App::OnGpuProcessCrashed() return undefined; }); - -deprecate.event(app, 'renderer-process-crashed', 'render-process-gone', (event: Electron.Event, webContents: Electron.WebContents, details: Electron.RenderProcessGoneDetails) => { - return [event, webContents, details.reason === 'killed']; -}); diff --git a/lib/browser/api/web-contents.ts b/lib/browser/api/web-contents.ts index 7c876d5317cf..3682e667e7ec 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -665,10 +665,6 @@ WebContents.prototype._init = function () { ipcMain.emit(channel, event, message); }); - deprecate.event(this, 'crashed', 'render-process-gone', (event: Electron.Event, details: Electron.RenderProcessGoneDetails) => { - return [event, details.reason === 'killed']; - }); - this.on('render-process-gone', (event, details) => { app.emit('render-process-gone', event, this, details); diff --git a/lib/browser/web-view-events.ts b/lib/browser/web-view-events.ts index e8086336f867..0d361a499b6e 100644 --- a/lib/browser/web-view-events.ts +++ b/lib/browser/web-view-events.ts @@ -21,7 +21,6 @@ export const webViewEvents: Record = { 'did-navigate-in-page': ['url', 'isMainFrame', 'frameProcessId', 'frameRoutingId'], '-focus-change': ['focus'], close: [], - crashed: [], 'render-process-gone': ['details'], 'plugin-crashed': ['name', 'version'], destroyed: [], diff --git a/spec/api-app-spec.ts b/spec/api-app-spec.ts index 0954e93302bf..bfe6d6a444c0 100644 --- a/spec/api-app-spec.ts +++ b/spec/api-app-spec.ts @@ -9,7 +9,6 @@ import { promisify } from 'node:util'; import { app, BrowserWindow, Menu, session, net as electronNet, WebContents } from 'electron/main'; import { closeWindow, closeAllWindows } from './lib/window-helpers'; import { ifdescribe, ifit, listen, waitUntil } from './lib/spec-helpers'; -import { expectDeprecationMessages } from './lib/deprecate-helpers'; import { once } from 'node:events'; import split = require('split') import * as semver from 'semver'; @@ -528,27 +527,6 @@ describe('app module', () => { expect(webContents.id).to.equal(w.webContents.id); }); - // FIXME: re-enable this test on win32. - ifit(process.platform !== 'win32')('should emit renderer-process-crashed event when renderer crashes', async () => { - w = new BrowserWindow({ - show: false, - webPreferences: { - nodeIntegration: true, - contextIsolation: false - } - }); - await w.loadURL('about:blank'); - - expectDeprecationMessages(async () => { - const emitted = once(app, 'renderer-process-crashed') as Promise<[any, WebContents, boolean]>; - w.webContents.executeJavaScript('process.crash()'); - - const [, webContents, killed] = await emitted; - expect(webContents).to.equal(w.webContents); - expect(killed).to.be.false(); - }, '\'renderer-process-crashed event\' is deprecated and will be removed. Please use \'render-process-gone event\' instead.'); - }); - // FIXME: re-enable this test on win32. ifit(process.platform !== 'win32')('should emit render-process-gone event when renderer crashes', async () => { w = new BrowserWindow({ diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index 0c39aa9d0a7a..9a02bd439b3e 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -6,7 +6,6 @@ import * as http from 'node:http'; import { BrowserWindow, ipcMain, webContents, session, app, BrowserView, WebContents } from 'electron/main'; import { closeAllWindows } from './lib/window-helpers'; import { ifdescribe, defer, waitUntil, listen, ifit } from './lib/spec-helpers'; -import { expectDeprecationMessages } from './lib/deprecate-helpers'; import { once } from 'node:events'; import { setTimeout } from 'node:timers/promises'; @@ -2344,30 +2343,6 @@ describe('webContents module', () => { }); }); - describe('crashed event', () => { - it('does not crash main process when destroying WebContents in it', (done) => { - const contents = (webContents as typeof ElectronInternal.WebContents).create({ nodeIntegration: true }); - contents.once('crashed', () => { - contents.destroy(); - done(); - }); - contents.loadURL('about:blank').then(() => contents.forcefullyCrashRenderer()); - }); - - it('logs a warning', async () => { - const contents = (webContents as typeof ElectronInternal.WebContents).create({ nodeIntegration: true }); - await contents.loadURL('about:blank'); - - expectDeprecationMessages(async () => { - const crashEvent = once(contents, 'crashed'); - contents.forcefullyCrashRenderer(); - const [, killed] = await crashEvent; - - expect(killed).to.be.a('boolean'); - }, '\'crashed event\' is deprecated and will be removed. Please use \'render-process-gone event\' instead.'); - }); - }); - describe('context-menu event', () => { afterEach(closeAllWindows); it('emits when right-clicked in page', async () => { diff --git a/spec/ts-smoke/electron/main.ts b/spec/ts-smoke/electron/main.ts index 319321f215e3..2079182f3b2e 100644 --- a/spec/ts-smoke/electron/main.ts +++ b/spec/ts-smoke/electron/main.ts @@ -437,6 +437,9 @@ app.configureHostResolver({ secureDnsMode: 'foo' }); // @ts-expect-error Removed API console.log(app.runningUnderRosettaTranslation); +// @ts-expect-error Removed API +app.on('renderer-process-crashed', () => {}); + // auto-updater // https://github.com/electron/electron/blob/main/docs/api/auto-updater.md @@ -1306,6 +1309,9 @@ win4.webContents.on('scroll-touch-edge', () => {}); // @ts-expect-error Removed API win4.webContents.on('scroll-touch-end', () => {}); +// @ts-expect-error Removed API +win4.webContents.on('crashed', () => {}); + // TouchBar // https://github.com/electron/electron/blob/main/docs/api/touch-bar.md