Skip to main content

Electron 35.0.0

· 10 min read

Electron 35.0.0 已发布!它包括对 Chromium 134.0.6998.44、V8 13.5 和 Node 22.14.0 的升级。

🌐 Electron 35.0.0 has been released! It includes upgrades to Chromium 134.0.6998.44, V8 13.5, and Node 22.14.0.


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

🌐 The Electron team is excited to announce the release of Electron 35.0.0! 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

Service Worker 预加载脚本,用于改进扩展支持

🌐 Service Worker Preload Scripts for Improved Extensions Support

最初由 @samuelmaddockRFC #8 中提出,Electron 35 增加了向 服务工作者 附加预加载脚本的能力。随着 Chrome 的 Manifest V3 扩展将大量工作通过 扩展服务工作者 路由,这一功能填补了 Electron 对现代 Chrome 扩展支持的空白。

🌐 Originally proposed in RFC #8 by @samuelmaddock, Electron 35 adds the ability to attach a preload script to Service Workers. With Chrome's Manifest V3 Extensions routing a lot of work through extension service workers, this feature fills in a gap in Electron's support for modern Chrome extensions.

在会话级别以编程方式注册预加载脚本时,现在可以使用 ses.registerPreloadScript(script) API 将其专门应用于服务工作线程上下文。

🌐 When registering a preload script programmatically at the Session level, you can now specifically apply it to Service Worker contexts with the ses.registerPreloadScript(script) API.

Main Process
// Add our preload realm script to the session.
session.defaultSession.registerPreloadScript({
// Our script should only run in service worker preload realms.
type: 'service-worker',
// The absolute path to the script.
script: path.join(__dirname, 'extension-sw-preload.js'),
});

此外,现在可以通过 ServiceWorkerMain.ipc 类在 Service Workers 与其附加的预加载脚本之间进行 IPC。预加载脚本仍将使用 ipcRenderer 模块与其 Service Worker 通信。更多详细信息请参阅原始 RFC。

🌐 Furthermore, IPC is now available between Service Workers and their attached preload scripts via the ServiceWorkerMain.ipc class. The preload script will still use the ipcRenderer module to communicate with its Service Worker. See the original RFC for more details.

此功能之前有许多其他更改为其奠定了基础:

🌐 This feature was preceded by many other changes that laid the groundwork for it:

  • #45329 重新设计了 Session 模块的预加载 API,以支持注册和注销单个预加载脚本。
  • #45229 添加了实验性的 contextBridge.executeInMainWorld(executionScript) 脚本,用于通过上下文桥在主世界中评估 JavaScript。
  • #45341 在主进程中添加了 ServiceWorkerMain 类以与服务工作者进行交互。

技术栈变更

🌐 Stack Changes

Electron 35 将 Chromium 从 132.0.6834.83 升级到 134.0.6998.44,Node 从 20.18.1 升级到 22.14.0,V8 从 13.2 升级到 13.5

🌐 Electron 35 upgrades Chromium from 132.0.6834.83 to 134.0.6998.44, Node from 20.18.1 to 22.14.0, and V8 from 13.2 to 13.5.

新功能

🌐 New Features

  • 已将 NSPrefersDisplaySafeAreaCompatibilityMode = false 添加到 Info.plist,以从应用选项中移除“缩放以适应内置相机”。#45357 (也在 v34.1.0 中)
  • 在主进程中添加了 ServiceWorkerMain 类以与服务工作线程进行交互。 #45341
    • ServiceWorkers 上添加了 running-status-changed 事件,以指示服务工作线程的运行状态已更改。
    • ServiceWorkers 上添加了 startWorkerForScope 以启动可能之前已停止的工作程序。
  • 新增实验性功能 contextBridge.executeInMainWorld,可跨世界边界安全执行代码。 #45330
  • 已将 frame 添加到 'console-message' 事件。#43617
  • 在 Windows 上添加了 query-session-end 事件并改进了 session-end 事件。#44598
  • 已添加 view.getVisible()#45409
  • 添加了 webContents.navigationHistory.restore(index, entries) API,允许恢复导航历史记录。 #45583
  • BrowserWindow.setVibrancy 添加了可选动画参数。 #35987
  • document.executeCommand("paste") 添加了权限支持。#45471 (也在 v34.1.0)
  • 在 Windows 上为 roundedCorners BrowserWindow 构造函数选项添加了支持。#45740 (也在 v34.3.0 中)
  • 增加了对服务工作线程预加载脚本的支持。 #45408
  • 支持门户的 globalShortcuts。Electron 必须在 --enable-features=GlobalShortcutsPortal 下运行才能使该功能正常工作。#45297

