跳转到主内容

Electron 35.0.0

· 阅读时间:约 8 分钟

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


Electron 团队很高兴发布了 Electron 35.0.0 ! 你可以通过 npm install electron@latest 或者从我们的发布网站下载它。 继续阅读此版本的详细信息。

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

重要变化

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

最初由 @samuelmaddockRFC #8 中提出,Electron 35 添加了将预加载脚本附加到 Service Workers 的功能。 由于 Chrome 的 Manifest V3 Extensions 通过 扩展 service workers 处理大量工作,该功能填补了 Electron 对现代 Chrome 扩展程序支持的空白。

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

Main Process
// 将我们的预加载脚本添加到会话中。
session.defaultSession.registerPreloadScript({
// 我们的脚本应该只在 service worker 预加载中运行。
type: 'service-worker',
// 脚本的绝对路径。
script: path.join(__dirname, 'extension-sw-preload.js'),
});

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

此功能之前已经进行了许多其他更改,为其奠定了基础:

  • #45329 重新设计了 Session 模块的预加载 API,以支持注册和取消注册单独的预加载脚本。
  • #45229 添加了实验性的 contextBridge.executeInMainWorld(executionScript) 脚本,用于通过 context bridge 在 main world 中执行 JavaScript。
  • #45341 添加了 ServiceWorkerMain 类,用于与主进程中的 Service Workers 交互。

架构(Stack)更新

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

新特性

  • 在 Info.plist 中添加了 NSPrefersDisplaySafeAreaCompatibilityMode = false,以移除应用选项中的 “Scale to fit below built-in camera” 选项。 #45357 (也适用于 v34.1.0
  • 在主进程中添加了 ServiceWorkerMain 类,用于与服务工作线程进行交互。 #45341
    • ServiceWorkers 上添加了 running-status-changed 事件,用于指示服务工作线程的运行状态何时发生更改。
    • ServiceWorkers 上添加了 startWorkerForScope 方法,用于启动可能先前已停止的工作线程。
  • 添加了实验性的 contextBridge.executeInMainWorld 方法,用于安全地跨 world 边界执行代码。 #45330
  • 'console-message' 事件中添加了 frame 属性。 #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 中)
  • 添加了对 service worker 线程预加载脚本的支持。 #45408
  • 支持 Portal 的 globalShortcuts。 Electron 必须使用 --enable-features=GlobalShortcutsPortal 运行,该功能才能生效。 #45297

重大更改

移除了 PrinterInfo 上的 isDefaultstatus 属性。

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

已弃用:session.serviceWorkers 上的 getFromVersionID

session.serviceWorkers.fromVersionID(versionId) API 已被弃用,建议使用 session.serviceWorkers.getInfoFromVersionID(versionId)。 此更改是为了在引入 session.serviceWorkers.getWorkerFromVersionID(versionId) API 后,更清楚地表明返回的是哪个对象。

// 已弃用
session.serviceWorkers.fromVersionID(versionId);

// 替换为
session.serviceWorkers.getInfoFromVersionID(versionId);

已弃用:Session 上的 setPreloadsgetPreloads

registerPreloadScriptunregisterPreloadScriptgetPreloadScripts 被引入作为对已弃用方法的替代。 这些新的 API 允许第三方库注册 preload scripts,而无需替换现有脚本。 此外,新的 type 选项允许超出 frame 的其他预加载目标。

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

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

已弃用:WebContents 上的 console-message 事件中的 levelmessagelinesourceId 参数。

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

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

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

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

行为变更:WebRequestFilterurls 属性。

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

// 已弃用
const deprecatedFilter = {
urls: [],
};

// 替换为
const newFilter = {
urls: ['<all_urls>'],
};

已弃用:systemPreferences.isAeroGlassEnabled()

systemPreferences.isAeroGlassEnabled() 函数已被弃用,且没有替代方案。 自 Electron 23 起,它一直返回 true,因为 Electron 23 仅支持 Windows 10+,而 Windows 10+ 中 DWM 合成已无法禁用。

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

终止对 32.x.y 的支持

根据项目的支持政策,Electron 32.x.y 已经达到了支持的终点。 我们鼓励开发者将应用程序升级到更新的 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

接下来

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

您可以在此处找到 Electron 的公开时间表

