跳到主要内容

Electron 22.0.0

·阅读时长约 5 分钟

Electron 22.0.0 已发布!它包含一个新的 utility process API,对 Windows 7/8/8.1 支持的更新,以及对 Chromium 108、V8 10.8 和 Node.js 16.17.1 的升级。阅读下文了解更多详情!


Electron 团队激动地宣布 Electron 22.0.0 发布!您可以通过 npm 使用 npm install electron@latest 进行安装,或者从我们的发布版本网站下载。请继续阅读以了解此版本的详细信息。

如果您有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!bug 和功能请求可以在 Electron 的issue 跟踪器中报告。

值得关注的变化

堆栈变化

重点功能

UtilityProcess API #36089

新的 UtilityProcess 主进程模块允许创建一个轻量级的 Chromium 子进程,该子进程只集成 Node.js,同时允许使用 MessageChannel 与沙盒渲染器进行通信。该 API 基于 Node.js 的 child_process.fork 设计,以便于过渡,其主要区别在于入口点 modulePath 必须来自打包应用程序内部,以便只加载受信任的脚本。此外,该模块默认阻止与渲染器建立通信通道,维护了主进程是应用程序中唯一受信任进程的约定。

您可以在我们的文档中在此处阅读更多关于 新 UtilityProcess API 的信息

Windows 7/8/8.1 支持更新

信息

2023年2月16日:关于 Windows Server 2012 支持的更新

上个月,Google 宣布 Chrome 109 将继续为 Windows Server 2012 和 Windows Server 2012 R2 提供关键安全修复,直到 2023 年 10 月 10 日。相应地,Electron 22(Chromium 108)原计划的生命周期结束日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续为此计划中的任何安全修复向 Electron 22 进行回移植,直到 2023 年 10 月 10 日。

请注意,我们不会为 Windows 7/8/8.1 提供额外的安全修复。此外,Electron 23 (Chromium 110) 将仅支持 Windows 10 及更高版本,正如之前宣布的那样。

Electron 22 将是最后一个支持 Windows 7/8/8.1 的 Electron 主要版本。Electron 遵循计划中的 Chromium 弃用策略,该策略将在 Chromium 109 中弃用对 Windows 7/8/8.1 的支持(在此阅读更多信息)

Electron 23 及更高版本将不再支持 Windows 7/8/8.1。

其他重点变化

  • 新增对 Linux 和 Windows 上 Web Bluetooth PIN 配对的支持。#35416
  • 新增 LoadBrowserProcessSpecificV8Snapshot 作为新的 fuse,允许主进程/浏览器进程从 browser_v8_context_snapshot.bin 文件加载其 v8 快照。其他进程将使用当前使用的相同路径。#35266
  • 新增 WebContents.opener 用于访问窗口 opener,以及 webContents.fromFrame(frame) 用于获取与 WebFrameMain 实例对应的 WebContents。#35140
  • 通过新的 session handler ses.setDisplayMediaRequestHandler 新增对 navigator.mediaDevices.getDisplayMedia 的支持。#30702

破坏性 API 更改

以下是 Electron 22 中引入的破坏性更改。您可以在 Planned Breaking Changes 页面上阅读更多关于这些更改和未来更改的信息。

已弃用:webContents.incrementCapturerCount(stayHidden, stayAwake)

webContents.incrementCapturerCount(stayHidden, stayAwake) 已弃用。现在当页面捕获完成时,由 webContents.capturePage 自动处理。

const w = new BrowserWindow({ show: false })

- w.webContents.incrementCapturerCount()
- w.capturePage().then(image => {
- console.log(image.toDataURL())
- w.webContents.decrementCapturerCount()
- })

+ w.capturePage().then(image => {
+ console.log(image.toDataURL())
+ })

已弃用:webContents.decrementCapturerCount(stayHidden, stayAwake)

webContents.decrementCapturerCount(stayHidden, stayAwake) 已弃用。现在当页面捕获完成时,由 webContents.capturePage 自动处理。

const w = new BrowserWindow({ show: false })

- w.webContents.incrementCapturerCount()
- w.capturePage().then(image => {
- console.log(image.toDataURL())
- w.webContents.decrementCapturerCount()
- })

+ w.capturePage().then(image => {
+ console.log(image.toDataURL())
+ })

已移除:WebContents 的 new-window 事件

WebContents 的 new-window 事件已移除。由 webContents.setWindowOpenHandler() 替代。

- webContents.on('new-window', (event) => {
- event.preventDefault()
- })

+ webContents.setWindowOpenHandler((details) => {
+ return { action: 'deny' }
+ })

已弃用:BrowserWindow 的 scroll-touch-* 事件

BrowserWindow 上的 scroll-touch-beginscroll-touch-endscroll-touch-edge 事件已弃用。请改用 WebContents 上新提供的input-event 事件

// Deprecated
- win.on('scroll-touch-begin', scrollTouchBegin)
- win.on('scroll-touch-edge', scrollTouchEdge)
- win.on('scroll-touch-end', scrollTouchEnd)

// Replace with
+ win.webContents.on('input-event', (_, event) => {
+ if (event.type === 'gestureScrollBegin') {
+ scrollTouchBegin()
+ } else if (event.type === 'gestureScrollUpdate') {
+ scrollTouchEdge()
+ } else if (event.type === 'gestureScrollEnd') {
+ scrollTouchEnd()
+ }
+ })

19.x.y 版本支持结束

根据项目的支持策略,Electron 19.x.y 已达到支持结束。鼓励开发者和应用程序升级到更新的 Electron 版本。

E19 (22年5月)E20 (22年8月)E21 (22年9月)E22 (22年11月)E23 (23年1月)
19.x.y20.x.y21.x.y22.x.y23.x.y
18.x.y19.x.y20.x.y21.x.y22.x.y
17.x.y18.x.y19.x.y20.x.y21.x.y

下一步计划

Electron 项目将在 2022 年 12 月暂停,并于 2023 年 1 月恢复。更多信息可在十二月停工博文中找到。

短期内,您可以期待团队继续专注于跟进构成 Electron 的主要组件的发展,包括 Chromium、Node 和 V8。

您可以在此处找到 Electron 的公开时间线

更多关于未来更改的信息可在Planned Breaking Changes 页面上找到。