跳到主要内容

Electron 32.0.0

·阅读时长 4 分钟

Electron 32.0.0 已发布!此版本升级了 Chromium 128.0.6613.36、V8 12.8 和 Node 20.16.0


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

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

重要变更

亮点

  • 在我们的文档中新增了 API 版本历史记录,这是由 @piotrpdev 作为 Google Summer of Code 项目的一部分创建的功能。您可以在这篇博文中了解更多信息。#42982
  • 从 Web File API 中移除了非标准的 File.path 扩展。#42053
  • 在尝试打开被阻止路径中的文件或目录时,将 Web 文件系统 API 中的失败路径与上游对齐。#42993
  • 将以下现有导航相关 API 添加到 webcontents.navigationHistorycanGoBackgoBackcanGoForwardgoForwardcanGoToOffsetgoToOffsetclear。之前的导航 API 现已弃用。#41752

技术栈变更

Electron 32 将 Chromium 从 126.0.6478.36 升级到 128.0.6613.36,将 Node 从 20.14.0 升级到 20.16.0,将 V8 从 12.6 升级到 12.8

新特性

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

重大变更

已移除:File.path

Web File 对象的非标准 path 属性是在 Electron 的早期版本中添加的,作为一种方便的方法,用于在渲染器中处理原生文件,当时这更为常见。然而,它偏离了标准,并且带来轻微的安全风险,因此从 Electron 32.0 开始,它已被移除,取而代之的是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 上的 clearHistorycanGoBackgoBackcanGoForwardgoForwardgoToIndexcanGoToOffsetgoToOffset

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);

行为变更:userData 中的 databases 目录将被删除

如果在 app.getPath('userData') 返回的目录中有一个名为 databases 的目录,它将在 Electron 32 首次运行时被删除。databases 目录用于 WebSQL,WebSQL 已在 Electron 31 中移除。Chromium 现在会执行清理操作,删除此目录。参见议题 #45396

停止支持 29.x.y

根据项目的支持政策,Electron 29.x.y 已达到支持终止期。建议开发者和应用程序升级到更新的 Electron 版本。

E32 (24年8月)E33 (24年10月)E34 (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 的公共时间线。

有关未来变更的更多信息,请参阅计划中的重大变更页面。