有关这些和未来变化的更多信息可在计划的突破性变化页面找到。

Google 代码之夏 2025

· 阅读时间:约 5 分钟

Electron has once again been accepted as a mentoring organization for Google Summer of Code (GSoC) 2025! Google Summer of Code is a global program focused on bringing new contributors into open source software development.

For more details about the program, visit Google’s Summer of Code homepage.

关于我们

Electron 是一个 JavaScript 框架,用于使用 Web 技术构建跨平台桌面应用程序。 Electron 的核心框架是一个编译的二进制可执行文件,由 ChromiumNode.js 构建,大多以 C++ 编写。

Outside of the Electron core repository, we also maintain several projects to support the Electron ecosystem, including:

As a GSoC contributor, you will have the opportunity to collaborate with some of Electron’s core contributors on one of many projects under the github.com/electron umbrella.

申请前

If you aren’t very familiar with Electron, we would recommend you start by reading the documentation and trying out some of the examples in Electron Fiddle.

To learn more about distributing Electron apps, try creating a sample application with Electron Forge:

npm init electron-app@latest my-app

在稍微熟悉了代码之后,请加入 Electron Discord 服务器.

info

If this is your first time participating in Google Summer of Code or if you’re new to open source in general, we recommend reading Google’s Contributor Guide before engaging with the community.

Project contributions

We encourage you to take a look at any repositories that are relevant to the project ideas you are interested in. One way of doing your research is to make contributions by reporting bugs, triaging existing issues, or submitting pull requests. Doing so is an effective way of getting hands-on practice with our codebases, but is not mandatory for proposal submissions. A well-crafted proposal should be able to demonstrate your understanding of the code without needing to refer to past contributions.

Here are a few tips if you are looking to contribute to Electron before submitting your proposal:

  1. Please provide descriptive issue or PR descriptions when submitting contributions. Regardless of the code itself, putting effort into the written part of a contribution shows us that you can be an effective communicator in a collaborative environment.
  2. PRs are always welcome for open issues. You do not need to comment on an issue asking a maintainer if you can be assigned to it. Note that we still encourage you to discuss potential solutions on an issue if you need to refine an idea for a solution, but comments strictly asking if you can work on something are redundant and add noise to the issue tracker.
  3. Low-effort project contributions (e.g. invalid issue reports, trivial wording changes in a repo README, or minor stylistic changes to front-end code) will negatively impact your final proposal, as they take up limited maintainer time and do not provide any net benefit to the Electron project.
  4. While AI coding assistants can be an effective tool for debugging and understanding new concepts, we highly discourage contributions that are copy/pasted directly from AI-generated output. These often turn out to be of low quality, and it's often more effort for maintainers to clean up code generated from an LLM than for us to just reject a PR altogether.

Crafting your proposal

有兴趣与 Electron 合作吗? First, check out the seven project idea drafts we have prepared. All listed ideas are open for proposals.

If you have a unique idea not on the list, we are open to considering it, but ensure your proposal is detailed and thoroughly outlined. 如有疑问,我们建议坚持使用我们列出的想法。

您的申请应包括:

  • A detailed proposal outlining what you plan to achieve over the summer.
  • 您作为开发者的背景。 如果你有简历,请附上一份副本。 Otherwise, tell us about your past technical experience.
    • Lack of experience in certain areas won’t disqualify you, but it will help our mentors work out a plan to best support you and make sure your summer project is successful.

A detailed guide of what to submit as part of your Electron application is here. Submit proposals directly to the Google Summer of Code portal. Proposals emailed to the Electron team will not be considered as final submissions.

For more guidance on your proposal, we recommend you follow the official Google Summer of Code proposal writing advice here.

Applications open on March 24th, 2025 and close on April 8th, 2025.

Past project proposals

📚 For GSoC 2024, @piotrpdev, worked on adding API History to the Electron core documentation. To see what Piotr worked on during his summer with Electron, read his report in the 2024 GSoC program archives.

🔐 For GSoC 2022, @aryanshridhar worked on enabling Context Isolation in Electron Fiddle. 如果你想要看到 Aryan 在 Electron 上做了什么,你可以在 2022 GSoC 程序档案阅读他的报告。

问题?

