跳转到主要内容

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 使用 npm install electron@latest 来安装它,或者从我们的发布网站下载它。 继续阅读有关此版本的详细信息。

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

重要变更

技术栈变更

亮点功能

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 支持的更新

上个月,谷歌宣布 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 以访问窗口开启者(window 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 的公开时间线

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