Skip to main content

Electron 42

· 12 min read

Electron 42 已发布!它包括对 Chromium 148.0.7778.96、V8 14.8 和 Node v24.15.0 的升级。

🌐 Electron 42 has been released! It includes upgrades to Chromium 148.0.7778.96, V8 14.8, and Node v24.15.0.


Electron 团队很高兴地宣布发布 Electron 42!你可以通过 npm install electron@latest 使用 npm 安装,或从我们的 发布网站 下载。继续阅读以了解有关此版本的详细信息。

🌐 The Electron team is excited to announce the release of Electron 42! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请通过 BlueskyMastodon 与我们分享,或者加入我们的社区 Discord!可以在 Electron 的 问题追踪器 报告漏洞和功能请求。

🌐 If you have any feedback, please share it with us on Bluesky or Mastodon, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

🌐 Notable Changes

macOS 通知现在使用 UNNotification API

🌐 macOS notifications now use UNNotification API

Electron 已从已弃用的 NSUserNotification API 迁移到 macOS 上的 UNNotification API。新 API 要求应用必须进行代码签名才能显示通知。如果应用没有进行代码签名,通知将在 Notification 对象上触发 failed 事件。 #47817

🌐 Electron has migrated from the deprecated NSUserNotification API to the UNNotification API on macOS. The new API requires that an application be code-signed in order for notifications to be displayed. If an application is not code-signed, notifications will emit a failed event on the Notification object. #47817