If you have questions we didn’t address in this blog post or inquiries about your proposal draft, please send us an email at summer-of-code@electronjs.org or check the GSoC FAQ. Please read our contributor guidance before emailing.

资源

Electron 34.0.0

· 阅读时间:约 5 分钟

Electron 34.0.0 已发布! 它包括对 Chromium 132.0.6834.83、V8 13.2 和 Node 20.18.1 的升级。


Electron 团队很高兴发布了 Electron 34.0.0 ! 你可以通过 npm install electron@latest 或者从我们的发布网站下载它。 继续阅读此版本的详细信息。

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

重要变化

HTTP Compression Shared Dictionary Management APIs

HTTP compression allows data to be compressed by a web server before being received by the browser. Modern versions of Chromium support Brotli and Zstandard, which are newer compression algorithms that perform better for text files than older schemes such as gzip.

Custom shared dictionaries further improve the efficiency of Brotli and Zstandard compression. See the Chrome for Developers blog on shared dictionaries for more information.

@felixrieseberg added the following APIs in #44950 to manage shared dictionaries at the Session level:

  • session.getSharedDictionaryUsageInfo()
  • session.getSharedDictionaryInfo(options)
  • session.clearSharedDictionaryCache()
  • session.clearSharedDictionaryCacheForIsolationKey(options)

Unresponsive Renderer JavaScript Call Stacks

Electron's unresponsive event occurs whenever a renderer process hangs for an excessive period of time. The new WebFrameMain.collectJavaScriptCallStack() API added by @samuelmaddock in #44204 allows you to collect the JavaScript call stack from the associated WebFrameMain object (webContnets.mainFrame).

This API can be useful to determine why the frame is unresponsive in cases where there's long-running JavaScript events causing the process to hang. For more information, see the proposed web standard Crash Reporting API.

Main Process
const { app } = require('electron');

app.commandLine.appendSwitch(
'enable-features',
'DocumentPolicyIncludeJSCallStacksInCrashReports',
);

app.on('web-contents-created', (_, webContents) => {
webContents.on('unresponsive', async () => {
// Interrupt execution and collect call stack from unresponsive renderer
const callStack = await webContents.mainFrame.collectJavaScriptCallStack();
console.log('Renderer unresponsive\n', callStack);
});
});
警告

This API requires the 'Document-Policy': 'include-js-call-stacks-in-crash-reports' header to be enabled. 详见: #45356

架构(Stack)更新

Electron 34 将 Chromium 从 130.0.6723.44 升级到 132.0.6834.83, Node 从 20.18.0 升级到 20.18.1 以及 V8 从 13.0 升级到 13.2

新特性

  • 添加了API以管理共享字典,以提高使用 Brotli 或 ZStandard 的压缩效率。 新的 APIs 是 session.getSharedDictionaryUsageInfo(), session.getSharedDictionaryInfo(options), session.clear. SharedDictionaryCache(), 和 session.clear. SharedDictionaryCacheForIsolation(options). #44950
  • 添加了 WebFrameMain.collectJavaScriptCallStack() 用于访问无响应渲染器的 JavaScript 调用堆栈。 #44938
  • 为处于卸载状态的帧添加了 WebFrameMain.detached
    • 添加了 WebFrameMain.isDestroyed() 方法,用于判断 frame 是否已被销毁。
    • 修复了 webFrameMain.fromId(processId, frameId) 在框架卸载时返回的 WebFrameMain 实例与给定参数不匹配的问题。 #43473
  • 在 utility process 中增加了 error 事件,以支持有关 V8 致命错误的诊断报告。 #43774
  • 新功能:GPU 加速的共享纹理离屏渲染。 #42953

重大更改

行为改变:在 Windows 全屏时,菜单栏将被隐藏

这使行为与Linux保持一致。 之前的行为:在 Windows 上全屏时菜单栏仍然可见。 新行为:在 Windows 全屏时隐藏菜单栏。

更正:之前这被列为 Electron 33 中的重大更改,但首次发布是在 Electron 34 中。

终止对 31.x.y 的支持

根据项目的支持政策,Electron 31.x.y 已经达到了支持的终点。 我们鼓励开发者将应用程序升级到更新的 Electron 版本。

