2018-05-29 09:15:30 +00:00
# API Contract
2019-05-02 22:17:17 +00:00
Breaking changes will be documented here, and deprecation warnings added to JS code where possible, at least [one major version ](../tutorial/electron-versioning.md#semver ) before the change is made.
2018-05-29 09:15:30 +00:00
2019-04-25 22:14:19 +00:00
## `FIXME` comments
2018-05-29 09:15:30 +00:00
The `FIXME` string is used in code comments to denote things that should be fixed for future releases. See https://github.com/electron/electron/search?q=fixme
2019-04-25 22:14:19 +00:00
## Planned Breaking API Changes (6.0)
2018-12-17 22:01:00 +00:00
2019-04-25 22:14:19 +00:00
### `win.setMenu(null)`
2019-01-31 18:58:23 +00:00
```js
// Deprecated
win.setMenu(null)
// Replace with
win.removeMenu()
```
2019-04-25 22:14:19 +00:00
### `contentTracing.getTraceBufferUsage()`
2019-02-13 21:24:57 +00:00
```js
// Deprecated
contentTracing.getTraceBufferUsage((percentage, value) => {
// do something
})
// Replace with
contentTracing.getTraceBufferUsage().then(infoObject => {
// infoObject has percentage and value fields
})
```
2019-04-25 22:14:19 +00:00
### `electron.screen` in renderer process
2018-12-17 22:01:00 +00:00
```js
// Deprecated
require('electron').screen
// Replace with
require('electron').remote.screen
```
2019-04-25 22:14:19 +00:00
### `require` in sandboxed renderers
2018-12-17 22:01:00 +00:00
```js
// Deprecated
require('child_process')
// Replace with
require('electron').remote.require('child_process')
// Deprecated
require('fs')
// Replace with
require('electron').remote.require('fs')
// Deprecated
require('os')
// Replace with
require('electron').remote.require('os')
// Deprecated
require('path')
// Replace with
require('electron').remote.require('path')
```
2019-04-25 22:14:19 +00:00
### `powerMonitor.querySystemIdleState`
2019-02-27 20:54:01 +00:00
```js
// Deprecated
powerMonitor.querySystemIdleState(threshold, callback)
// Replace with synchronous API
const idleState = getSystemIdleState(threshold)
```
2019-04-25 22:14:19 +00:00
### `powerMonitor.querySystemIdleTime`
2019-02-27 20:54:01 +00:00
```js
// Deprecated
powerMonitor.querySystemIdleTime(callback)
// Replace with synchronous API
const idleTime = getSystemIdleTime()
```
2019-04-24 04:07:40 +00:00
## `app.enableMixedSandbox`
```js
// Deprecated
app.enableMixedSandbox()
```
Mixed-sandbox mode is now enabled by default.
2019-04-25 22:14:19 +00:00
### Preload scripts outside of app path are not allowed
2019-03-28 10:38:51 +00:00
For security reasons, preload scripts can only be loaded from a subpath of the [app path ](app.md#appgetapppath ).
2019-04-25 22:14:19 +00:00
## Planned Breaking API Changes (5.0)
2018-10-10 05:36:18 +00:00
2019-04-25 22:14:19 +00:00
### `new BrowserWindow({ webPreferences })`
2018-10-10 05:36:18 +00:00
The following `webPreferences` option default values are deprecated in favor of the new defaults listed below.
| Property | Deprecated Default | New Default |
|----------|--------------------|-------------|
| `contextIsolation` | `false` | `true` |
| `nodeIntegration` | `true` | `false` |
| `webviewTag` | `nodeIntegration` if set else `true` | `false` |
2019-04-26 20:30:45 +00:00
E.g. Re-enabling the webviewTag
```js
const w = new BrowserWindow({
webPreferences: {
webviewTag: true
}
})
```
2019-04-25 22:14:19 +00:00
### `nativeWindowOpen`
2018-10-25 06:31:07 +00:00
Child windows opened with the `nativeWindowOpen` option will always have Node.js integration disabled.
2018-05-29 09:15:30 +00:00
2019-04-25 22:14:19 +00:00
### Privileged Schemes Registration
2019-01-29 07:11:01 +00:00
Renderer process APIs `webFrame.setRegisterURLSchemeAsPrivileged` and `webFrame.registerURLSchemeAsBypassingCSP` as well as browser process API `protocol.registerStandardSchemes` have been removed.
A new API, `protocol.registerSchemesAsPrivileged` has been added and should be used for registering custom schemes with the required privileges. Custom schemes are required to be registered before app ready.
2019-04-25 22:14:19 +00:00
### webFrame Isolated World APIs
2019-02-13 18:05:28 +00:00
```js
// Deprecated
webFrame.setIsolatedWorldContentSecurityPolicy(worldId, csp)
webFrame.setIsolatedWorldHumanReadableName(worldId, name)
webFrame.setIsolatedWorldSecurityOrigin(worldId, securityOrigin)
// Replace with
webFrame.setIsolatedWorldInfo(
worldId,
{
securityOrigin: 'some_origin',
name: 'human_readable_name',
csp: 'content_security_policy'
})
```
2019-04-25 22:14:19 +00:00
## Planned Breaking API Changes (4.0)
2018-05-29 09:17:26 +00:00
2019-01-31 18:58:23 +00:00
The following list includes the breaking API changes made in Electron 4.0.
2018-05-29 09:17:26 +00:00
2019-04-25 22:14:19 +00:00
### `app.makeSingleInstance`
2018-05-29 09:17:26 +00:00
```js
// Deprecated
2018-12-05 12:14:52 +00:00
app.makeSingleInstance((argv, cwd) => {
/* ... */
2018-05-29 09:17:26 +00:00
})
// Replace with
app.requestSingleInstanceLock()
2018-12-05 12:14:52 +00:00
app.on('second-instance', (event, argv, cwd) => {
/* ... */
2018-05-29 09:17:26 +00:00
})
```
2019-04-25 22:14:19 +00:00
### `app.releaseSingleInstance`
2018-05-29 09:17:26 +00:00
```js
// Deprecated
app.releaseSingleInstance()
// Replace with
app.releaseSingleInstanceLock()
```
2019-04-25 22:14:19 +00:00
### `app.getGPUInfo`
2018-10-08 04:06:50 +00:00
```js
app.getGPUInfo('complete')
// Now behaves the same with `basic` on macOS
app.getGPUInfo('basic')
```
2019-04-25 22:14:19 +00:00
### `win_delay_load_hook`
2018-11-20 00:13:50 +00:00
When building native modules for windows, the `win_delay_load_hook` variable in
the module's `binding.gyp` must be true (which is the default). If this hook is
not present, then the native module will fail to load on Windows, with an error
message like `Cannot find module` . See the [native module
guide](/docs/tutorial/using-native-node-modules.md) for more.
2019-04-25 22:14:19 +00:00
## Breaking API Changes (3.0)
2016-09-07 18:41:54 +00:00
2018-06-27 06:47:01 +00:00
The following list includes the breaking API changes in Electron 3.0.
2016-09-07 18:41:54 +00:00
2019-04-25 22:14:19 +00:00
### `app`
2017-05-18 03:01:06 +00:00
```js
// Deprecated
app.getAppMemoryInfo()
// Replace with
app.getAppMetrics()
2018-06-27 06:47:01 +00:00
// Deprecated
const metrics = app.getAppMetrics()
2018-09-13 16:10:51 +00:00
const { memory } = metrics[0] // Deprecated property
2017-05-18 03:01:06 +00:00
```
2019-04-25 22:14:19 +00:00
### `BrowserWindow`
2016-09-08 16:09:49 +00:00
```js
// Deprecated
2018-09-13 16:10:51 +00:00
let optionsA = { webPreferences: { blinkFeatures: '' } }
2016-09-08 16:15:05 +00:00
let windowA = new BrowserWindow(optionsA)
2016-09-08 16:09:49 +00:00
// Replace with
2018-09-13 16:10:51 +00:00
let optionsB = { webPreferences: { enableBlinkFeatures: '' } }
2016-09-08 16:15:05 +00:00
let windowB = new BrowserWindow(optionsB)
2018-05-21 01:52:04 +00:00
// Deprecated
window.on('app-command', (e, cmd) => {
if (cmd === 'media-play_pause') {
// do something
}
})
// Replace with
window.on('app-command', (e, cmd) => {
if (cmd === 'media-play-pause') {
// do something
}
})
2016-09-08 16:09:49 +00:00
```
2019-04-25 22:14:19 +00:00
### `clipboard`
2016-09-08 16:09:49 +00:00
2016-09-07 18:41:54 +00:00
```js
// Deprecated
clipboard.readRtf()
// Replace with
clipboard.readRTF()
// Deprecated
clipboard.writeRtf()
// Replace with
clipboard.writeRTF()
// Deprecated
clipboard.readHtml()
// Replace with
clipboard.readHTML()
// Deprecated
clipboard.writeHtml()
// Replace with
clipboard.writeHTML()
2016-09-08 16:09:49 +00:00
```
2019-04-25 22:14:19 +00:00
### `crashReporter`
2016-11-28 23:06:03 +00:00
```js
// Deprecated
crashReporter.start({
companyName: 'Crashly',
submitURL: 'https://crash.server.com',
autoSubmit: true
})
// Replace with
crashReporter.start({
companyName: 'Crashly',
submitURL: 'https://crash.server.com',
uploadToServer: true
})
```
2019-04-25 22:14:19 +00:00
### `nativeImage`
2016-09-07 18:41:54 +00:00
2016-09-08 16:09:49 +00:00
```js
2016-12-14 18:12:37 +00:00
// Deprecated
nativeImage.createFromBuffer(buffer, 1.0)
// Replace with
nativeImage.createFromBuffer(buffer, {
scaleFactor: 1.0
})
2016-09-08 16:09:49 +00:00
```
2016-09-07 18:41:54 +00:00
2019-04-25 22:14:19 +00:00
### `process`
2018-06-27 06:47:01 +00:00
```js
// Deprecated
const info = process.getProcessMemoryInfo()
```
2019-04-25 22:14:19 +00:00
### `screen`
2016-09-16 22:57:07 +00:00
```js
// Deprecated
2018-03-07 07:06:33 +00:00
screen.getMenuBarHeight()
2016-09-16 22:57:07 +00:00
// Replace with
2018-03-07 07:06:33 +00:00
screen.getPrimaryDisplay().workArea
2016-09-16 22:57:07 +00:00
```
2019-04-25 22:14:19 +00:00
### `session`
2017-02-07 23:44:56 +00:00
```js
// Deprecated
2018-12-05 12:14:52 +00:00
ses.setCertificateVerifyProc((hostname, certificate, callback) => {
2017-02-07 23:44:56 +00:00
callback(true)
})
// Replace with
2018-12-05 12:14:52 +00:00
ses.setCertificateVerifyProc((request, callback) => {
2017-02-07 23:44:56 +00:00
callback(0)
})
```
2019-04-25 22:14:19 +00:00
### `Tray`
2016-09-07 18:41:54 +00:00
2016-09-08 16:09:49 +00:00
```js
2016-09-07 18:41:54 +00:00
// Deprecated
tray.setHighlightMode(true)
// Replace with
tray.setHighlightMode('on')
// Deprecated
tray.setHighlightMode(false)
// Replace with
tray.setHighlightMode('off')
2016-09-08 16:09:49 +00:00
```
2016-09-07 18:41:54 +00:00
2019-04-25 22:14:19 +00:00
### `webContents`
2016-09-08 16:09:49 +00:00
```js
2016-09-07 18:41:54 +00:00
// Deprecated
2018-09-13 16:10:51 +00:00
webContents.openDevTools({ detach: true })
2016-09-07 18:41:54 +00:00
// Replace with
2018-09-13 16:10:51 +00:00
webContents.openDevTools({ mode: 'detach' })
2018-08-23 01:45:43 +00:00
// Removed
webContents.setSize(options)
// There is no replacement for this API
2016-09-07 18:41:54 +00:00
```
2016-11-04 21:30:14 +00:00
2019-04-25 22:14:19 +00:00
### `webFrame`
2016-11-22 16:11:14 +00:00
```js
2016-11-14 18:33:30 +00:00
// Deprecated
webFrame.registerURLSchemeAsSecure('app')
// Replace with
2018-09-13 16:10:51 +00:00
protocol.registerStandardSchemes(['app'], { secure: true })
2016-11-14 18:33:30 +00:00
// Deprecated
2018-09-13 16:10:51 +00:00
webFrame.registerURLSchemeAsPrivileged('app', { secure: true })
2016-11-14 18:33:30 +00:00
// Replace with
2018-09-13 16:10:51 +00:00
protocol.registerStandardSchemes(['app'], { secure: true })
2016-11-22 16:11:14 +00:00
```
2019-04-25 22:14:19 +00:00
### `<webview>`
2018-08-23 01:45:43 +00:00
```js
// Removed
webview.setAttribute('disableguestresize', '')
// There is no replacement for this API
// Removed
webview.setAttribute('guestinstance', instanceId)
// There is no replacement for this API
2018-08-29 06:59:23 +00:00
// Keyboard listeners no longer work on webview tag
webview.onkeydown = () => { /* handler */ }
webview.onkeyup = () => { /* handler */ }
2018-08-23 01:45:43 +00:00
```
2019-04-25 22:14:19 +00:00
### Node Headers URL
2016-11-04 21:30:14 +00:00
This is the URL specified as `disturl` in a `.npmrc` file or as the `--dist-url`
command line flag when building native Node modules.
Deprecated: https://atom.io/download/atom-shell
Replace with: https://atom.io/download/electron
2017-06-15 19:46:25 +00:00
2019-04-25 22:14:19 +00:00
## Breaking API Changes (2.0)
2018-05-29 09:23:28 +00:00
2018-05-29 09:42:20 +00:00
The following list includes the breaking API changes made in Electron 2.0.
2019-04-25 22:14:19 +00:00
### `BrowserWindow`
2018-05-29 09:23:28 +00:00
```js
// Deprecated
2018-09-13 16:10:51 +00:00
let optionsA = { titleBarStyle: 'hidden-inset' }
2018-05-29 09:23:28 +00:00
let windowA = new BrowserWindow(optionsA)
// Replace with
2018-09-13 16:10:51 +00:00
let optionsB = { titleBarStyle: 'hiddenInset' }
2018-05-29 09:23:28 +00:00
let windowB = new BrowserWindow(optionsB)
```
2019-04-25 22:14:19 +00:00
### `menu`
2018-05-29 09:23:28 +00:00
```js
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
menu.popup(browserWindow, 100, 200, 2)
2018-05-29 09:37:42 +00:00
// Replaced with
2018-09-13 16:10:51 +00:00
menu.popup(browserWindow, { x: 100, y: 200, positioningItem: 2 })
2018-05-29 09:23:28 +00:00
```
2019-04-25 22:14:19 +00:00
### `nativeImage`
2018-05-29 09:23:28 +00:00
```js
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
nativeImage.toPng()
2018-05-29 09:37:42 +00:00
// Replaced with
2018-05-29 09:23:28 +00:00
nativeImage.toPNG()
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
nativeImage.toJpeg()
2018-05-29 09:37:42 +00:00
// Replaced with
2018-05-29 09:23:28 +00:00
nativeImage.toJPEG()
```
2019-04-25 22:14:19 +00:00
### `process`
2018-05-29 09:23:28 +00:00
* `process.versions.electron` and `process.version.chrome` will be made
read-only properties for consistency with the other `process.versions`
properties set by Node.
2019-04-25 22:14:19 +00:00
### `webContents`
2018-05-29 09:23:28 +00:00
```js
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
webContents.setZoomLevelLimits(1, 2)
2018-05-29 09:37:42 +00:00
// Replaced with
2018-05-29 09:23:28 +00:00
webContents.setVisualZoomLevelLimits(1, 2)
```
2019-04-25 22:14:19 +00:00
### `webFrame`
2018-05-29 09:23:28 +00:00
```js
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
webFrame.setZoomLevelLimits(1, 2)
2018-05-29 09:37:42 +00:00
// Replaced with
2018-05-29 09:23:28 +00:00
webFrame.setVisualZoomLevelLimits(1, 2)
```
2019-04-25 22:14:19 +00:00
### `<webview>`
2018-05-29 09:23:28 +00:00
```js
2018-05-29 09:37:42 +00:00
// Removed
2018-05-29 09:23:28 +00:00
webview.setZoomLevelLimits(1, 2)
2018-05-29 09:37:42 +00:00
// Replaced with
2018-05-29 09:23:28 +00:00
webview.setVisualZoomLevelLimits(1, 2)
```
2019-04-25 22:14:19 +00:00
### Duplicate ARM Assets
2018-05-29 09:23:28 +00:00
2018-05-29 09:37:42 +00:00
Each Electron release includes two identical ARM builds with slightly different
filenames, like `electron-v1.7.3-linux-arm.zip` and
`electron-v1.7.3-linux-armv7l.zip` . The asset with the `v7l` prefix was added
to clarify to users which ARM version it supports, and to disambiguate it from
2018-05-29 09:23:28 +00:00
future armv6l and arm64 assets that may be produced.
2018-05-29 09:37:42 +00:00
The file _without the prefix_ is still being published to avoid breaking any
setups that may be consuming it. Starting at 2.0, the un-prefixed file will
2018-05-29 09:23:28 +00:00
no longer be published.
For details, see
[6986 ](https://github.com/electron/electron/pull/6986 )
2018-05-29 09:37:42 +00:00
and
2018-05-29 09:23:28 +00:00
[7189 ](https://github.com/electron/electron/pull/7189 ).