此外,Electron 42 为 macOS 添加了 Notification.getHistory() (#51123),并在 Notification 构造函数中添加了 idgroupId 选项,以允许在通知中心进行自定义标识符和视觉分组 (#50304)。

🌐 Additionally, Electron 42 adds Notification.getHistory() for macOS (#51123), and id and groupId options to the Notification constructor to allow custom identifiers and visual grouping in Notification Center (#50304).

electron 不再通过 postinstall 脚本自行下载

🌐 electron no longer downloads itself via postinstall script

之前,electron npm 包会在包的 postinstall 脚本中从仓库的 GitHub Releases 下载 Electron 二进制文件。由于近期针对 npm 生态系统的供应链安全攻击中,postinstall 脚本是常见的攻击向量,Electron 现在将在第一次运行其主 bin 脚本时动态下载自身(例如,通过 npx electron)。通过此更改,你现在可以使用带有 npm --ignore-scripts 标志的 Electron。更多背景信息请参见 RFC #22#49328

🌐 Previously, the electron npm package would download the Electron binary from the repository's GitHub Releases in the package's postinstall script. With recent supply chain security attacks against the npm ecosystem with postinstall scripts as a common attack vector, Electron will now download itself dynamically the first time that its main bin script is run (e.g. via npx electron). With this change, you can now use Electron with the npm --ignore-scripts flag. See RFC #22 for more context. #49328

如果你需要按需下载 Electron 二进制文件,现在可以调用 install-electron 脚本:

🌐 If you need to download the Electron binary on-demand, you can now call the install-electron script:

npm install electron --save-dev --ignore-scripts
npx install-electron

macOS 上的 WebAuthn Touch ID 支持

🌐 WebAuthn Touch ID support on macOS

已添加 app.configureWebAuthn({ touchID: { keychainAccessGroup } }) 以在 macOS 上启用 WebAuthn Touch ID 平台身份验证器。这还引入了用于可发现凭证选择的 select-webauthn-account 会话事件。#51411

🌐 Added app.configureWebAuthn({ touchID: { keychainAccessGroup } }) to enable the WebAuthn Touch ID platform authenticator on macOS. This also introduces a select-webauthn-account session event for discoverable-credential selection. #51411

查看动画和背景模糊

🌐 View animations and background blur

view.setBounds() 添加了动画功能,并添加了 view.setBackgroundBlur(),允许更流畅的 UI 过渡和原生背景模糊效果。 #48812

🌐 Added animation functionality to view.setBounds() and added view.setBackgroundBlur(), allowing for smoother UI transitions and native background blur effects. #48812

技术栈变更

🌐 Stack Changes

Electron 42 将 Chromium 从 146.0.7680.65 升级到 148.0.7778.96,Node.js 从 v24.14.0 升级到 v24.15.0,以及 V8 从 14.6 升级到 14.8

🌐 Electron 42 upgrades Chromium from 146.0.7680.65 to 148.0.7778.96, Node.js from v24.14.0 to v24.15.0, and V8 from 14.6 to 14.8.

新功能和改进

🌐 New Features and Improvements

  • 在 macOS 上添加 app.configureWebAuthn({ touchID: { keychainAccessGroup } }) 以启用 WebAuthn Touch ID 平台身份验证器。同时引入了一个用于可发现凭证选择的 select-webauthn-account 会话事件。 #51411 (也在 41)
  • 已向 protocol.registerSchemesAsPrivileged() 添加 allowExtensions 权限,以在自定义协议上启用 Chrome 扩展程序。#49951
  • 为 macOS 添加了 Notification.getHistory()#51123
  • 在 Windows 上添加了 Notification.handleActivation(callback) API 以处理通知点击、回复和操作按钮——包括应用从通知启动(冷启动)时。#49919
  • 添加了 ELECTRON_INSTALL_PLATFORMELECTRON_INSTALL_ARCH 变量以从其他平台和架构安装二进制文件。#49981
  • 添加了 app.isActive() 用于检查应用是否为活动/前台应用(仅限 macOS)。#49622
  • 添加了 globalShortcut.setSuspended()globalShortcut.isSuspended() 方法用于临时暂停和恢复全局快捷键处理。 #50777
  • 在 macOS 上的通知构造函数中添加了 idgroupId 选项,用于在通知中心实现自定义标识符和可视分组。#50304
  • 为 Windows 通知添加了 idgroupIdgroupTitle 支持。#50895
  • 在 macOS 上添加了 nativeTheme.shouldDifferentiateWithoutColor#50409 (也在 41 中)
  • view.setBounds() 添加了动画功能,并添加了 view.setBackgroundBlur()#48812
  • contentTracing 中添加了对堆分析的支持。#51162 (也在 41)
  • 添加了使用 nv16 像素格式导入共享纹理的支持。 #51187
  • 添加了使用 p010le 10 位 YUV 像素格式导入共享纹理的支持。 #49272
  • 通过 safeStorage 中新的异步功能,为多个 safeStorage 后端添加了支持。 #49054
  • 在 Windows 通知中添加了对 urgency 选项的支持。#50383 (也在 41)
  • 添加了在渲染器 OOM 时捕获 JS 堆栈跟踪的能力。#50911
  • Electron 现在在首次启动时会将其二进制文件动态下载到 node_modules,而不是运行 postinstall 脚本。还添加了 install-electron 脚本以手动触发下载。 #49328
  • WasmTrapHandlers fuse 背后启用 wasm 陷阱处理程序。#48983 (也在 41)
  • 用用户通知替换已弃用的 NSUserNotification#47817

重大变化

🌐 Breaking Changes

行为变更:macOS 通知现在使用 UNNotification API

🌐 Behavior Changed: macOS notifications now use UNNotification API

Electron 已经从已弃用的 NSUserNotification API 迁移到 macOS 上的 UNNotification API。新 API 要求应用必须进行代码签名才能显示通知。如果应用未进行代码签名,通知将在 Notification 对象上触发 failed 事件。 #47817

🌐 Electron has migrated from the deprecated NSUserNotification API to the UNNotification API on macOS. The new API requires that an application be code-signed in order for notifications to be displayed. If an application is not code-signed, notifications will emit a failed event on the Notification object. #47817

行为已更改:electron 不再通过 postinstall 脚本自行下载

🌐 Behavior Changed: electron no longer downloads itself via postinstall script

以前,electron npm 包会在包的 postinstall 脚本中从仓库的 GitHub Releases 下载 Electron 二进制文件。随着近期针对 npm 生态系统的供应链安全攻击,postinstall 脚本成为常见攻击手段,Electron 现在将在其主 bin 脚本首次运行时动态下载自身(例如通过 npx electron)。更多背景信息请参见 RFC #22#49328

🌐 Previously, the electron npm package would download the Electron binary from the repository's GitHub Releases in the package's postinstall script. With recent supply chain security attacks against the npm ecosystem with postinstall scripts as a common attack vector, Electron will now download itself dynamically the first time that its main bin script is run (e.g. via npx electron). See RFC #22 for more context. #49328

行为已更改:屏幕外渲染默认设备缩放因子

🌐 Behavior Changed: Offscreen rendering default device scale factor

以前,OSR 使用主显示器的设备缩放因子进行渲染。从 Electron 42 开始,默认值更改为常量值 1.0,以获得更一致的输出大小。使用 webPreferences.offscreen.deviceScaleFactor 来指定自定义值。#49683

🌐 Previously, OSR used the primary display's device scale factor for rendering. Starting from Electron 42, the default changes to a constant value of 1.0 for more consistent output sizes. Use webPreferences.offscreen.deviceScaleFactor to specify a custom value. #49683

已从 Session.clearStorageData(options) 中移除:quotas 对象

🌐 Removed: quotas object from Session.clearStorageData(options)

在调用 Session.clearStorageData(options) 时,options.quotas 对象不再受支持,因为它已从上游 Chromium 中移除。

🌐 When calling Session.clearStorageData(options), the options.quotas object is no longer supported because it has been removed from upstream Chromium.

已移除:ELECTRON_SKIP_BINARY_DOWNLOAD 环境变量

🌐 Removed: ELECTRON_SKIP_BINARY_DOWNLOAD environment variable

由于新的延迟下载行为,此环境变量不再受支持。 #50459

🌐 This environment variable is no longer supported due to the new lazy download behavior. #50459

已弃用:仅将数组 hslShift 传递给 nativeImage.createFromNamedImage()

🌐 Deprecated: Passing only an array hslShift to nativeImage.createFromNamedImage()

仅将数组 hslShift 传递给 nativeImage.createFromNamedImage() 已被弃用。你现在应该传递一个带有 hslShift 属性的选项对象:

🌐 Passing only an array hslShift to nativeImage.createFromNamedImage() is deprecated. You should now pass an options object with an hslShift property instead:

// Deprecated
nativeImage.createFromNamedImage(imageName, [0, 1, -1]);
// Replace with
nativeImage.createFromNamedImage(imageName, {
hslShift: [0, 1, -1],
});

39.x.y 版本停止支持

🌐 End of Support for 39.x.y

根据项目的支持政策,Electron 39.x.y 已达到支持终止。建议开发者和应用升级到较新的 Electron 版本。请访问 https://releases.electronjs.org/schedule 查看 Electron 支持版本的时间表。

🌐 Electron 39.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron. See https://releases.electronjs.org/schedule to see the timeline for supported versions of Electron.

下一步计划

🌐 What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

🌐 In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以在这里找到 Electron 的公开时间线

🌐 You can find Electron's public timeline here.

有关未来更改的更多信息可以在计划中的重大变更页面上找到。

🌐 More information about future changes can be found on the Planned Breaking Changes page.