E28 (25 年 1 月)E35 (25 年 4 月)E36 (25 年 6 月)
34.x.y35.x.y36.x.y
33.x.y34.x.y35.x.y
32.x.y33.x.y34.x.y

接下来

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

您可以在此处找到 Electron 的公开时间表

有关这些和未来变化的更多信息可在计划的突破性变化页面找到。

Moving our Ecosystem to Node 22

· 阅读时间:约 2 分钟

In early 2025, Electron’s npm ecosystem repos (under the @electron/ and @electron-forge/ namespaces) will move to Node.js 22 as the minimum supported version.


What does this mean?

In the past, packages in Electron’s npm ecosystem (Forge, Packager, etc) have supported Node versions for as long as possible, even after a version has reached its End-Of-Life (EOL) date. This is done to make sure we don’t fragment the ecosystem—we understand that many projects depend on older versions of Node, and we don’t want to risk stranding those projects unless there was a pressing reason to upgrade.

Over time, using Node.js 14 as our minimum version has become increasingly difficult for a few reasons:

  • Lack of official Node.js 14 macOS ARM64 builds requires us to maintain CI infrastructure workarounds to provide full test coverage.
  • engines requirements for upstream package dependencies have moved forward, making it increasingly difficult to resolve supply chain security issues with dependency bumps.

Additionally, newer versions of Node.js have included many improvements that we would like to leverage, such as runtime-native common utilities (e.g. fs.glob and util.parseArgs) and entire new batteries-included modules (e.g. node:test, node:sqlite).

Why upgrade now?

