Критические изменения
Здесь будут описаны критические изменения, а также будут добавлены предупреждения об устаревших функциях в JS коде, где это возможно, по крайней мере перед тем, как изменения будут сделаны в одной мажорной версии.
Типы критических изменений
В этом документе используется следующее соглашение для классификации критических изменений:
- Изменение API: API был изменен таким образом, что код, который не был обновлен, гарантировано бросит исключение.
- Изменение поведения: Поведение Electron было изменено, но не обязательно появление исключений.
- Изменено значение по-умолчанию: Код, работа которого зависит от старого значения по-умолчанию, может сломаться, не обязательно кидая исключение. Старое поведение можно восстановить, если явно указать значение.
- Устарело: API был помечен как устаревший. API продолжит функци онировать, но будет появляться предупреждающее сообщение о том, что API будет удален в будущем релизе.
- Удалено: API или функция была удалена и больше не поддерживается Electron.
Запланированные критические изменения API (33.0)
Behavior Changed: webContents
property on login
on app
The webContents
property in the login
event from app
will be null
when the event is triggered for requests from the utility process created with respondToAuthRequestsFromMainProcess
option.
Deprecated: systemPreferences.accessibilityDisplayShouldReduceTransparency
The systemPreferences.accessibilityDisplayShouldReduceTransparency
property is now deprecated in favor of the new nativeTheme.prefersReducedTransparency
, which provides identical information and works cross-platform.
// Deprecated
const shouldReduceTransparency = systemPreferences.accessibilityDisplayShouldReduceTransparency
// Replace with:
const prefersReducedTransparency = nativeTheme.prefersReducedTransparency
Запланированные критические изменения API (32.0)
Removed: File.path
The nonstandard path
property of the Web File
object was added in an early version of Electron as a convenience method for working with native files when doing everything in the renderer was more common. However, it represents a deviation from the standard and poses a minor security risk as well, so beginning in Electron 32.0 it has been removed in favor of the webUtils.getPathForFile
method.
// 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)
// (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}`)
}
})
Deprecated: clearHistory
, canGoBack
, goBack
, canGoForward
, goForward
, goToIndex
, canGoToOffset
, goToOffset
on WebContents
The navigation-related APIs are now deprecated.
These APIs have been moved to the navigationHistory
property of WebContents
to provide a more structured and intuitive interface for managing navigation history.
// 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)
Запланированные критические изменения API (31.0)
Removed: WebSQL
support
Chromium has removed support for WebSQL upstream, transitioning it to Android only. See Chromium's intent to remove discussion for more information.
Behavior Changed: nativeImage.toDataURL
will preserve PNG colorspace
PNG decoder implementation has been changed to preserve colorspace data, the encoded data returned from this function now matches it.
See crbug.com/332584706 for more information.
Behavior Changed: window.flashFrame(bool)
will flash dock icon continuously on macOS
This brings the behavior to parity with Windows and Linux. Prior behavior: The first flashFrame(true)
bounces the dock icon only once (using the NSInformationalRequest level) and flashFrame(false)
does nothing. New behavior: Flash continuously until flashFrame(false)
is called. This uses the NSCriticalRequest level instead. To explicitly use NSInformationalRequest
to cause a single dock icon bounce, it is still possible to use dock.bounce('informational')
.
Запланированные критические изменения API (30.0)
Behavior Changed: cross-origin iframes now use Permission Policy to access features
Cross-origin iframes must now specify features available to a given iframe
via the allow
attribute in order to access them.
See documentation for more information.
Removed: The --disable-color-correct-rendering
switch
This switch was never formally documented but it's removal is being noted here regardless. Chromium itself now has better support for color spaces so this flag should not be needed.
Behavior Changed: BrowserView.setAutoResize
behavior on macOS
In Electron 30, BrowserView is now a wrapper around the new WebContentsView API.
Previously, the setAutoResize
function of the BrowserView
API was backed by autoresizing on macOS, and by a custom algorithm on Windows and Linux. For simple use cases such as making a BrowserView fill the entire window, the behavior of these two approaches was identical. However, in more advanced cases, BrowserViews would be autoresized differently on macOS than they would be on other platforms, as the custom resizing algorithm for Windows and Linux did not perfectly match the behavior of macOS's autoresizing API. The autoresizing behavior is now standardized across all platforms.
If your app uses BrowserView.setAutoResize
to do anything more complex than making a BrowserView fill the entire window, it's likely you already had custom logic in place to handle this difference in behavior on macOS. If so, that logic will no longer be needed in Electron 30 as autoresizing behavior is consistent.
Deprecated: BrowserView
The BrowserView
class has been deprecated and replaced by the new WebContentsView
class.
BrowserView
related methods in BrowserWindow
have also been deprecated:
BrowserWindow.fromBrowserView(browserView)
win.setBrowserView(browserView)
win.getBrowserView()
win.addBrowserView(browserView)
win.removeBrowserView(browserView)
win.setTopBrowserView(browserView)
win.getBrowserViews()
Removed: params.inputFormType
property on context-menu
on WebContents
The inputFormType
property of the params object in the context-menu
event from WebContents
has been removed. Use the new formControlType
property instead.
Удален: process.getIOCounters()
Chromium has removed access to this information.
Запланированные критические изменения API (29.0)
Behavior Changed: ipcRenderer
can no longer be sent over the contextBridge
Attempting to send the entire ipcRenderer
module as an object over the contextBridge
will now result in an empty object on the receiving side of the bridge. This change was made to remove / mitigate a security footgun. You should not directly expose ipcRenderer or its methods over the bridge. Instead, provide a safe wrapper like below:
contextBridge.exposeInMainWorld('app', {
onEvent: (cb) => ipcRenderer.on('foo', (e, ...args) => cb(args))
})
Removed: renderer-process-crashed
event on app
The renderer-process-crashed
event on app
has been removed. Use the new render-process-gone
event instead.
// Removed
app.on('renderer-process-crashed', (event, webContents, killed) => { /* ... */ })
// Replace with
app.on('render-process-gone', (event, webContents, details) => { /* ... */ })
Removed: crashed
event on WebContents
and <webview>
The crashed
events on WebContents
and <webview>
have been removed. Use the new render-process-gone
event instead.
// Removed
win.webContents.on('crashed', (event, killed) => { /* ... */ })
webview.addEventListener('crashed', (event) => { /* ... */ })
// Replace with
win.webContents.on('render-process-gone', (event, details) => { /* ... */ })
webview.addEventListener('render-process-gone', (event) => { /* ... */ })
Removed: gpu-process-crashed
event on app
The gpu-process-crashed
event on app
has been removed. Use the new child-process-gone
event instead.
// Removed
app.on('gpu-process-crashed', (event, killed) => { /* ... */ })
// Replace with
app.on('child-process-gone', (event, details) => { /* ... */ })
Запланированные критические изменения API (28.0)
Behavior Changed: WebContents.backgroundThrottling
set to false affects all WebContents
in the host BrowserWindow
WebContents.backgroundThrottling
set to false will disable frames throttling in the BrowserWindow
for all WebContents
displayed by it.
Удален: BrowserWindow.setTrafficLightPosition(position)
BrowserWindow.setTrafficLightPosition(position)
has been removed, the BrowserWindow.setWindowButtonPosition(position)
API should be used instead which accepts null
instead of { x: 0, y: 0 }
to reset the position to system default.
// Removed in Electron 28
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()
BrowserWindow.getTrafficLightPosition()
has been removed, the BrowserWindow.getWindowButtonPosition()
API should be used instead which returns null
instead of { x: 0, y: 0 }
when there is no custom position.
// Removed in Electron 28
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.
}
Удален: ipcRenderer.sendTo()
The ipcRenderer.sendTo()
API has been removed. It should be replaced by setting up a MessageChannel
between the renderers.
The senderId
and senderIsMainFrame
properties of IpcRendererEvent
have been removed as well.
Удален: app.runningUnderRosettaTranslation
The app.runningUnderRosettaTranslation
property has been removed. Вместо него используйте app.runningUnderARM64Translation
.
// Removed
console.log(app.runningUnderRosettaTranslation)
// Replace with
console.log(app.runningUnderARM64Translation)
Deprecated: renderer-process-crashed
event on app
The renderer-process-crashed
event on app
has been deprecated. Use the new render-process-gone
event instead.
// Deprecated
app.on('renderer-process-crashed', (event, webContents, killed) => { /* ... */ })
// Replace with
app.on('render-process-gone', (event, webContents, details) => { /* ... */ })
Deprecated: params.inputFormType
property on context-menu
on WebContents
The inputFormType
property of the params object in the context-menu
event from WebContents
has been deprecated. Use the new formControlType
property instead.
Deprecated: crashed
event on WebContents
and <webview>
The crashed
events on WebContents
and <webview>
have been deprecated. Use the new render-process-gone
event instead.
// Deprecated
win.webContents.on('crashed', (event, killed) => { /* ... */ })
webview.addEventListener('crashed', (event) => { /* ... */ })
// Replace with
win.webContents.on('render-process-gone', (event, details) => { /* ... */ })
webview.addEventListener('render-process-gone', (event) => { /* ... */ })
Deprecated: gpu-process-crashed
event on app
The gpu-process-crashed
event on app
has been deprecated. Use the new child-process-gone
event instead.
// Deprecated
app.on('gpu-process-crashed', (event, killed) => { /* ... */ })
// Replace with
app.on('child-process-gone', (event, details) => { /* ... */ })
Запланированные критические изменения API (27.0)
Removed: macOS 10.13 / 10.14 support
macOS 10.13 (High Sierra) and macOS 10.14 (Mojave) are no longer supported by Chromium.
Older versions of Electron will continue to run on these operating systems, but macOS 10.15 (Catalina) or later will be required to run Electron v27.0.0 and higher.
Устарело: ipcRenderer.sendTo()
The ipcRenderer.sendTo()
API has been deprecated. It should be replaced by setting up a MessageChannel
between the renderers.
The senderId
and senderIsMainFrame
properties of IpcRendererEvent
have been deprecated as well.
Removed: color scheme events in systemPreferences
The following systemPreferences
events have been removed:
inverted-color-scheme-changed
high-contrast-color-scheme-changed
Use the new updated
event on the nativeTheme
module instead.
// Removed
systemPreferences.on('inverted-color-scheme-changed', () => { /* ... */ })
systemPreferences.on('high-contrast-color-scheme-changed', () => { /* ... */ })
// Replace with
nativeTheme.on('updated', () => { /* ... */ })
Removed: Some window.setVibrancy
options on macOS
The following vibrancy options have been removed:
- 'light'
- 'medium-light'
- 'dark'
- 'ultra-dark'
- 'appearance-based'
These were previously deprecated and have been removed by Apple in 10.15.
Удален: webContents.getPrinters
The webContents.getPrinters
method has been removed. Используйте вместо него webContents.getPrintersAsync
.
const w = new BrowserWindow({ show: false })
// Removed
console.log(w.webContents.getPrinters())
// Replace with
w.webContents.getPrintersAsync().then((printers) => {
console.log(printers)
})
Removed: systemPreferences.{get,set}AppLevelAppearance
and systemPreferences.appLevelAppearance
The systemPreferences.getAppLevelAppearance
and systemPreferences.setAppLevelAppearance
methods have been removed, as well as the systemPreferences.appLevelAppearance
property. Вместо этого используйте модуль nativeTheme
.
// Removed
systemPreferences.getAppLevelAppearance()
// Replace with
nativeTheme.shouldUseDarkColors
// Removed
systemPreferences.appLevelAppearance
// Replace with
nativeTheme.shouldUseDarkColors
// Removed
systemPreferences.setAppLevelAppearance('dark')
// Replace with
nativeTheme.themeSource = 'dark'
Removed: alternate-selected-control-text
value for systemPreferences.getColor
The alternate-selected-control-text
value for systemPreferences.getColor
has been removed. Вместо него используйте selected-content-background
.
// Removed
systemPreferences.getColor('alternate-selected-control-text')
// Replace with
systemPreferences.getColor('selected-content-background')
Запланированные критические изменения API (26.0)
Устарело: webContents.getPrinters
Метод webContents.getPrinters
устарел. Используйте вместо него webContents.getPrintersAsync
.
const w = new BrowserWindow({ show: false })
// Устарело
console.log(w.webContents.getPrinters())
// Заменить на
w.webContents.getPrintersAsync().then((printers) => {
console.log(printers)
})
Устарело: systemPreferences.{get,set}AppLevelAppearance
и systemPreferences.appLevelAppearance
Методы systemPreferences.getAppLevelAppearance
и systemPreferences.setAppLevelAppearance
устарели, так же как и свойство systemPreferences.appLevelAppearance
. Вместо этого используйте модуль nativeTheme
.
// Устарело
systemPreferences.getAppLevelAppearance()
// Заменить на
nativeTheme.shouldUseDarkColors
// Устарело
systemPreferences.appLevelAppearance
// Заменить на
nativeTheme.shouldUseDarkColors
// Устарело
systemPreferences.setAppLevelAppearance('dark')
// Заменить на
nativeTheme.themeSource = 'dark'
Устарело: значение alternate-selected-control-text
для systemPreferences.getColor
Значение alternate-selected-control-text
для systemPreferences.getColor
устарело. Вместо него используйте selected-content-background
.
// Устарело
systemPreferences.getColor('alternate-selected-control-text')
// Заменить на
systemPreferences.getColor('selected-content-background')