Electron 35.0.0
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 install electron@latest
使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。
¥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.
如果你有任何反馈,请在 Bluesky 或 Mastodon 上与我们分享,或加入我们的社区 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
最初由 @samuelmaddock 在 RFC #8 中提出的 Electron 35 添加了将预加载脚本附加到 服务工作进程 的功能。由于 Chrome 的 Manifest V3 Extensions 将大量工作路由到 扩展服务工作者,此功能填补了 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 将其专门应用于 Service Worker 上下文。
¥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.
// 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 Worker 及其附加的预加载脚本之间进行进程间通信 (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,以支持注册和注销单个预加载脚本。
¥#45329 redesigned the Session module's preload APIs to support registering and unregistering individual preload scripts.
-
#45229 添加了实验性的
contextBridge.executeInMainWorld(executionScript)
脚本,用于通过上下文桥接器在主世界中执行 JavaScript。¥#45229 added the experimental
contextBridge.executeInMainWorld(executionScript)
script to evaluate JavaScript in the main world over the context bridge. -
#45341 添加了
ServiceWorkerMain
类,用于在主进程中与 Service Worker 交互。¥#45341 added the
ServiceWorkerMain
class to interact with Service Workers in the main process.
技术栈变更
¥Stack Changes
-
Chromium
134.0.6998.44
-
Node
22.14.0
-
V8
13.5
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
-
在
Info.plist
中添加了NSPrefersDisplaySafeAreaCompatibilityMode
=false
以从应用选项中移除 "缩放以适应内置摄像头。"。#45357 (v34.1.0 中也包含)¥Added
NSPrefersDisplaySafeAreaCompatibilityMode
=false
toInfo.plist
to remove "Scale to fit below built-in camera." from app options. #45357 (Also in v34.1.0) -
添加了
ServiceWorkerMain
类,用于与主进程中的服务工作线程交互。#45341¥Added
ServiceWorkerMain
class to interact with service workers in the main process. #45341-
在
ServiceWorkers
上添加了running-status-changed
事件,用于指示服务工作线程的运行状态何时发生变化。¥Added
running-status-changed
event onServiceWorkers
to indicate when a service worker's running status has changed. -
在
ServiceWorkers
上添加了startWorkerForScope
,用于启动可能之前已停止的工作器。¥Added
startWorkerForScope
onServiceWorkers
to start a worker that may have been previously stopped.
-
-
添加了实验性
contextBridge.executeInMainWorld
,以便安全地跨世界边界执行代码。#45330¥Added experimental
contextBridge.executeInMainWorld
to safely execute code across world boundaries. #45330 -
在
'console-message'
事件中添加了frame
。#43617¥Added
frame
to'console-message'
event. #43617 -
在 Windows 上添加了
query-session-end
事件并改进了session-end
事件。#44598¥Added
query-session-end
event and improvedsession-end
events on Windows. #44598 -
添加了
view.getVisible()
。#45409¥Added
view.getVisible()
. #45409 -
添加了允许恢复导航历史记录的
webContents.navigationHistory.restore(index, entries)
API。#45583¥Added
webContents.navigationHistory.restore(index, entries)
API that allows restoration of navigation history. #45583 -
为
BrowserWindow.setVibrancy
添加了可选动画参数。#35987¥Added optional animation parameter to
BrowserWindow.setVibrancy
. #35987 -
为
document.executeCommand("paste")
添加了权限支持。#45471 (v34.1.0 中也包含)¥Added permission support for
document.executeCommand("paste")
. #45471 (Also in v34.1.0) -
添加了对 Windows 上
roundedCorners
BrowserWindow 构造函数选项的支持。#45740 (v34.3.0 中也包含)¥Added support for
roundedCorners
BrowserWindow constructor option on Windows. #45740 (Also in v34.3.0) -
添加了对服务工作线程预加载脚本的支持。#45408
¥Added support for service worker preload scripts. #45408
-
支持 Portal 的
globalShortcuts
。Electron 必须与--enable-features=GlobalShortcutsPortal
一起运行才能使该功能正常运行。#45297¥Support Portal's
globalShortcuts
. Electron must be run with--enable-features=GlobalShortcutsPortal
in order to have the feature working. #45297
重大变化
¥Breaking Changes
删除:PrinterInfo
上的 isDefault
和 status
属性
¥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.
已弃用:session.serviceWorkers
上的 getFromVersionID
¥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);
已弃用:Session
上的 setPreloads
、getPreloads
¥Deprecated: setPreloads
, getPreloads
on Session
registerPreloadScript
、unregisterPreloadScript
和 getPreloadScripts
是作为弃用方法的替代品引入的。这些新 API 允许第三方库注册预加载脚本,而无需替换现有脚本。此外,新的 type
选项允许除 frame
之外的其他预加载目标。
¥registerPreloadScript
, unregisterPreloadScript
, and getPreloadScripts
are introduced as a
replacement for the deprecated methods. These new APIs allow third-party libraries to register
preload scripts without replacing existing scripts. Also, the new type
option allows for
additional preload targets beyond frame
.
// Deprecated
session.setPreloads([path.join(__dirname, 'preload.js')]);
// Replace with:
session.registerPreloadScript({
type: 'frame',
id: 'app-preload',
filePath: path.join(__dirname, 'preload.js'),
});
已弃用:WebContents
上 console-message
事件中的 level
、message
、line
和 sourceId
参数
¥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
现在是一个字符串,可能的值为 info
、warning
、error
和 debug
。
¥Additionally, level
is now a string with possible values of info
, warning
, error
, and debug
.
行为改变:WebRequestFilter
的 urls
属性。
¥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.
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.y | 36.x.y | 37.x.y |
34.x.y | 35.x.y | 36.x.y |
33.x.y | 34.x.y | 35.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.