重大变化

🌐 Breaking Changes

已移除:PrinterInfo 上的 isDefaultstatus 属性

🌐 Removed: isDefault and status properties on PrinterInfo

这些属性已从 PrinterInfo 对象中移除,因为它们已从上游 Chromium 中移除。

🌐 These properties have been removed from the PrinterInfo object because they have been removed from upstream Chromium.

已弃用:getFromVersionIDsession.serviceWorkers

🌐 Deprecated: getFromVersionID on session.serviceWorkers

session.serviceWorkers.fromVersionID(versionId) API 已被废弃,取而代之的是 session.serviceWorkers.getInfoFromVersionID(versionId)。此更改旨在通过引入 session.serviceWorkers.getWorkerFromVersionID(versionId) API,更清楚地显示返回的是哪个对象。

🌐 The session.serviceWorkers.fromVersionID(versionId) API has been deprecated in favor of session.serviceWorkers.getInfoFromVersionID(versionId). This was changed to make it more clear which object is returned with the introduction of the session.serviceWorkers.getWorkerFromVersionID(versionId) API.

// Deprecated
session.serviceWorkers.fromVersionID(versionId);

// Replace with
session.serviceWorkers.getInfoFromVersionID(versionId);

已弃用:setPreloadsgetPreloadsSession

🌐 Deprecated: setPreloads, getPreloads on Session

registerPreloadScriptunregisterPreloadScriptgetPreloadScripts 被引入用于替代已弃用的方法。这些新 API 允许第三方库注册预加载脚本,而不替换现有脚本。此外,新的 type 选项允许在 frame 之外添加额外的预加载目标。

// Deprecated
session.setPreloads([path.join(__dirname, 'preload.js')]);

// Replace with:
session.registerPreloadScript({
type: 'frame',
id: 'app-preload',
filePath: path.join(__dirname, 'preload.js'),
});

已弃用:在 WebContentsconsole-message 事件中使用 levelmessagelinesourceId 参数

🌐 Deprecated: level, message, line, and sourceId arguments in console-message event on WebContents

WebContents 上的 console-message 事件已更新,以提供有关 Event 参数的详细信息。

🌐 The console-message event on WebContents has been updated to provide details on the Event argument.

// Deprecated
webContents.on(
'console-message',
(event, level, message, line, sourceId) => {},
);

// Replace with:
webContents.on(
'console-message',
({ level, message, lineNumber, sourceId, frame }) => {},
);

此外,level 现在是一个字符串,可能的取值为 infowarningerrordebug

🌐 Additionally, level is now a string with possible values of info, warning, error, and debug.

行为已更改:WebRequestFilterurls 属性。

🌐 Behavior Changed: urls property of WebRequestFilter.

以前,空的 urls 数组被解释为包含所有 URL。现在,开发者如果想明确包含所有 URL,应该使用 <all_urls> 模式,这是一个指定的 URL 模式,可以匹配所有可能的 URL。此更改明确了意图,并确保行为更加可预测。

🌐 Previously, an empty urls array was interpreted as including all URLs. To explicitly include all URLs, developers should now use the <all_urls> pattern, which is a designated URL pattern that matches every possible URL. This change clarifies the intent and ensures more predictable behavior.

// Deprecated
const deprecatedFilter = {
urls: [],
};

// Replace with
const newFilter = {
urls: ['<all_urls>'],
};

已弃用:systemPreferences.isAeroGlassEnabled()

🌐 Deprecated: systemPreferences.isAeroGlassEnabled()

systemPreferences.isAeroGlassEnabled() 函数已被弃用且没有替代方案。自 Electron 23 起,它一直返回 true,因为该版本仅支持 Windows 10 及更高版本,而 DWM 组合已无法再被禁用。

🌐 The systemPreferences.isAeroGlassEnabled() function has been deprecated without replacement. It has been always returning true since Electron 23, which only supports Windows 10+, where DWM composition can no longer be disabled.

https://learn.microsoft.com/en-us/windows/win32/dwm/composition-ovw#disabling-dwm-composition-windows7-and-earlier

32.x.y 停止支持

🌐 End of Support for 32.x.y

根据项目的支持政策,Electron 32.x.y 已结束支持。我们鼓励开发者和应用升级到更新版本的 Electron。

🌐 Electron 32.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.

E35(2025年3月)E36(2025年4月)E37(2025年6月)
35.x.y36.x.y37.x.y
34.x.y35.x.y36.x.y
33.x.y34.x.y35.x.y

下一步计划

🌐 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.