跳转到主要内容

Electron 22.0.0

·6 分钟阅读

Electron 22.0.0 已经发布! 它包括一个新的实用工具进程 API,对 Windows 7/8/8.1 支持的更新,以及对 Chromium 108, V8 10.8, 和 Node.js 16.17.1 的升级。 请继续阅读以了解更多详情!


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

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

重要变更

技术栈变更

亮点功能

UtilityProcess API #36089

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

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

Windows 7/8/8.1 支持更新

信息

2023/02/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 以访问窗口打开程序,以及 webContents.fromFrame(frame) 以获取与 WebFrameMain 实例对应的 WebContents。#35140
  • 通过一个新的会话处理程序 ses.setDisplayMediaRequestHandler,增加了对 navigator.mediaDevices.getDisplayMedia 的支持。#30702

破坏性 API 变更

以下是 Electron 22 中引入的重大更改。您可以在计划的重大更改页面上了解更多关于这些更改和未来更改的信息。

已弃用: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 的公开时间线

有关未来变更的更多信息,请参阅计划中的破坏性变更页面。