In July 2024, Electron’s Ecosystem Working Group decided to upgrade all packages to the earliest Node version where require()of synchronous ESM graphs will be supported (see nodejs/node#51977 and nodejs/node#53500) at a future point after that version reaches its LTS date.

We’ve decided to set that update time to January/February 2025. After this upgrade occurs, Node 22 will be the minimum supported version in existing ecosystem packages.

What action do I need to take?

We’ll strive to maintain compatibility as much as possible. However, to ensure the best support, we encourage you to upgrade your apps to Node 22 or higher.

Note that the Node version running in your project is unrelated to the Node version embedded into your current version of Electron.

下一步

Please feel free to write to us at info@electronjs.org if you have any questions or concerns. You can also find community support in our official Electron Discord.

12月安静期(2024年12月)

· 阅读时间:约 2 分钟

2024年12月Electron项目将进入暂停状态,然后在2025年1月全速恢复。

via GIPHY


12月保持不变的内容

  1. 必要时将发布零日和其他与安全相关的主版本。 Security incidents should be reported via SECURITY.md.
  2. Code of Conduct reports and moderation will continue.

12月变动的内容

  1. 2024's last stable branch releases for the year, which include Electron 31, 32, and 33, will occur the week of December 1st. There will be no additional planned releases in December.
  2. 12 月的最后两周没有 Nightly 和 Alpha 版本。
  3. 除了少数例外,不会合并请求的审核或合并。
  4. 任何仓库上都不会有问题跟进更新。
  5. 维护人员不会提供 Discord 调试帮助。
  6. 社交媒体暂停更新内容。

See you all in 2025!

从 BrowserView 迁移到 WebContentsView

· 阅读时间:约 5 分钟

BrowserViewElectron 30 起已被弃用,现由 WebContentView 替代。 幸运的是,迁移过程相对简单。


Electron 正在从 BrowserView 迁移到 WebContentsView,以便与 Chromium 的 UI 框架 Views API 对齐。 WebContentsView 提供了一个可重用的 view,可以直接与 Chromium 的渲染管道相连,简化了未来的升级,并为开发者在他们的 Electron 应用中集成非网页 UI 元素打开了可能性。 通过采用 WebContentsView,应用程序不仅为即将到来的更新做好了准备,还能在长期中受益于减少代码复杂性和潜在错误的数量。

熟悉 BrowserWindows 和 BrowserViews 的开发者应注意,BrowserWindowWebContentsView 分别是从 BaseWindowView 基类继承的子类。 要全面了解可用的实例变量和方法,请务必查阅这些基类的文档。

迁移步骤

1. 升级 Electron 到 30.0.0 或更高

警告

新版本 Electron 可能含有破坏性更改,影响到您的应用程序。 在继续进行此迁移的其他部分之前,最好先在您的应用程序上测试并完成 Electron 升级。 可以在这里找到每个 Electron 主版本的破坏性更改列表,以及在 Electron 博客中每个主版本的发布说明。

2. 熟悉您的应用程序在哪些地方使用了 BrowserViews。

一种方法是搜索你的代码库中 new BrowserView(。 这将让你了解你的应用程序是如何使用 BrowserViews 的,以及有多少需要迁移的调用点。

提示

在大多数情况下,您的应用程序实例化新的 BrowserViews 时,每个实例都可以与其他实例独立迁移。

3. 迁移每个 BrowserView

  1. 迁移实例化。 这应该相当简单,因为 WebContentsViewBrowserView 的构造函数基本上具有相同的形式。 两者都通过 webPreferences 参数接受 WebPreferences

    - this.tabBar = new BrowserView({
    + this.tabBar = new WebContentsView({
    info

    By default, WebContentsView instantiates with a white background, while BrowserView instantiates with a transparent background. To get a transparent background in WebContentsView, set its background color to an RGBA hex value with an alpha (opaqueness) channel set to 00:

    + this.webContentsView.setBackgroundColor("#00000000");
  2. 迁移 BrowserView 到添加到父窗口的地方。

    - this.browserWindow.addBrowserView(this.tabBar)
    + this.browserWindow.contentView.addChildView(this.tabBar);
  3. 迁移父窗口上的 BrowserView 实例方法调用。

    旧方法新方法注意:
    win.setBrowserViewwin.contentView.removeChildView + win.contentView.addChildView
    win.getBrowserViewwin.contentView.children
    win.removeBrowserViewwin.contentView.removeChildView
    win.setTopBrowserViewwin.contentView.addChildView在现有视图上调用 addChildView 会将其重新排序到顶部。
    win.getBrowserViewswin.contentView.children
  4. setAutoResize 实例方法迁移到一个 resize 监听器上。

    - this.browserView.setAutoResize({
    - vertical: true,
    - })

    + this.browserWindow.on('resize', () => {
    + if (!this.browserWindow || !this.webContentsView) {
    + return;
    + }
    + const bounds = this.browserWindow.getBounds();
    + this.webContentsView.setBounds({
    + x: 0,
    + y: 0,
    + width: bounds.width,
    + height: bounds.height,
    + });
    + });
    提示

    所有现有的 browserView.webContents 使用以及实例方法 browserView.setBoundsbrowserView.getBoundsbrowserView.setBackgroundColor 都无需迁移,并且应该与 WebContentsView 实例无缝兼容!

4) 测试并提交您的更改

遇到问题了吗? 请检查 Electron Issues 上的 WebContentsView 标签,以查看您遇到的问题是否已被报告。 如果您在那里没有看到您的问题,请随时添加一个新的错误报告。 包含测试用例 gist 将帮助我们更好地判断您的问题!

恭喜,您已经迁移到WebContentsView! 🎉

Electron 33.0.0

· 阅读时间:约 5 分钟

Electron 33.0.0 已发布! 它包括对 Chromium 130.0.6723.44、V8 13.0 和 Node 20.18.0 的升级。


Electron 团队很高兴发布了 Electron 33.0.0! 你可以通过 npm install electron@latest 或者从我们的发布网站下载它。 继续阅读此版本的详细信息。

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

重要变化

重点内容

  • 添加了一个处理程序 app.setClientCertRequestPasswordHandler(handler),以帮助在需要 PIN 时解锁加密设备。 #41205
  • 扩展 navigationHistory API,增加两个新功能以改善 history 管理。 #42014
  • 改善了原生主题透明度检查。 #42862

架构(Stack)更新

Electron 33 将 Chromium 从 128.0.6613.36 升级到 130.0.6723.44, Node 从 20.16.0 升级到 20.18.0 以及 V8 从 12.8 升级到 13.0

新特性

  • 添加了一个处理程序 app.setClientCertRequestPasswordHandler(handler),以帮助在需要 PIN 时解锁加密设备。 #41205
  • 在 utility process 中增加了 error 事件,以支持有关 V8 致命错误的诊断报告。 #43997
  • 新增了 View.setBorderRadius(radius) 以自定义 view 的边框半径,并与 WebContentsView 兼容。 #42320
  • 扩展 navigationHistory API,增加两个新功能以改善 history 管理。 #42014

重大更改

移除:macOS 10.15 支持

macOS 10.15(Catalina)不再受到 Chromium 的支持。

旧版本的 Electron 将继续在 Catalina 上运行,但要运行 Electron v33.0.0 及更高版本,将需要 macOS 11(Big Sur)或更高版本。

行为变化:Native modules 现在需要 C++20

由于上游的改动,V8Node.js 现在要求 C++20 作为最低版本。 Developers using native node modules should build their modules with --std=c++20 rather than --std=c++17. 使用 gcc9 或更低版本的镜像可能需要更新到 gcc10 才能进行编译。 详见: #43555

行为变化:Windows 上的自定义协议 URL 处理

由于在 Chromium 中进行的更改,以支持非特殊方案 URL,使用 Windows 文件路径的自定义协议 URL 将不再与已弃用的 protocol.registerFileProtocolBrowserWindow.loadURLWebContents.loadURL 以及 <webview>.loadURL 上的 baseURLForDataURL 属性工作。 protocol.handle 也无法处理这些类型的 URL,但这并不是一个变化,因为它一直都是这样的工作方式。

// No longer works
protocol.registerFileProtocol('other', () => {
callback({ filePath: '/path/to/my/file' });
});

const mainWindow = new BrowserWindow();
mainWindow.loadURL(
'data:text/html,<script src="loaded-from-dataurl.js"></script>',
{ baseURLForDataURL: 'other://C:\\myapp' },
);
mainWindow.loadURL('other://C:\\myapp\\index.html');

// Replace with
const path = require('node:path');
const nodeUrl = require('node:url');
protocol.handle(other, (req) => {
const srcPath = 'C:\\myapp\\';
const reqURL = new URL(req.url);
return net.fetch(
nodeUrl.pathToFileURL(path.join(srcPath, reqURL.pathname)).toString(),
);
});

mainWindow.loadURL(
'data:text/html,<script src="loaded-from-dataurl.js"></script>',
{ baseURLForDataURL: 'other://' },
);
mainWindow.loadURL('other://index.html');

行为变化:app 上的 loginwebContents 属性

app 中的 login 事件的 webContents 属性在事件因来自于使用 respondToAuthRequestsFromMainProcess 选项创建的 utility process 的请求而被触发时,将为 null

已弃用: BrowserWindowConstructorOption.type 中的 textured 选项

BrowserWindowConstructorOptions 中的 typetextured 选项已被弃用,且没有替代方案。 此选项依赖于 macOS 上的 NSWindowStyleMaskTexturedBackground 样式掩码,该样式已被弃用且没有替代方案。

已弃用:systemPreferences.accessibilityDisplayShouldReduceTransparency

systemPreferences.accessibilityDisplayShouldReduceTransparency 属性现已被弃用,取而代之的是新的 nativeTheme.prefersReducedTransparency,它提供相同的信息并支持跨平台使用。

// Deprecated
const shouldReduceTransparency =
systemPreferences.accessibilityDisplayShouldReduceTransparency;

// Replace with:
const prefersReducedTransparency = nativeTheme.prefersReducedTransparency;

End of Support for 30.x.y

根据项目的支持政策,Electron 30.x.y 已经达到了支持的终点。 我们鼓励开发者将应用程序升级到更新的 Electron 版本。

E33 (24 年 10 月)E28 (25 年 1 月)E35 (25 年 4 月)
33.x.y34.x.y35.x.y
32.x.y33.x.y34.x.y
31.x.y32.x.y33.x.y

接下来

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

您可以在此处找到 Electron 的公开时间表

有关这些和未来变化的更多信息可在计划的突破性变化页面找到。

Introducing API History (GSoC 2024)

· 阅读时间:约 7 分钟

Historical changes to Electron APIs will now be detailed in the docs.


Hi 👋, I'm Peter, the 2024 Google Summer of Code (GSoC) contributor to Electron.

Over the course of the GSoC program, I implemented an API history feature for the Electron documentation and its functions, classes, etc. in a similar fashion to the Node.js documentation: by allowing the use of a simple but powerful YAML schema in the API documentation Markdown files and displaying it nicely on the Electron documentation website.

Electron 32.0.0

· 阅读时间:约 6 分钟

Electron 32.0.0 已发布! 包括升级 Chromium 128.0.6613.36,和 V8 12.8 以及 Node. js 20.16.2


Electron 团队很高兴发布了 Electron 32.0.0! 你可以通过 npm install electron@latest 或者从我们的发布网站下载它。 继续阅读此版本的详细信息。

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

重要变化

重点内容

  • 在我们的文档中添加新的 API 版本历史,一个由 @piotrpdev 创建的功能,作为Google Summer 代码的一部分。 You can learn more about it in this blog post. #42982
  • 从 Web 文件 API 中移除非标准 File.path 扩展。 #42053
  • 尝试打开受阻止路径中的文件或目录时,将 Web File System API 中的故障路径与上游对齐。 #42993
  • 将以下现有的导航相关API添加到 webContents.navigationHistory : canGoBack, goBack, canGoForward, goForward, canGoToOffset, goToOffset, clear。 旧的导航API现已被废弃。 #41752

架构(Stack)更新

Electron 32 将 Chromium 从 026.0.6478.36 升级到 128.0.6613.36, Node 从 20.14.0 升级到 20.16.1 以及 V8 从 12.6 升级到 12.8

新特性

  • 添加了对通过app模块的'login'事件,响应来自实用程序进程发起的认证请求的支持。 #43317
  • CPUUsage结构中添加了cumulativeCPUUsage属性,该属性返回自进程启动以来使用的 CPU 时间的总秒数。 #41819
  • 将以下现有的导航相关API添加到 webContents.navigationHistory: canGoBack, goBack, canGoForward, goForward, canGoToOffset, goToOffset, clear#41752
  • 扩展 WebContentsView 以接受预先存在的 webContents 对象。 #42086
  • nativeTheme中添加了一个新属性prefersReducedTransparency,该属性指示用户是否选择通过系统辅助功能设置来降低操作系统级别的透明度。 #43137
  • 尝试打开阻塞路径中的文件或目录时,将文件系统访问 API 中的故障路径与上游对齐。 #42993
  • 在 Linux 上启用 Windows 控制叠加层API。 #42681
  • 在网络请求中启用 zstd 压缩。 #43300

重大更改

移除: File.path

Electron 的早期版本在 Web File 对象中添加了非标准 path 属性作为在渲染器中执行所有操作更为常见时处理本机文件的便捷方法。 然而它偏离了标准,并且也带来了较小的安全风险,因此从 Electron 32 开始它已被移除,取而代之的是 webUtils.getPathForFile 方法。

// Before (renderer)
const file = document.querySelector('input[type=file]');
alert(`Uploaded file path was: ${file.path}`);
// After (renderer)
const file = document.querySelector('input[type=file]');
electron.showFilePath(file);

// After (preload)
const { contextBridge, webUtils } = require('electron');

contextBridge.exposeInMainWorld('electron', {
showFilePath(file) {
// It's best not to expose the full file path to the web content if
// possible.
const path = webUtils.getPathForFile(file);
alert(`Uploaded file path was: ${path}`);
},
});

废弃:WebContents 中的 clearHistory, canGoBack, goBack, canGoForward, goForward, goToIndex, canGoToOffset, goToOffset

WebContents 实例上与导航相关的API现在已被废弃。 这些API已被移动到WebContentsnavigationHistory 属性,以便为管理导航历史提供一个更有条理和直观的接口。

// Deprecated
win.webContents.clearHistory();
win.webContents.canGoBack();
win.webContents.goBack();
win.webContents.canGoForward();
win.webContents.goForward();
win.webContents.goToIndex(index);
win.webContents.canGoToOffset();
win.webContents.goToOffset(index);

// Replace with
win.webContents.navigationHistory.clear();
win.webContents.navigationHistory.canGoBack();
win.webContents.navigationHistory.goBack();
win.webContents.navigationHistory.canGoForward();
win.webContents.navigationHistory.goForward();
win.webContents.navigationHistory.canGoToOffset();
win.webContents.navigationHistory.goToOffset(index);

Behavior changed: Directory databases in userData will be deleted

If you have a directory called databases in the directory returned by app.getPath('userData'), it will be deleted when Electron 32 is first run. The databases directory was used by WebSQL, which was removed in Electron 31. Chromium now performs a cleanup that deletes this directory. See issue #45396.

终止对 29.x.y 的支持

根据项目的支持政策,Electron 29.x.y 已经达到了支持的终点。 我们鼓励开发者将应用程序升级到更新的 Electron 版本。

E26(24 年 8月)E33 (24 年 10 月)E28 (25 年 1 月)
32.x.y33.x.y34.x.y
31.x.y32.x.y33.x.y
30.x.y31.x.y32.x.y

接下来

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

您可以在此处找到 Electron 的公开时间表

有关这些和未来变化的更多信息可在计划的突破性变化页面找到。

Electron 31.0.0

· 阅读时间:约 4 分钟

Electron 31.0.0 已发布! 包括升级 Chromium 126.0.6478.36,和 V8 12.6 以及 Node. js 20.14.2


Electron 团队很高兴发布了 Electron 31.0.0 ! 你可以通过 npm install electron@latest 或者从我们的发布网站下载它。 继续阅读此版本的详细信息。

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

重要变化

重点内容

  • 扩展 WebContentsView 以接受预先存在的 webContents 对象 #42319
  • 添加了对 NODE_EXTRA_CA_CERTS 的支持。 #41689
  • 更新了 window.flashFrame(bool) 以在 macOS 上持续闪烁。 #41391
  • 移除了 WebSQL 支持。#41868
  • nativeImage.toDataURL 将保留 PNG 颜色空间 #41610
  • 扩展 webContents.setWindowOpenHandler 以支持手动创建 BrowserWindow。 #41432

架构(Stack)更新

Electron 31 将 Chromium 从 114.0.6367.49 升级到 122.. 0.661.39, Node 从 20.11.2 升级到 20.14.0,V8 从 12.4 升级到 12.6

新特性

  • 添加 clearData 方法支 Session. #40983
    • 添加参数到 Session.clearData API。 #41355
  • 添加了对 navigator.serial 中的服务类ID请求的蓝牙端口的支持。 #41638
  • 支持 Node's NODE_EXTRA_CA_CERTS 环境变量. #41689
  • 扩展 webContents.setWindowOpenHandler 以支持手动创建 BrowserWindow。 #41432
  • 实现了对 web 标准 File System API 的支持。 #41419
  • 扩展 WebContentsView 以接受预先存在的 webContents 对象 #42319
  • 在 webContents API 上添加了一个新的实例属性 navigationHistory,配合 navigationHistory.getEntryAtIndex 方法,使应用能够检索浏览历史中任何导航条目的 URL 和标题。 #41577 (Also in 29, 30)

重大更改

移除: WebSQL 的支持

Chromium has removed support for WebSQL upstream, transitioning it to Android only. 更多信息,请阅读 Chromium's 移除意图的讨论

行为变更:nativeImage.toDataURL 将保留 PNG 色彩空间。

PNG 解码器已支持保留颜色空间数据。 从此函数返回的编码数据现在与预期结果匹配。

更多信息,请阅读 crbug.com/332584706

行为变更:win.flashFrame(bool) 将在 macOS 上持续闪烁 Dock 图标。

This brings the behavior to parity with Windows and Linux. 之前的行为:第一次调用 flashFrame(true) 只会使 Dock 图标弹跳一次 (使用 NSInformationalRequest level),调用 flashFrame(false) 不会有任何效果。 现在的行为:持续闪烁,直到调用 flashFrame(false)。 使用了 NSCriticalRequest 级别替换。 如果要明确使用 NSInformationalRequest 使 Dock 图标弹跳一次,仍然可以使用 dock.bounce('informational').

终止对 28.x.y 的支持

根据项目的支持政策,Electron 28.x.y 已经达到了支持的终点。 我们鼓励开发者将应用程序升级到更新的 Electron 版本。

E31 (24 年 6 月)E26(24 年 8月)E33 (24 年 10 月)
31.x.y32.x.y33.x.y
30.x.y31.x.y32.x.y
28.x.y29.x.y31.x.y

接下来

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

您可以在此处找到 Electron 的公开时间表

有关这些和未来变化的更多信息可在计划的突破性变化页面找到。