Skip to main content

Electron 25.0.0

· 7 min read

Electron 25.0.0 已经发布!它包括对 Chromium 114、V8 11.4 和 Node.js 18.15.0 的升级。请往下阅读了解更多详情!

🌐 Electron 25.0.0 has been released! It includes upgrades to Chromium 114, V8 11.4, and Node.js 18.15.0. Read below for more details!


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

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

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

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

22.x.y 持续支持

🌐 22.x.y Continued Support

如在《告别 Windows 7/8/8.1》(https://www.electronjs.org/blog/windows-7-to-8-1-deprecation-notice) 中所述,Electron 22(Chromium 108)的计划终止支持日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续为该版本提供安全修复的回溯更新,直至 2023 年 10 月 10 日。10 月的支持日期是根据 Chromium 和 Microsoft 的延长支持日期确定的。自 10 月 11 日起,Electron 团队将仅支持最新的三个稳定主版本,这些版本将不再支持 Windows 7/8/8.1。

🌐 As noted in Farewell, Windows 7/8/8.1, Electron 22's (Chromium 108) planned end of life date will be extended from May 30, 2023 to October 10, 2023. The Electron team will continue to backport any security fixes that are part of this program to Electron 22 until October 10, 2023. The October support date follows the extended support dates from both Chromium and Microsoft. On October 11, the Electron team will drop support back to the latest three stable major versions, which will no longer support Windows 7/8/8.1.

E25(2023年5月)E26(2023年8月)E27(2023年10月)
25.x.y26.x.y27.x.y
24.x.y25.x.y26.x.y
23.x.y24.x.y25.x.y
22.x.y22.x.y--

显著变化

🌐 Notable Changes

  • 在 Electron 的 net 模块中实现了 net.fetch,使用了 Chromium 的网络栈。这与 Node 的 fetch() 不同,后者使用 Node.js 的 HTTP 栈。参见 #36733#36606
  • 添加了 protocol.handle,它取代并弃用 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674
  • 为了与 Chromium 以及微软的 Windows 7/8/8.1 弃用计划保持一致,扩展对 Electron 22 的支持。更多详细信息请参见本文博客文章末尾。

技术栈变更

🌐 Stack Changes

重大变化

🌐 Breaking Changes

已弃用:protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol

🌐 Deprecated: protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol

protocol.register*Protocolprotocol.intercept*Protocol 方法已被 protocol.handle 取代。

🌐 The protocol.register*Protocol and protocol.intercept*Protocol methods have been replaced with protocol.handle.

这种新方法可以注册新的协议或拦截现有协议,并且响应可以是任何类型。

🌐 The new method can either register a new protocol or intercept an existing protocol, and responses can be of any type.

// Deprecated in Electron 25
protocol.registerBufferProtocol('some-protocol', () => {
callback({ mimeType: 'text/html', data: Buffer.from('<h5>Response</h5>') });
});

// Replace with
protocol.handle('some-protocol', () => {
return new Response(
Buffer.from('<h5>Response</h5>'), // Could also be a string or ReadableStream.
{ headers: { 'content-type': 'text/html' } },
);
});
// Deprecated in Electron 25
protocol.registerHttpProtocol('some-protocol', () => {
callback({ url: 'https://electron.nodejs.cn' });
});

// Replace with
protocol.handle('some-protocol', () => {
return net.fetch('https://electron.nodejs.cn');
});
// Deprecated in Electron 25
protocol.registerFileProtocol('some-protocol', () => {
callback({ filePath: '/path/to/my/file' });
});

// Replace with
protocol.handle('some-protocol', () => {
return net.fetch('file:///path/to/my/file');
});

已弃用:BrowserWindow.setTrafficLightPosition(position)

🌐 Deprecated: BrowserWindow.setTrafficLightPosition(position)

BrowserWindow.setTrafficLightPosition(position) 已被弃用,应改用 BrowserWindow.setWindowButtonPosition(position) API,该 API 接受 null 而不是 { x: 0, y: 0 } 来将位置重置为系统默认值。

// Deprecated in Electron 25
win.setTrafficLightPosition({ x: 10, y: 10 });
win.setTrafficLightPosition({ x: 0, y: 0 });

// Replace with
win.setWindowButtonPosition({ x: 10, y: 10 });
win.setWindowButtonPosition(null);

已弃用:BrowserWindow.getTrafficLightPosition()

🌐 Deprecated: BrowserWindow.getTrafficLightPosition()

BrowserWindow.getTrafficLightPosition() 已被弃用,应使用 BrowserWindow.getWindowButtonPosition() API,当没有自定义位置时,它会返回 null 而不是 { x: 0, y: 0 }

// Deprecated in Electron 25
const pos = win.getTrafficLightPosition();
if (pos.x === 0 && pos.y === 0) {
// No custom position.
}

// Replace with
const ret = win.getWindowButtonPosition();
if (ret === null) {
// No custom position.
}

新功能

🌐 New Features

  • 已添加 net.fetch()#36733
    • net.fetch 支持对 file: URL 以及通过 protocol.register*Protocol 注册的自定义协议的请求。#36606
  • 新增了 BrowserWindow.set/getWindowButtonPosition API。 #37094
  • 已添加 protocol.handle,替换并废弃 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674
  • webContents<webview> 标签添加了一个 will-frame-navigate 事件,当帧层级中的任何帧尝试导航时触发。#34418
  • 已将发起者信息添加到导航器事件中。此信息可以区分由父框架引起的导航(window.open)与子框架发起的导航。#37085
  • 添加了 net.resolveHost,用于使用 defaultSession 对象解析主机。 #38152
  • app 中新增了 'did-resign-active' 事件。 #38018
  • webContents.print() 添加了几个标准页面大小选项。 #37159
  • 在会话处理器 ses.setDisplayMediaRequestHandler() 回调中添加了 enableLocalEcho 标志,以允许在 audioWebFrameMain 时将远程音频输入回显到本地输出流。#37315
  • 已向 powerMonitor 添加热管理信息。#38028
  • 允许将绝对路径传递给 session.fromPath() API。#37604
  • webContents 上暴露 audio-state-changed 事件。 #37366

下一步计划

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