显著变化

1. Electron版本发布周期变化

从 Electron 15 开始,新的 major 版本发布周期会从 12 周改为 8 周。
New Electron Release Cadence
此外,到 2022 年 5 月前,Electron 会由原来支持最新 3 个版本改为支持最新 4 个版本。
Electron Versioning

2. 技术栈变化

Electron 17 使用以下版本:

  • Chromium 98
  • Node.js 16.13.0
  • V8 9.8

V8 9.7-9.8 新特性

亮点特性

1. 新增 webContents.getMediaSourceId() 以获取页面的媒体流

新增的webContents.getMediaSourceId()支持和navigator.mediaDevices.getUserMedia() 一起使用,以从页面 webContents 的媒体流 [MediaStream](https://developer.mozilla.org/zh-CN/docs/Web/API/MediaStream)的 id。
[navigator.mediaDevices.getUserMedia()](https://developer.mozilla.org/zh-CN/docs/Web/API/MediaDevices/getUserMedia) 是 web API,可以用于从桌面捕获音频和视频的媒体源的信息。
其实在之前的版本已经有 desktopCapturer.getMediaSourceIdForWebContents() 这个 API 通过 DesktopCapturer提供相同的能力,但后来发现只能在渲染进程使用,与原本官方宣称在主进程和渲染进程都能使用相悖。所以官方把 API 从 DesktopCapturer 迁移到了WebContents下,但因为 WebContents 是主进程模块,也意味着该 API 现在只能在主进程使用。
PR 链接

2. 废弃 webContents.getPrinters(),加入webContents.getPrintersAsync()

同步的易阻塞的 API webContents.getPrinters() 被废弃,引入了新 API webContents.getPrintersAsync() 以提供异步获取系统打印机列表。
PR 链接

3. desktopCapturer.getSources 只能在主进程使用了

出于安全考虑,官方移除了渲染进程里的[desktopCapturer.getSources](https://www.electronjs.org/zh/docs/latest/api/desktop-capturer#desktopcapturergetsourcesoptions),现在该 API 只能在主进程使用了。该改动是用于防止渲染进程在没有经过主进程许可的情况下捕获桌面窗口内容(视频/音频)。
如果想在渲染进程使用,可以通过 ipc 通信(参考):

  1. // Main process
  2. const { ipcMain, desktopCapturer } = require('electron')
  3. ipcMain.handle(
  4. 'DESKTOP_CAPTURER_GET_SOURCES',
  5. (event, opts) => desktopCapturer.getSources(opts)
  6. )
  1. // Renderer process
  2. const { ipcRenderer } = require('electron')
  3. const desktopCapturer = {
  4. getSources: (opts) => ipcRenderer.invoke('DESKTOP_CAPTURER_GET_SOURCES', opts)
  5. }

PR 链接

更多特性,可看 Electron 17 发布版本通知

突破性变化

Electron 17 没有突破性变化

更多未来的突破性变化,可看 Planned Breaking Changes

版本支持

结束支持 Electron 13.x.y。接下来的版本支持时间表:

E15 (21年9月) E16 (21年11月) E17 (22年2月) E18 (22年3月) E19 (22年5月)
15.x.y 16.x.y 17.x.y 18.x.y 19.x.y
14.x.y 15.x.y 16.x.y 17.x.y 18.x.y
13.x.y 14.x.y 15.x.y 16.x.y 17.x.y
12.x.y 13.x.y 14.x.y 15.x.y

原文链接

Electron 17.0.0