- 重要的API变更
- 重大更改
- Types of Breaking Changes
- 计划重写的 API (12.0)
- 计划重写的 API (11.0)
- 计划重写的 API (10.0)
- 计划重写的 API (9.0)
- Default Changed: Loading non-context-aware native modules in the renderer process is disabled by default
- Removed: <webview>.getWebContents()
- Removed: webFrame.setLayoutZoomLevelLimits()
- Behavior Changed: Sending non-JS objects over IPC now throws an exception
- API Changed: shell.openItem is now shell.openPath
- 计划重写的 API (8.0)
重要的API变更
重大更改
这里将记录重大更改,并在可能的情况下向JS代码添加弃用警告,在这更改之前至少会有一个重要版本.
Types of Breaking Changes
This document uses the following convention to categorize breaking changes:
-
API Changed: An API was changed in such a way that code that has not been updated is guaranteed to throw an exception.
-
Behavior Changed: The behavior of Electron has changed, but not in such a way that an exception will necessarily be thrown.
-
Default Changed: Code depending on the old default may break, not necessarily throwing an exception. The old behavior can be restored by explicitly specifying the value.
-
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.
计划重写的 API (12.0)
Removed: crashReporter methods in the renderer process
The following crashReporter methods are no longer available in the renderer process:
-
crashReporter.start
-
crashReporter.getLastCrashReport
-
crashReporter.getUploadedReports
-
crashReporter.getUploadToServer
-
crashReporter.setUploadToServer
-
crashReporter.getCrashesDirectory
They should be called only from the main process.
See #23265 for more details.
计划重写的 API (11.0)
计划重写的 API (10.0)
Deprecated: companyName argument to crashReporter.start()
The companyName argument to crashReporter.start(), which was previously required, is now optional, and further, is deprecated. To get the same behavior in a non-deprecated way, you can pass a companyName value in globalExtra.
// Deprecated in Electron 10crashReporter.start({ companyName: 'Umbrella Corporation' })// Replace withcrashReporter.start({ globalExtra: { _companyName: 'Umbrella Corporation' } })
Deprecated: crashReporter.getCrashesDirectory()
The crashReporter.getCrashesDirectory method has been deprecated. Usage should be replaced by app.getPath('crashDumps').
// Deprecated in Electron 10crashReporter.getCrashesDirectory()// Replace withapp.getPath('crashDumps')
Deprecated: crashReporter methods in the renderer process
Calling the following crashReporter methods from the renderer process is deprecated:
-
crashReporter.start
-
crashReporter.getLastCrashReport
-
crashReporter.getUploadedReports
-
crashReporter.getUploadToServer
-
crashReporter.setUploadToServer
-
crashReporter.getCrashesDirectory
The only non-deprecated methods remaining in the crashReporter module in the renderer are addExtraParameter, removeExtraParameter and getParameters.
All above methods remain non-deprecated when called from the main process.
See #23265 for more details.
Removed: Browser Window Affinity
The affinity option when constructing a new BrowserWindow will be removed as part of our plan to more closely align with Chromium’s process model for security, performance and maintainability.
For more detailed information see #18397.
Default Changed: enableRemoteModule defaults to false
In Electron 9, using the remote module without explicitly enabling it via the enableRemoteModule WebPreferences option began emitting a warning. In Electron 10, the remote module is now disabled by default. To use the remote module, enableRemoteModule: true must be specified in WebPreferences:
const w = new BrowserWindow({ webPreferences: { enableRemoteModule: true }})
We recommend moving away from the remote module.
计划重写的 API (9.0)
Default Changed: Loading non-context-aware native modules in the renderer process is disabled by default
As of Electron 9 we do not allow loading of non-context-aware native modules in the renderer process. This is to improve security, performance and maintainability of Electron as a project.
If this impacts you, you can temporarily set app.allowRendererProcessReuse to false to revert to the old behavior. This flag will only be an option until Electron 11 so you should plan to update your native modules to be context aware.
For more detailed information see #18397.
Removed: <webview>.getWebContents()
This API, which was deprecated in Electron 8.0, is now removed.
// Removed in Electron 9.0webview.getWebContents()// Replace withconst { remote } = require('electron')remote.webContents.fromId(webview.getWebContentsId())
Removed: webFrame.setLayoutZoomLevelLimits()
Chromium has removed support for changing the layout zoom level limits, and it is beyond Electron’s capacity to maintain it. The function was deprecated in Electron 8.x, and has been removed in Electron 9.x. The layout zoom level limits are now fixed at a minimum of 0.25 and a maximum of 5.0, as defined here.
Behavior Changed: Sending non-JS objects over IPC now throws an exception
In Electron 8.0, IPC was changed to use the Structured Clone Algorithm, bringing significant performance improvements. To help ease the transition, the old IPC serialization algorithm was kept and used for some objects that aren’t serializable with Structured Clone. In particular, DOM objects (e.g. Element, Location and DOMMatrix), Node.js objects backed by C++ classes (e.g. process.env, some members of Stream), and Electron objects backed by C++ classes (e.g. WebContents, BrowserWindow and WebFrame) are not serializable with Structured Clone. Whenever the old algorithm was invoked, a deprecation warning was printed.
In Electron 9.0, the old serialization algorithm has been removed, and sending such non-serializable objects will now throw an “object could not be cloned” error.
API Changed: shell.openItem is now shell.openPath
The shell.openItem API has been replaced with an asynchronous shell.openPath API. You can see the original API proposal and reasoning here.
计划重写的 API (8.0)
Behavior Changed: Values sent over IPC are now serialized with Structured Clone Algorithm
The algorithm used to serialize objects sent over IPC (through ipcRenderer.send, ipcRenderer.sendSync, WebContents.send and related methods) has been switched from a custom algorithm to V8’s built-in Structured Clone Algorithm, the same algorithm used to serialize messages for postMessage. This brings about a 2x performance improvement for large messages, but also brings some breaking changes in behavior.
- Sending Functions, Promises, WeakMaps, WeakSets, or objects containing any such values, over IPC will now throw an exception, instead of silently converting the functions to undefined.
// Previously:
ipcRenderer.send(‘channel’, { value: 3, someFunction: () => {} })
// => results in { value: 3 } arriving in the main process
// From Electron 8:
ipcRenderer.send(‘channel’, { value: 3, someFunction: () => {} })
// => throws Error(“() => {} could not be cloned.”)
NaN,Infinityand-Infinitywill now be correctly serialized, instead of being converted tonull.- Objects containing cyclic references will now be correctly serialized, instead of being converted tonull.-Set,Map,ErrorandRegExpvalues will be correctly serialized, instead of being converted to{}.-BigIntvalues will be correctly serialized, instead of being converted tonull.- Sparse arrays will be serialized as such, instead of being converted to dense arrays withnulls.-Dateobjects will be transferred asDateobjects, instead of being converted to their ISO string representation.- Typed Arrays (such asUint8Array,Uint16Array,Uint32Arrayand so on) will be transferred as such, instead of being converted to Node.jsBuffer.- Node.jsBufferobjects will be transferred asUint8Arrays. You can convert aUint8Arrayback to a Node.jsBufferby wrapping the underlyingArrayBuffer:jsBuffer.from(value.buffer, value.byteOffset, value.byteLength)
