diff --git a/.circleci/config.yml b/.circleci/config.yml index 2ac7b6319e5..c1335e3d2ec 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -119,6 +119,7 @@ build-steps: &build-steps if [ "$RUN_TESTS" != "false" ]; then cd src ninja -C out/Default third_party/electron_node:headers + export ELECTRON_OUT_DIR=Default (cd electron && npm run test -- --ci --enable-logging) fi - <<: *notify-slack-failure @@ -195,6 +196,7 @@ mac-build-steps: &mac-build-steps if [ "$RUN_TESTS" != "false" ]; then cd src ninja -C out/Default third_party/electron_node:headers + export ELECTRON_OUT_DIR=Default (cd electron && npm run test -- --ci --enable-logging) fi - <<: *notify-slack-failure diff --git a/appveyor.yml b/appveyor.yml index 005b8571340..2fa527201ea 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -4,6 +4,7 @@ image: libcc-20-vs2017-15.7.4 environment: GIT_CACHE_PATH: C:\Users\electron\libcc_cache DISABLE_CRASH_REPORTER_TESTS: true + ELECTRON_OUT_DIR: Default build_script: - ps: >- if(($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_NAME -split "/")[0] -eq ($env:APPVEYOR_REPO_NAME -split "/")[0]) { diff --git a/default_app/default_app.js b/default_app/default_app.js index 1b9da74e503..0a000433120 100644 --- a/default_app/default_app.js +++ b/default_app/default_app.js @@ -1,4 +1,4 @@ -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') const path = require('path') let mainWindow = null diff --git a/default_app/main.js b/default_app/main.js index 0e93f684875..e16e67893ea 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -1,4 +1,4 @@ -const {app, dialog, shell, Menu} = require('electron') +const { app, dialog, shell, Menu } = require('electron') const fs = require('fs') const Module = require('module') diff --git a/default_app/renderer.js b/default_app/renderer.js index 977aad7ab9d..e4d10fc27fd 100644 --- a/default_app/renderer.js +++ b/default_app/renderer.js @@ -1,4 +1,4 @@ -const {remote, shell} = require('electron') +const { remote, shell } = require('electron') const fs = require('fs') const path = require('path') const URL = require('url') @@ -7,7 +7,7 @@ const electronPath = path.relative(process.cwd(), remote.process.execPath) Array.from(document.querySelectorAll('a[href]')).forEach(link => { // safely add `?utm_source=default_app let url = URL.parse(link.getAttribute('href'), true) - url.query = Object.assign(url.query, {utm_source: 'default_app'}) + url.query = Object.assign(url.query, { utm_source: 'default_app' }) url = URL.format(url) link.addEventListener('click', (e) => { diff --git a/docs/api/accelerator.md b/docs/api/accelerator.md index f90e409043f..260a19f6c64 100644 --- a/docs/api/accelerator.md +++ b/docs/api/accelerator.md @@ -16,7 +16,7 @@ using the [`register`](global-shortcut.md#globalshortcutregisteraccelerator-call method, i.e. ```javascript -const {app, globalShortcut} = require('electron') +const { app, globalShortcut } = require('electron') app.on('ready', () => { // Register a 'CommandOrControl+Y' shortcut listener. diff --git a/docs/api/app.md b/docs/api/app.md index 14dc557e237..905f5017746 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -8,7 +8,7 @@ The following example shows how to quit the application when the last window is closed: ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('window-all-closed', () => { app.quit() }) @@ -268,7 +268,7 @@ certificate you should prevent the default behavior with `event.preventDefault()` and call `callback(true)`. ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('certificate-error', (event, webContents, url, error, certificate, callback) => { if (url === 'https://github.com') { @@ -300,7 +300,7 @@ and `callback` can be called with an entry filtered from the list. Using certificate from the store. ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('select-client-certificate', (event, webContents, url, list, callback) => { event.preventDefault() @@ -335,7 +335,7 @@ should prevent the default behavior with `event.preventDefault()` and call `callback(username, password)` with the credentials. ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('login', (event, webContents, request, authInfo, callback) => { event.preventDefault() @@ -375,7 +375,7 @@ Returns: Emitted when Electron has created a new `session`. ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('session-created', (event, session) => { console.log(session) @@ -448,9 +448,9 @@ An example of restarting current instance immediately and adding a new command line argument to the new instance: ```javascript -const {app} = require('electron') +const { app } = require('electron') -app.relaunch({args: process.argv.slice(1).concat(['--relaunch'])}) +app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) }) app.exit(0) ``` @@ -712,7 +712,7 @@ items can be obtained using `app.getJumpListSettings()`. Here's a very simple example of creating a custom Jump List: ```javascript -const {app} = require('electron') +const { app } = require('electron') app.setJumpList([ { @@ -798,7 +798,7 @@ An example of activating the window of primary instance when a second instance starts: ```javascript -const {app} = require('electron') +const { app } = require('electron') let myWindow = null const gotTheLock = app.requestSingleInstanceLock() diff --git a/docs/api/breaking-changes.md b/docs/api/breaking-changes.md index e5e5f00b752..3ce08630c5e 100644 --- a/docs/api/breaking-changes.md +++ b/docs/api/breaking-changes.md @@ -49,17 +49,17 @@ app.getAppMetrics() // Deprecated const metrics = app.getAppMetrics() -const {memory} = metrics[0] // Deprecated property +const { memory } = metrics[0] // Deprecated property ``` ## `BrowserWindow` ```js // Deprecated -let optionsA = {webPreferences: {blinkFeatures: ''}} +let optionsA = { webPreferences: { blinkFeatures: '' } } let windowA = new BrowserWindow(optionsA) // Replace with -let optionsB = {webPreferences: {enableBlinkFeatures: ''}} +let optionsB = { webPreferences: { enableBlinkFeatures: '' } } let windowB = new BrowserWindow(optionsB) // Deprecated @@ -175,9 +175,9 @@ tray.setHighlightMode('off') ```js // Deprecated -webContents.openDevTools({detach: true}) +webContents.openDevTools({ detach: true }) // Replace with -webContents.openDevTools({mode: 'detach'}) +webContents.openDevTools({ mode: 'detach' }) // Removed webContents.setSize(options) @@ -190,12 +190,12 @@ webContents.setSize(options) // Deprecated webFrame.registerURLSchemeAsSecure('app') // Replace with -protocol.registerStandardSchemes(['app'], {secure: true}) +protocol.registerStandardSchemes(['app'], { secure: true }) // Deprecated -webFrame.registerURLSchemeAsPrivileged('app', {secure: true}) +webFrame.registerURLSchemeAsPrivileged('app', { secure: true }) // Replace with -protocol.registerStandardSchemes(['app'], {secure: true}) +protocol.registerStandardSchemes(['app'], { secure: true }) ``` ## `` @@ -232,10 +232,10 @@ The following list includes the breaking API changes made in Electron 2.0. ```js // Deprecated -let optionsA = {titleBarStyle: 'hidden-inset'} +let optionsA = { titleBarStyle: 'hidden-inset' } let windowA = new BrowserWindow(optionsA) // Replace with -let optionsB = {titleBarStyle: 'hiddenInset'} +let optionsB = { titleBarStyle: 'hiddenInset' } let windowB = new BrowserWindow(optionsB) ``` @@ -245,7 +245,7 @@ let windowB = new BrowserWindow(optionsB) // Removed menu.popup(browserWindow, 100, 200, 2) // Replaced with -menu.popup(browserWindow, {x: 100, y: 200, positioningItem: 2}) +menu.popup(browserWindow, { x: 100, y: 200, positioningItem: 2 }) ``` ## `nativeImage` diff --git a/docs/api/browser-view.md b/docs/api/browser-view.md index ee1780942db..7174d8bb422 100644 --- a/docs/api/browser-view.md +++ b/docs/api/browser-view.md @@ -16,9 +16,9 @@ relative to its owning window. It is meant to be an alternative to the ```javascript // In the main process. -const {BrowserView, BrowserWindow} = require('electron') +const { BrowserView, BrowserWindow } = require('electron') -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.on('closed', () => { win = null }) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 3c7f42a86a1..8cdb8a19b54 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -6,12 +6,12 @@ Process: [Main](../glossary.md#main-process) ```javascript // In the main process. -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') // Or use `remote` from the renderer process. -// const {BrowserWindow} = require('electron').remote +// const { BrowserWindow } = require('electron').remote -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.on('closed', () => { win = null }) @@ -40,8 +40,8 @@ process has rendered the page for the first time if the window has not been show the window after this event will have no visual flash: ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({show: false}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ show: false }) win.once('ready-to-show', () => { win.show() }) @@ -58,9 +58,9 @@ the app feel slow. In this case, it is recommended to show the window immediately, and use a `backgroundColor` close to your app's background: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let win = new BrowserWindow({backgroundColor: '#2e2c29'}) +let win = new BrowserWindow({ backgroundColor: '#2e2c29' }) win.loadURL('https://github.com') ``` @@ -72,10 +72,10 @@ to set `backgroundColor` to make app feel more native. By using `parent` option, you can create child windows: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let top = new BrowserWindow() -let child = new BrowserWindow({parent: top}) +let child = new BrowserWindow({ parent: top }) child.show() top.show() ``` @@ -88,9 +88,9 @@ A modal window is a child window that disables parent window, to create a modal window, you have to set both `parent` and `modal` options: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let child = new BrowserWindow({parent: top, modal: true, show: false}) +let child = new BrowserWindow({ parent: top, modal: true, show: false }) child.loadURL('https://github.com') child.once('ready-to-show', () => { child.show() @@ -558,7 +558,7 @@ Commands are lowercased, underscores are replaced with hyphens, and the e.g. `APPCOMMAND_BROWSER_BACKWARD` is emitted as `browser-backward`. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.on('app-command', (e, cmd) => { // Navigate the window back when the user hits their mouse back button @@ -692,7 +692,7 @@ an Object containing `name` and `version` properties. To check if a DevTools extension is installed you can run the following: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let installed = BrowserWindow.getDevToolsExtensions().hasOwnProperty('devtron') console.log(installed) @@ -706,9 +706,9 @@ is emitted. Objects created with `new BrowserWindow` have the following properties: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') // In this example `win` is our instance -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('https://github.com') ``` @@ -1085,7 +1085,7 @@ attached just below the window frame, but you may want to display them beneath a HTML-rendered toolbar. For example: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() let toolbarRect = document.getElementById('toolbar').getBoundingClientRect() @@ -1354,7 +1354,7 @@ The `flags` is an array that can include following `String`s: Sets the region of the window to show as the thumbnail image displayed when hovering over the window in the taskbar. You can reset the thumbnail to be the entire window by specifying an empty region: -`{x: 0, y: 0, width: 0, height: 0}`. +`{ x: 0, y: 0, width: 0, height: 0 }`. #### `win.setThumbnailToolTip(toolTip)` _Windows_ diff --git a/docs/api/chrome-command-line-switches.md b/docs/api/chrome-command-line-switches.md index b2b28f5adb7..41b77a162ae 100644 --- a/docs/api/chrome-command-line-switches.md +++ b/docs/api/chrome-command-line-switches.md @@ -7,7 +7,7 @@ your app's main script before the [ready][ready] event of the [app][app] module is emitted: ```javascript -const {app} = require('electron') +const { app } = require('electron') app.commandLine.appendSwitch('remote-debugging-port', '8315') app.commandLine.appendSwitch('host-rules', 'MAP * 127.0.0.1') @@ -72,7 +72,7 @@ list of hosts. This flag has an effect only if used in tandem with For example: ```javascript -const {app} = require('electron') +const { app } = require('electron') app.commandLine.appendSwitch('proxy-bypass-list', ';*.google.com;*foo.com;1.2.3.4:5678') ``` diff --git a/docs/api/clipboard.md b/docs/api/clipboard.md index ed03a4d35c6..429395877af 100644 --- a/docs/api/clipboard.md +++ b/docs/api/clipboard.md @@ -7,7 +7,7 @@ Process: [Main](../glossary.md#main-process), [Renderer](../glossary.md#renderer The following example shows how to write a string to the clipboard: ```javascript -const {clipboard} = require('electron') +const { clipboard } = require('electron') clipboard.writeText('Example String') ``` @@ -15,7 +15,7 @@ On X Window systems, there is also a selection clipboard. To manipulate it you need to pass `selection` to each method: ```javascript -const {clipboard} = require('electron') +const { clipboard } = require('electron') clipboard.writeText('Example String', 'selection') console.log(clipboard.readText('selection')) ``` @@ -141,7 +141,7 @@ Returns `String[]` - An array of supported formats for the clipboard `type`. Returns `Boolean` - Whether the clipboard supports the specified `format`. ```javascript -const {clipboard} = require('electron') +const { clipboard } = require('electron') console.log(clipboard.has('

selection

')) ``` @@ -176,7 +176,7 @@ Writes the `buffer` into the clipboard as `format`. * `type` String (optional) ```javascript -const {clipboard} = require('electron') -clipboard.write({text: 'test', html: 'test'}) +const { clipboard } = require('electron') +clipboard.write({ text: 'test', html: 'test' }) ``` Writes `data` to the clipboard. diff --git a/docs/api/content-tracing.md b/docs/api/content-tracing.md index 158427ddb5b..7fe9f1dd2ff 100644 --- a/docs/api/content-tracing.md +++ b/docs/api/content-tracing.md @@ -14,7 +14,7 @@ module is emitted. ```javascript -const {app, contentTracing} = require('electron') +const { app, contentTracing } = require('electron') app.on('ready', () => { const options = { diff --git a/docs/api/cookies.md b/docs/api/cookies.md index afc20454c8e..813e1fc4fa3 100644 --- a/docs/api/cookies.md +++ b/docs/api/cookies.md @@ -10,7 +10,7 @@ a `Session`. For example: ```javascript -const {session} = require('electron') +const { session } = require('electron') // Query all cookies. session.defaultSession.cookies.get({}, (error, cookies) => { @@ -18,13 +18,13 @@ session.defaultSession.cookies.get({}, (error, cookies) => { }) // Query all cookies associated with a specific url. -session.defaultSession.cookies.get({url: 'http://www.github.com'}, (error, cookies) => { +session.defaultSession.cookies.get({ url: 'http://www.github.com' }, (error, cookies) => { console.log(error, cookies) }) // Set a cookie with the given cookie data; // may overwrite equivalent cookies if they exist. -const cookie = {url: 'http://www.github.com', name: 'dummy_name', value: 'dummy'} +const cookie = { url: 'http://www.github.com', name: 'dummy_name', value: 'dummy' } session.defaultSession.cookies.set(cookie, (error) => { if (error) console.error(error) }) diff --git a/docs/api/crash-reporter.md b/docs/api/crash-reporter.md index 80d266ab563..dcd64a3bbd2 100644 --- a/docs/api/crash-reporter.md +++ b/docs/api/crash-reporter.md @@ -8,7 +8,7 @@ The following is an example of automatically submitting a crash report to a remote server: ```javascript -const {crashReporter} = require('electron') +const { crashReporter } = require('electron') crashReporter.start({ productName: 'YourName', @@ -71,18 +71,18 @@ first call `start` you can call `addExtraParameter` on macOS or call `start` again with the new/updated `extra` parameters on Linux and Windows. ```js - const args = [ - `--reporter-url=${submitURL}`, - `--application-name=${productName}`, - `--crashes-directory=${crashesDirectory}` - ] - const env = { - ELECTRON_INTERNAL_CRASH_SERVICE: 1 - } - spawn(process.execPath, args, { - env: env, - detached: true - }) +const args = [ + `--reporter-url=${submitURL}`, + `--application-name=${productName}`, + `--crashes-directory=${crashesDirectory}` +] +const env = { + ELECTRON_INTERNAL_CRASH_SERVICE: 1 +} +spawn(process.execPath, args, { + env: env, + detached: true +}) ``` **Note:** On macOS, Electron uses a new `crashpad` client for crash collection and reporting. diff --git a/docs/api/debugger.md b/docs/api/debugger.md index 1be33833ed8..f044f4a6fa6 100644 --- a/docs/api/debugger.md +++ b/docs/api/debugger.md @@ -8,7 +8,7 @@ Chrome Developer Tools has a [special binding][rdp] available at JavaScript runtime that allows interacting with pages and instrumenting them. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() try { diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 7b897f2ad1b..71d8d263fd7 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -10,9 +10,9 @@ title is `Electron`: ```javascript // In the renderer process. -const {desktopCapturer} = require('electron') +const { desktopCapturer } = require('electron') -desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { +desktopCapturer.getSources({ types: ['window', 'screen'] }, (error, sources) => { if (error) throw error for (let i = 0; i < sources.length; ++i) { if (sources[i].name === 'Electron') { @@ -28,9 +28,8 @@ desktopCapturer.getSources({types: ['window', 'screen']}, (error, sources) => { maxHeight: 720 } } - }) - .then((stream) => handleStream(stream)) - .catch((e) => handleError(e)) + }).then((stream) => handleStream(stream)) + .catch((e) => handleError(e)) return } } diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 11101ae3ec0..72c07336658 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -7,15 +7,15 @@ Process: [Main](../glossary.md#main-process) An example of showing a dialog to select multiple files and directories: ```javascript -const {dialog} = require('electron') -console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']})) +const { dialog } = require('electron') +console.log(dialog.showOpenDialog({ properties: ['openFile', 'openDirectory', 'multiSelections'] })) ``` The Dialog is opened from Electron's main thread. If you want to use the dialog object from a renderer process, remember to access it using the remote: ```javascript -const {dialog} = require('electron').remote +const { dialog } = require('electron').remote console.log(dialog) ``` @@ -66,10 +66,10 @@ selected when you want to limit the user to a specific type. For example: ```javascript { filters: [ - {name: 'Images', extensions: ['jpg', 'png', 'gif']}, - {name: 'Movies', extensions: ['mkv', 'avi', 'mp4']}, - {name: 'Custom File Type', extensions: ['as']}, - {name: 'All Files', extensions: ['*']} + { name: 'Images', extensions: ['jpg', 'png', 'gif'] }, + { name: 'Movies', extensions: ['mkv', 'avi', 'mp4'] }, + { name: 'Custom File Type', extensions: ['as'] }, + { name: 'All Files', extensions: ['*'] } ] } ``` diff --git a/docs/api/download-item.md b/docs/api/download-item.md index f5265d26a5d..dcf058a4bc1 100644 --- a/docs/api/download-item.md +++ b/docs/api/download-item.md @@ -10,7 +10,7 @@ control the download item. ```javascript // In the main process. -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.webContents.session.on('will-download', (event, item, webContents) => { // Set the save path, making Electron not to prompt a save dialog. diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index 46e496407a8..596e35dc326 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -14,8 +14,8 @@ To create a frameless window, you need to set `frame` to `false` in ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({width: 800, height: 600, frame: false}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ width: 800, height: 600, frame: false }) win.show() ``` @@ -33,8 +33,8 @@ You can do so by specifying the `titleBarStyle` option: Results in a hidden title bar and a full size content window, yet the title bar still has the standard window controls (“traffic lights”) in the top left. ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({titleBarStyle: 'hidden'}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ titleBarStyle: 'hidden' }) win.show() ``` @@ -43,8 +43,8 @@ win.show() Results in a hidden title bar with an alternative look where the traffic light buttons are slightly more inset from the window edge. ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({titleBarStyle: 'hiddenInset'}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ titleBarStyle: 'hiddenInset' }) win.show() ``` @@ -56,8 +56,8 @@ with mouse events that occur with the standard window toolbar buttons. This option is only applicable for frameless windows. ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({titleBarStyle: 'customButtonsOnHover', frame: false}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ titleBarStyle: 'customButtonsOnHover', frame: false }) win.show() ``` @@ -67,8 +67,8 @@ By setting the `transparent` option to `true`, you can also make the frameless window transparent: ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({transparent: true, frame: false}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ transparent: true, frame: false }) win.show() ``` @@ -98,7 +98,7 @@ events, you can call the [win.setIgnoreMouseEvents(ignore)][ignore-mouse-events] API: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.setIgnoreMouseEvents(true) ``` @@ -114,7 +114,7 @@ allowing events such as `mouseleave` to be emitted: let win = require('electron').remote.getCurrentWindow() let el = document.getElementById('clickThroughElement') el.addEventListener('mouseenter', () => { - win.setIgnoreMouseEvents(true, {forward: true}) + win.setIgnoreMouseEvents(true, { forward: true }) }) el.addEventListener('mouseleave', () => { win.setIgnoreMouseEvents(false) diff --git a/docs/api/global-shortcut.md b/docs/api/global-shortcut.md index d0f48a6f805..6632f851de1 100644 --- a/docs/api/global-shortcut.md +++ b/docs/api/global-shortcut.md @@ -13,7 +13,7 @@ not have the keyboard focus. You should not use this module until the `ready` event of the app module is emitted. ```javascript -const {app, globalShortcut} = require('electron') +const { app, globalShortcut } = require('electron') app.on('ready', () => { // Register a 'CommandOrControl+X' shortcut listener. diff --git a/docs/api/ipc-main.md b/docs/api/ipc-main.md index 1dc51f618cc..f4439fe0a6e 100644 --- a/docs/api/ipc-main.md +++ b/docs/api/ipc-main.md @@ -25,7 +25,7 @@ processes: ```javascript // In main process. -const {ipcMain} = require('electron') +const { ipcMain } = require('electron') ipcMain.on('asynchronous-message', (event, arg) => { console.log(arg) // prints "ping" event.sender.send('asynchronous-reply', 'pong') @@ -39,7 +39,7 @@ ipcMain.on('synchronous-message', (event, arg) => { ```javascript // In renderer process (web page). -const {ipcRenderer} = require('electron') +const { ipcRenderer } = require('electron') console.log(ipcRenderer.sendSync('synchronous-message', 'ping')) // prints "pong" ipcRenderer.on('asynchronous-reply', (event, arg) => { diff --git a/docs/api/menu.md b/docs/api/menu.md index e1d6e9958de..21f84c66fa6 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -149,42 +149,42 @@ An example of creating the application menu in the main process with the simple template API: ```javascript -const {app, Menu} = require('electron') +const { app, Menu } = require('electron') const template = [ { label: 'Edit', submenu: [ - {role: 'undo'}, - {role: 'redo'}, - {type: 'separator'}, - {role: 'cut'}, - {role: 'copy'}, - {role: 'paste'}, - {role: 'pasteandmatchstyle'}, - {role: 'delete'}, - {role: 'selectall'} + { role: 'undo' }, + { role: 'redo' }, + { type: 'separator' }, + { role: 'cut' }, + { role: 'copy' }, + { role: 'paste' }, + { role: 'pasteandmatchstyle' }, + { role: 'delete' }, + { role: 'selectall' } ] }, { label: 'View', submenu: [ - {role: 'reload'}, - {role: 'forcereload'}, - {role: 'toggledevtools'}, - {type: 'separator'}, - {role: 'resetzoom'}, - {role: 'zoomin'}, - {role: 'zoomout'}, - {type: 'separator'}, - {role: 'togglefullscreen'} + { role: 'reload' }, + { role: 'forcereload' }, + { role: 'toggledevtools' }, + { type: 'separator' }, + { role: 'resetzoom' }, + { role: 'zoomin' }, + { role: 'zoomout' }, + { type: 'separator' }, + { role: 'togglefullscreen' } ] }, { role: 'window', submenu: [ - {role: 'minimize'}, - {role: 'close'} + { role: 'minimize' }, + { role: 'close' } ] }, { @@ -202,37 +202,37 @@ if (process.platform === 'darwin') { template.unshift({ label: app.getName(), submenu: [ - {role: 'about'}, - {type: 'separator'}, - {role: 'services', submenu: []}, - {type: 'separator'}, - {role: 'hide'}, - {role: 'hideothers'}, - {role: 'unhide'}, - {type: 'separator'}, - {role: 'quit'} + { role: 'about' }, + { type: 'separator' }, + { role: 'services', submenu: [] }, + { type: 'separator' }, + { role: 'hide' }, + { role: 'hideothers' }, + { role: 'unhide' }, + { type: 'separator' }, + { role: 'quit' } ] }) // Edit menu template[1].submenu.push( - {type: 'separator'}, + { type: 'separator' }, { label: 'Speech', submenu: [ - {role: 'startspeaking'}, - {role: 'stopspeaking'} + { role: 'startspeaking' }, + { role: 'stopspeaking' } ] } ) // Window menu template[3].submenu = [ - {role: 'close'}, - {role: 'minimize'}, - {role: 'zoom'}, - {type: 'separator'}, - {role: 'front'} + { role: 'close' }, + { role: 'minimize' }, + { role: 'zoom' }, + { type: 'separator' }, + { role: 'front' } ] } @@ -249,17 +249,17 @@ the user right clicks the page: ```html ``` diff --git a/docs/api/native-image.md b/docs/api/native-image.md index d2951b5b273..33c37dd3b35 100644 --- a/docs/api/native-image.md +++ b/docs/api/native-image.md @@ -11,17 +11,17 @@ For example, when creating a tray or setting a window's icon, you can pass an image file path as a `String`: ```javascript -const {BrowserWindow, Tray} = require('electron') +const { BrowserWindow, Tray } = require('electron') const appIcon = new Tray('/Users/somebody/images/icon.png') -let win = new BrowserWindow({icon: '/Users/somebody/images/window.png'}) +let win = new BrowserWindow({ icon: '/Users/somebody/images/window.png' }) console.log(appIcon, win) ``` Or read the image from the clipboard which returns a `NativeImage`: ```javascript -const {clipboard, Tray} = require('electron') +const { clipboard, Tray } = require('electron') const image = clipboard.readImage() const appIcon = new Tray(image) console.log(appIcon) @@ -73,7 +73,7 @@ images/ ```javascript -const {Tray} = require('electron') +const { Tray } = require('electron') let appIcon = new Tray('/Users/somebody/images/icon.png') console.log(appIcon) ``` diff --git a/docs/api/net-log.md b/docs/api/net-log.md index 5e82a83a14d..dda984fead9 100644 --- a/docs/api/net-log.md +++ b/docs/api/net-log.md @@ -5,7 +5,7 @@ Process: [Main](../glossary.md#main-process) ```javascript -const {netLog} = require('electron') +const { netLog } = require('electron') console.log('Start recording net-logs') netLog.startLogging('/path/to/net-log') // After some network events diff --git a/docs/api/net.md b/docs/api/net.md index e5e59617148..0236923d780 100644 --- a/docs/api/net.md +++ b/docs/api/net.md @@ -30,9 +30,9 @@ For instance, the following example quickly shows how the `net` API might be used: ```javascript -const {app} = require('electron') +const { app } = require('electron') app.on('ready', () => { - const {net} = require('electron') + const { net } = require('electron') const request = net.request('https://github.com') request.on('response', (response) => { console.log(`STATUS: ${response.statusCode}`) diff --git a/docs/api/power-monitor.md b/docs/api/power-monitor.md index 4f45031d53f..95d9e025e85 100644 --- a/docs/api/power-monitor.md +++ b/docs/api/power-monitor.md @@ -11,7 +11,7 @@ For example: ```javascript const electron = require('electron') -const {app} = electron +const { app } = electron app.on('ready', () => { electron.powerMonitor.on('suspend', () => { diff --git a/docs/api/power-save-blocker.md b/docs/api/power-save-blocker.md index ea9a81f3f50..548b02756c6 100644 --- a/docs/api/power-save-blocker.md +++ b/docs/api/power-save-blocker.md @@ -7,7 +7,7 @@ Process: [Main](../glossary.md#main-process) For example: ```javascript -const {powerSaveBlocker} = require('electron') +const { powerSaveBlocker } = require('electron') const id = powerSaveBlocker.start('prevent-display-sleep') console.log(powerSaveBlocker.isStarted(id)) diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 4e14a5f8cad..1a6a0f8532a 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -8,13 +8,13 @@ An example of implementing a protocol that has the same effect as the `file://` protocol: ```javascript -const {app, protocol} = require('electron') +const { app, protocol } = require('electron') const path = require('path') app.on('ready', () => { protocol.registerFileProtocol('atom', (request, callback) => { const url = request.url.substr(7) - callback({path: path.normalize(`${__dirname}/${url}`)}) + callback({ path: path.normalize(`${__dirname}/${url}`) }) }, (error) => { if (error) console.error('Failed to register protocol') }) @@ -62,7 +62,7 @@ are disabled for non standard schemes. So in general if you want to register a custom protocol to replace the `http` protocol, you have to register it as a standard scheme: ```javascript -const {app, protocol} = require('electron') +const { app, protocol } = require('electron') protocol.registerStandardSchemes(['atom']) app.on('ready', () => { @@ -99,7 +99,7 @@ going to be created with `scheme`. `completion` will be called with To handle the `request`, the `callback` should be called with either the file's path or an object that has a `path` property, e.g. `callback(filePath)` or -`callback({path: filePath})`. +`callback({ path: filePath })`. When `callback` is called with nothing, a number, or an object that has an `error` property, the `request` will fail with the `error` number you @@ -134,10 +134,10 @@ should be called with either a `Buffer` object or an object that has the `data`, Example: ```javascript -const {protocol} = require('electron') +const { protocol } = require('electron') protocol.registerBufferProtocol('atom', (request, callback) => { - callback({mimeType: 'text/html', data: Buffer.from('
Response
')}) + callback({ mimeType: 'text/html', data: Buffer.from('
Response
') }) }, (error) => { if (error) console.error('Failed to register protocol') }) @@ -218,8 +218,8 @@ has the `data`, `statusCode`, and `headers` properties. Example: ```javascript -const {protocol} = require('electron') -const {PassThrough} = require('stream') +const { protocol } = require('electron') +const { PassThrough } = require('stream') function createStream (text) { const rv = new PassThrough() // PassThrough is also a Readable stream @@ -245,7 +245,7 @@ It is possible to pass any object that implements the readable stream API (emits `data`/`end`/`error` events). For example, here's how a file could be returned: ```javascript -const {protocol} = require('electron') +const { protocol } = require('electron') const fs = require('fs') protocol.registerStreamProtocol('atom', (request, callback) => { diff --git a/docs/api/remote.md b/docs/api/remote.md index cb7eaec1793..4bff0926162 100644 --- a/docs/api/remote.md +++ b/docs/api/remote.md @@ -16,8 +16,8 @@ similar to Java's [RMI][rmi]. An example of creating a browser window from a renderer process: ```javascript -const {BrowserWindow} = require('electron').remote -let win = new BrowserWindow({width: 800, height: 600}) +const { BrowserWindow } = require('electron').remote +let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('https://github.com') ``` @@ -158,7 +158,7 @@ project/ ```js // main process: main/index.js -const {app} = require('electron') +const { app } = require('electron') app.on('ready', () => { /* ... */ }) ``` diff --git a/docs/api/sandbox-option.md b/docs/api/sandbox-option.md index 8a9d242fce0..1298eec5db3 100644 --- a/docs/api/sandbox-option.md +++ b/docs/api/sandbox-option.md @@ -115,7 +115,7 @@ and preload.js: // private scope that can access a subset of Electron renderer APIs. We must be // careful to not leak any objects into the global scope! const fs = require('fs') -const {ipcRenderer} = require('electron') +const { ipcRenderer } = require('electron') // read a configuration file using the `fs` module const buf = fs.readFileSync('allowed-popup-urls.json') diff --git a/docs/api/screen.md b/docs/api/screen.md index bb3aed2c413..d847b55abdd 100644 --- a/docs/api/screen.md +++ b/docs/api/screen.md @@ -10,19 +10,19 @@ module is emitted. `screen` is an [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter). **Note:** In the renderer / DevTools, `window.screen` is a reserved DOM -property, so writing `let {screen} = require('electron')` will not work. +property, so writing `let { screen } = require('electron')` will not work. An example of creating a window that fills the whole screen: ```javascript const electron = require('electron') -const {app, BrowserWindow} = electron +const { app, BrowserWindow } = electron let win app.on('ready', () => { - const {width, height} = electron.screen.getPrimaryDisplay().workAreaSize - win = new BrowserWindow({width, height}) + const { width, height } = electron.screen.getPrimaryDisplay().workAreaSize + win = new BrowserWindow({ width, height }) win.loadURL('https://github.com') }) ``` @@ -31,7 +31,7 @@ Another example of creating a window in the external display: ```javascript const electron = require('electron') -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win diff --git a/docs/api/session.md b/docs/api/session.md index e7f782187ba..1d706e9c46f 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -10,9 +10,9 @@ You can also access the `session` of existing pages by using the `session` property of [`WebContents`](web-contents.md), or from the `session` module. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('http://github.com') const ses = win.webContents.session @@ -59,7 +59,7 @@ Process: [Main](../glossary.md#main-process) You can create a `Session` object in the `session` module: ```javascript -const {session} = require('electron') +const { session } = require('electron') const ses = session.fromPartition('persist:name') console.log(ses.getUserAgent()) ``` @@ -80,7 +80,7 @@ Calling `event.preventDefault()` will cancel the download and `item` will not be available from next tick of the process. ```javascript -const {session} = require('electron') +const { session } = require('electron') session.defaultSession.on('will-download', (event, item, webContents) => { event.preventDefault() require('request')(item.getURL(), (data) => { @@ -239,7 +239,7 @@ window.webContents.session.enableNetworkEmulation({ }) // To emulate a network outage. -window.webContents.session.enableNetworkEmulation({offline: true}) +window.webContents.session.enableNetworkEmulation({ offline: true }) ``` #### `ses.disableNetworkEmulation()` @@ -272,11 +272,11 @@ Calling `setCertificateVerifyProc(null)` will revert back to default certificate verify proc. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.webContents.session.setCertificateVerifyProc((request, callback) => { - const {hostname} = request + const { hostname } = request if (hostname === 'github.com') { callback(0) } else { @@ -303,7 +303,7 @@ Calling `callback(true)` will allow the permission and `callback(false)` will re To clear the handler, call `setPermissionRequestHandler(null)`. ```javascript -const {session} = require('electron') +const { session } = require('electron') session.fromPartition('some-partition').setPermissionRequestHandler((webContents, permission, callback) => { if (webContents.getURL() === 'some-host' && permission === 'notifications') { return callback(false) // denied. @@ -329,7 +329,7 @@ Returning `true` will allow the permission and `false` will reject it. To clear the handler, call `setPermissionCheckHandler(null)`. ```javascript -const {session} = require('electron') +const { session } = require('electron') session.fromPartition('some-partition').setPermissionCheckHandler((webContents, permission) => { if (webContents.getURL() === 'some-host' && permission === 'notifications') { return false // denied @@ -354,7 +354,7 @@ Dynamically sets whether to always send credentials for HTTP NTLM or Negotiate authentication. ```javascript -const {session} = require('electron') +const { session } = require('electron') // consider any url ending with `example.com`, `foobar.com`, `baz` // for integrated authentication. session.defaultSession.allowNTLMCredentialsForDomains('*example.com, *foobar.com, *baz') @@ -441,14 +441,14 @@ A [WebRequest](web-request.md) object for this session. A [Protocol](protocol.md) object for this session. ```javascript -const {app, session} = require('electron') +const { app, session } = require('electron') const path = require('path') app.on('ready', function () { const protocol = session.fromPartition('some-partition').protocol protocol.registerFileProtocol('atom', function (request, callback) { var url = request.url.substr(7) - callback({path: path.normalize(`${__dirname}/${url}`)}) + callback({ path: path.normalize(`${__dirname}/${url}`) }) }, function (error) { if (error) console.error('Failed to register protocol') }) diff --git a/docs/api/shell.md b/docs/api/shell.md index 45d18add854..a469f9455c0 100644 --- a/docs/api/shell.md +++ b/docs/api/shell.md @@ -9,7 +9,7 @@ The `shell` module provides functions related to desktop integration. An example of opening a URL in the user's default browser: ```javascript -const {shell} = require('electron') +const { shell } = require('electron') shell.openExternal('https://github.com') ``` diff --git a/docs/api/synopsis.md b/docs/api/synopsis.md index 4325acc3e35..8b3ea560947 100644 --- a/docs/api/synopsis.md +++ b/docs/api/synopsis.md @@ -19,11 +19,11 @@ scripts to be able to use those modules. The main process script is like a normal Node.js script: ```javascript -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win = null app.on('ready', () => { - win = new BrowserWindow({width: 800, height: 600}) + win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('https://github.com') }) ``` @@ -36,7 +36,7 @@ extra ability to use node modules: @@ -52,7 +52,7 @@ As of 0.37, you can use built-in modules. ```javascript -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win @@ -67,7 +67,7 @@ destructuring to access the individual modules from `electron`. ```javascript const electron = require('electron') -const {app, BrowserWindow} = electron +const { app, BrowserWindow } = electron let win diff --git a/docs/api/system-preferences.md b/docs/api/system-preferences.md index 88948789cf3..ab4b91dbaf9 100644 --- a/docs/api/system-preferences.md +++ b/docs/api/system-preferences.md @@ -5,7 +5,7 @@ Process: [Main](../glossary.md#main-process) ```javascript -const {systemPreferences} = require('electron') +const { systemPreferences } = require('electron') console.log(systemPreferences.isDarkMode()) ``` @@ -185,8 +185,8 @@ An example of using it to determine if you should create a transparent window or not (transparent windows won't work correctly when DWM composition is disabled): ```javascript -const {BrowserWindow, systemPreferences} = require('electron') -let browserOptions = {width: 1000, height: 800} +const { BrowserWindow, systemPreferences } = require('electron') +let browserOptions = { width: 1000, height: 800 } // Make the window transparent only if the platform supports it. if (process.platform !== 'win32' || systemPreferences.isAeroGlassEnabled()) { diff --git a/docs/api/touch-bar.md b/docs/api/touch-bar.md index dafb75621e5..a5c1f17cd93 100644 --- a/docs/api/touch-bar.md +++ b/docs/api/touch-bar.md @@ -36,9 +36,9 @@ Below is an example of a simple slot machine touch bar game with a button and some labels. ```javascript -const {app, BrowserWindow, TouchBar} = require('electron') +const { app, BrowserWindow, TouchBar } = require('electron') -const {TouchBarLabel, TouchBarButton, TouchBarSpacer} = TouchBar +const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar let spinning = false @@ -114,13 +114,13 @@ const finishSpin = () => { const touchBar = new TouchBar([ spin, - new TouchBarSpacer({size: 'large'}), + new TouchBarSpacer({ size: 'large' }), reel1, - new TouchBarSpacer({size: 'small'}), + new TouchBarSpacer({ size: 'small' }), reel2, - new TouchBarSpacer({size: 'small'}), + new TouchBarSpacer({ size: 'small' }), reel3, - new TouchBarSpacer({size: 'large'}), + new TouchBarSpacer({ size: 'large' }), result ]) diff --git a/docs/api/tray.md b/docs/api/tray.md index 552511e3b3d..b9671676ae2 100644 --- a/docs/api/tray.md +++ b/docs/api/tray.md @@ -7,16 +7,16 @@ Process: [Main](../glossary.md#main-process) `Tray` is an [EventEmitter][event-emitter]. ```javascript -const {app, Menu, Tray} = require('electron') +const { app, Menu, Tray } = require('electron') let tray = null app.on('ready', () => { tray = new Tray('/path/to/my/icon') const contextMenu = Menu.buildFromTemplate([ - {label: 'Item1', type: 'radio'}, - {label: 'Item2', type: 'radio'}, - {label: 'Item3', type: 'radio', checked: true}, - {label: 'Item4', type: 'radio'} + { label: 'Item1', type: 'radio' }, + { label: 'Item2', type: 'radio' }, + { label: 'Item3', type: 'radio', checked: true }, + { label: 'Item4', type: 'radio' } ]) tray.setToolTip('This is my application.') tray.setContextMenu(contextMenu) @@ -35,14 +35,14 @@ __Platform limitations:__ you have to call `setContextMenu` again. For example: ```javascript -const {app, Menu, Tray} = require('electron') +const { app, Menu, Tray } = require('electron') let appIcon = null app.on('ready', () => { appIcon = new Tray('/path/to/my/icon') const contextMenu = Menu.buildFromTemplate([ - {label: 'Item1', type: 'radio'}, - {label: 'Item2', type: 'radio'} + { label: 'Item1', type: 'radio' }, + { label: 'Item2', type: 'radio' } ]) // Make a change to the context menu @@ -225,9 +225,9 @@ by toggling between `'never'` and `'always'` modes when the window visibility changes. ```javascript -const {BrowserWindow, Tray} = require('electron') +const { BrowserWindow, Tray } = require('electron') -const win = new BrowserWindow({width: 800, height: 600}) +const win = new BrowserWindow({ width: 800, height: 600 }) const tray = new Tray('/path/to/my/icon') tray.on('click', () => { diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index abde45cd4a7..f9bc6113177 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -11,9 +11,9 @@ the [`BrowserWindow`](browser-window.md) object. An example of accessing the `webContents` object: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let win = new BrowserWindow({width: 800, height: 1500}) +let win = new BrowserWindow({ width: 800, height: 1500 }) win.loadURL('http://github.com') let contents = win.webContents @@ -25,7 +25,7 @@ console.log(contents) These methods can be accessed from the `webContents` module: ```javascript -const {webContents} = require('electron') +const { webContents } = require('electron') console.log(webContents) ``` @@ -140,7 +140,7 @@ instance, failing to do so may result in unexpected behavior. For example: ```javascript myBrowserWindow.webContents.on('new-window', (event, url) => { event.preventDefault() - const win = new BrowserWindow({show: false}) + const win = new BrowserWindow({ show: false }) win.once('ready-to-show', () => win.show()) win.loadURL(url) event.newGuest = win @@ -240,8 +240,8 @@ Calling `event.preventDefault()` will ignore the `beforeunload` event handler and allow the page to be unloaded. ```javascript -const {BrowserWindow, dialog} = require('electron') -const win = new BrowserWindow({width: 800, height: 600}) +const { BrowserWindow, dialog } = require('electron') +const win = new BrowserWindow({ width: 800, height: 600 }) win.webContents.on('will-prevent-unload', (event) => { const choice = dialog.showMessageBox(win, { type: 'question', @@ -312,9 +312,9 @@ To only prevent the menu shortcuts, use [`setIgnoreMenuShortcuts`](#contentssetignoremenushortcutsignore-experimental): ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.webContents.on('before-input-event', (event, input) => { // For example, only enable application menu keyboard shortcuts when @@ -535,13 +535,13 @@ first available device will be selected. `callback` should be called with cancel the request. ```javascript -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win = null app.commandLine.appendSwitch('enable-experimental-web-platform-features') app.on('ready', () => { - win = new BrowserWindow({width: 800, height: 600}) + win = new BrowserWindow({ width: 800, height: 600 }) win.webContents.on('select-bluetooth-device', (event, deviceList, callback) => { event.preventDefault() let result = deviceList.find((device) => { @@ -568,9 +568,9 @@ Emitted when a new frame is generated. Only the dirty area is passed in the buffer. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') -let win = new BrowserWindow({webPreferences: {offscreen: true}}) +let win = new BrowserWindow({ webPreferences: { offscreen: true } }) win.webContents.on('paint', (event, dirty, image) => { // updateBitmap(dirty, image.getBitmap()) }) @@ -642,8 +642,8 @@ e.g. the `http://` or `file://`. If the load should bypass http cache then use the `pragma` header to achieve it. ```javascript -const {webContents} = require('electron') -const options = {extraHeaders: 'pragma: no-cache\n'} +const { webContents } = require('electron') +const options = { extraHeaders: 'pragma: no-cache\n' } webContents.loadURL('https://github.com', options) ``` @@ -685,8 +685,8 @@ Initiates a download of the resource at `url` without navigating. The Returns `String` - The URL of the current web page. ```javascript -const {BrowserWindow} = require('electron') -let win = new BrowserWindow({width: 800, height: 600}) +const { BrowserWindow } = require('electron') +let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('http://github.com') let currentURL = win.webContents.getURL() @@ -979,7 +979,7 @@ can be obtained by subscribing to [`found-in-page`](web-contents.md#event-found- Stops any `findInPage` request for the `webContents` with the provided `action`. ```javascript -const {webContents} = require('electron') +const { webContents } = require('electron') webContents.on('found-in-page', (event, result) => { if (result.finalUpdate) webContents.stopFindInPage('clearSelection') }) @@ -1037,7 +1037,7 @@ the system's default printer if `deviceName` is empty and the default settings for printing. Calling `window.print()` in web page is equivalent to calling -`webContents.print({silent: false, printBackground: false, deviceName: ''})`. +`webContents.print({ silent: false, printBackground: false, deviceName: '' })`. Use `page-break-before: always; ` CSS style to force to print to a new page. @@ -1080,10 +1080,10 @@ Use `page-break-before: always; ` CSS style to force to print to a new page. An example of `webContents.printToPDF`: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') const fs = require('fs') -let win = new BrowserWindow({width: 800, height: 600}) +let win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL('http://github.com') win.webContents.on('did-finish-load', () => { @@ -1106,7 +1106,7 @@ Adds the specified path to DevTools workspace. Must be used after DevTools creation: ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.webContents.on('devtools-opened', () => { win.webContents.addWorkSpace(__dirname) @@ -1167,7 +1167,7 @@ An example of showing devtools in a `` tag: An example of showing devtools in a `BrowserWindow`: ```js -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win = null let devtools = null @@ -1177,7 +1177,7 @@ app.once('ready', () => { devtools = new BrowserWindow() win.loadURL('https://github.com') win.webContents.setDevToolsWebContents(devtools.webContents) - win.webContents.openDevTools({mode: 'detach'}) + win.webContents.openDevTools({ mode: 'detach' }) }) ``` @@ -1236,11 +1236,11 @@ An example of sending messages from the main process to the renderer process: ```javascript // In the main process. -const {app, BrowserWindow} = require('electron') +const { app, BrowserWindow } = require('electron') let win = null app.on('ready', () => { - win = new BrowserWindow({width: 800, height: 600}) + win = new BrowserWindow({ width: 800, height: 600 }) win.loadURL(`file://${__dirname}/index.html`) win.webContents.on('did-finish-load', () => { win.webContents.send('ping', 'whoooooooh!') @@ -1270,7 +1270,7 @@ app.on('ready', () => { * `mobile` - Mobile screen type. * `screenSize` [Size](structures/size.md) - Set the emulated screen size (screenPosition == mobile). * `viewPosition` [Point](structures/point.md) - Position the view on the screen - (screenPosition == mobile) (default: `{x: 0, y: 0}`). + (screenPosition == mobile) (default: `{ x: 0, y: 0 }`). * `deviceScaleFactor` Integer - Set the device scale factor (if zero defaults to original device scale factor) (default: `0`). * `viewSize` [Size](structures/size.md) - Set the emulated view size (empty means no override) @@ -1373,7 +1373,7 @@ the cursor when dragging. Returns `Boolean` - true if the process of saving page has been initiated successfully. ```javascript -const {BrowserWindow} = require('electron') +const { BrowserWindow } = require('electron') let win = new BrowserWindow() win.loadURL('https://github.com') diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 1fcbfbd593d..995b629798b 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -11,7 +11,7 @@ be retrieved by certain properties and methods (e.g. `webFrame.firstChild`). An example of zooming current page to 200%. ```javascript -const {webFrame} = require('electron') +const { webFrame } = require('electron') webFrame.setZoomFactor(2) ``` @@ -73,7 +73,7 @@ whether the word passed is correctly spelled. An example of using [node-spellchecker][spellchecker] as provider: ```javascript -const {webFrame} = require('electron') +const { webFrame } = require('electron') webFrame.setSpellCheckProvider('en-US', true, { spellCheck (text) { return !(require('spellchecker').isMisspelled(text)) @@ -105,7 +105,7 @@ Specify an option with the value of `false` to omit it from the registration. An example of registering a privileged scheme, without bypassing Content Security Policy: ```javascript -const {webFrame} = require('electron') +const { webFrame } = require('electron') webFrame.registerURLSchemeAsPrivileged('foo', { bypassCSP: false }) ``` @@ -177,7 +177,7 @@ Returns an object describing usage information of Blink's internal memory caches. ```javascript -const {webFrame} = require('electron') +const { webFrame } = require('electron') console.log(webFrame.getResourceUsage()) ``` diff --git a/docs/api/web-request.md b/docs/api/web-request.md index 0904db05acc..413d8801331 100644 --- a/docs/api/web-request.md +++ b/docs/api/web-request.md @@ -23,7 +23,7 @@ called with a `response` object when `listener` has done its work. An example of adding `User-Agent` header for requests: ```javascript -const {session} = require('electron') +const { session } = require('electron') // Modify the user agent for all requests to the following urls. const filter = { @@ -32,7 +32,7 @@ const filter = { session.defaultSession.webRequest.onBeforeSendHeaders(filter, (details, callback) => { details.requestHeaders['User-Agent'] = 'MyAgent' - callback({cancel: false, requestHeaders: details.requestHeaders}) + callback({ cancel: false, requestHeaders: details.requestHeaders }) }) ``` diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index 883109c3e81..de3bf24e934 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -752,7 +752,7 @@ Fired when the guest page attempts to open a new browser window. The following example code opens the new url in system's default browser. ```javascript -const {shell} = require('electron') +const { shell } = require('electron') const webview = document.querySelector('webview') webview.addEventListener('new-window', (e) => { @@ -844,7 +844,7 @@ webview.send('ping') ```javascript // In guest page. -const {ipcRenderer} = require('electron') +const { ipcRenderer } = require('electron') ipcRenderer.on('ping', () => { ipcRenderer.sendToHost('pong') }) diff --git a/docs/development/upgrading-chromium.md b/docs/development/upgrading-chromium.md index 61c97bbc5c9..0f6fb66d7f6 100644 --- a/docs/development/upgrading-chromium.md +++ b/docs/development/upgrading-chromium.md @@ -144,7 +144,7 @@ codecs. ', {baseURLForDataURL: `file://${path.join(fixtures, 'api')}${path.sep}`}) + w.loadURL('data:text/html,', { baseURLForDataURL: `file://${path.join(fixtures, 'api')}${path.sep}` }) }) }) @@ -360,7 +361,7 @@ describe('BrowserWindow module', () => { }) it('emits when window is shown', (done) => { w.once('show', () => { - assert.equal(w.isVisible(), true) + assert.strictEqual(w.isVisible(), true) done() }) w.show() @@ -386,7 +387,7 @@ describe('BrowserWindow module', () => { it('emits when window is hidden', (done) => { w.show() w.once('hide', () => { - assert.equal(w.isVisible(), false) + assert.strictEqual(w.isVisible(), false) done() }) w.hide() @@ -402,9 +403,9 @@ describe('BrowserWindow module', () => { describe('BrowserWindow.focus()', () => { it('does not make the window become visible', () => { - assert.equal(w.isVisible(), false) + assert.strictEqual(w.isVisible(), false) w.focus() - assert.equal(w.isVisible(), false) + assert.strictEqual(w.isVisible(), false) }) }) @@ -419,10 +420,10 @@ describe('BrowserWindow module', () => { it('returns the opener window when dev tools window is focused', (done) => { w.show() w.webContents.once('devtools-focused', () => { - assert.deepEqual(BrowserWindow.getFocusedWindow(), w) + assert.deepStrictEqual(BrowserWindow.getFocusedWindow(), w) done() }) - w.webContents.openDevTools({mode: 'undocked'}) + w.webContents.openDevTools({ mode: 'undocked' }) }) }) @@ -474,8 +475,8 @@ describe('BrowserWindow module', () => { describe('BrowserWindow.setMinimum/MaximumSize(width, height)', () => { it('sets the maximum and minimum size of the window', () => { - assert.deepEqual(w.getMinimumSize(), [0, 0]) - assert.deepEqual(w.getMaximumSize(), [0, 0]) + assert.deepStrictEqual(w.getMinimumSize(), [0, 0]) + assert.deepStrictEqual(w.getMaximumSize(), [0, 0]) w.setMinimumSize(100, 100) assertBoundsEqual(w.getMinimumSize(), [100, 100]) @@ -505,8 +506,8 @@ describe('BrowserWindow module', () => { const pos = [10, 10] w.once('move', () => { const newPos = w.getPosition() - assert.equal(newPos[0], pos[0]) - assert.equal(newPos[1], pos[1]) + assert.strictEqual(newPos[0], pos[0]) + assert.strictEqual(newPos[1], pos[1]) done() }) w.setPosition(pos[0], pos[1]) @@ -518,8 +519,8 @@ describe('BrowserWindow module', () => { const size = [400, 400] w.setContentSize(size[0], size[1]) var after = w.getContentSize() - assert.equal(after[0], size[0]) - assert.equal(after[1], size[1]) + assert.strictEqual(after[0], size[0]) + assert.strictEqual(after[1], size[1]) }) it('works for a frameless window', () => { w.destroy() @@ -532,14 +533,14 @@ describe('BrowserWindow module', () => { const size = [400, 400] w.setContentSize(size[0], size[1]) const after = w.getContentSize() - assert.equal(after[0], size[0]) - assert.equal(after[1], size[1]) + assert.strictEqual(after[0], size[0]) + assert.strictEqual(after[1], size[1]) }) }) describe('BrowserWindow.setContentBounds(bounds)', () => { it('sets the content size and position', (done) => { - const bounds = {x: 10, y: 10, width: 250, height: 250} + const bounds = { x: 10, y: 10, width: 250, height: 250 } w.once('resize', () => { assertBoundsEqual(w.getContentBounds(), bounds) done() @@ -554,9 +555,9 @@ describe('BrowserWindow module', () => { width: 300, height: 300 }) - const bounds = {x: 10, y: 10, width: 250, height: 250} + const bounds = { x: 10, y: 10, width: 250, height: 250 } w.once('resize', () => { - assert.deepEqual(w.getContentBounds(), bounds) + assert.deepStrictEqual(w.getContentBounds(), bounds) done() }) w.setContentBounds(bounds) @@ -687,30 +688,30 @@ describe('BrowserWindow module', () => { }) it('sets the progress using "paused" mode', () => { assert.doesNotThrow(() => { - w.setProgressBar(0.5, {mode: 'paused'}) + w.setProgressBar(0.5, { mode: 'paused' }) }) }) it('sets the progress using "error" mode', () => { assert.doesNotThrow(() => { - w.setProgressBar(0.5, {mode: 'error'}) + w.setProgressBar(0.5, { mode: 'error' }) }) }) it('sets the progress using "normal" mode', () => { assert.doesNotThrow(() => { - w.setProgressBar(0.5, {mode: 'normal'}) + w.setProgressBar(0.5, { mode: 'normal' }) }) }) }) describe('BrowserWindow.setAlwaysOnTop(flag, level)', () => { it('sets the window as always on top', () => { - assert.equal(w.isAlwaysOnTop(), false) + assert.strictEqual(w.isAlwaysOnTop(), false) w.setAlwaysOnTop(true, 'screen-saver') - assert.equal(w.isAlwaysOnTop(), true) + assert.strictEqual(w.isAlwaysOnTop(), true) w.setAlwaysOnTop(false) - assert.equal(w.isAlwaysOnTop(), false) + assert.strictEqual(w.isAlwaysOnTop(), false) w.setAlwaysOnTop(true) - assert.equal(w.isAlwaysOnTop(), true) + assert.strictEqual(w.isAlwaysOnTop(), true) }) it('raises an error when relativeLevel is out of bounds', function () { if (process.platform !== 'darwin') { @@ -740,13 +741,13 @@ describe('BrowserWindow module', () => { }) it('resets the windows level on minimize', () => { - assert.equal(w.isAlwaysOnTop(), false) + assert.strictEqual(w.isAlwaysOnTop(), false) w.setAlwaysOnTop(true, 'screen-saver') - assert.equal(w.isAlwaysOnTop(), true) + assert.strictEqual(w.isAlwaysOnTop(), true) w.minimize() - assert.equal(w.isAlwaysOnTop(), false) + assert.strictEqual(w.isAlwaysOnTop(), false) w.restore() - assert.equal(w.isAlwaysOnTop(), true) + assert.strictEqual(w.isAlwaysOnTop(), true) }) }) @@ -862,10 +863,10 @@ describe('BrowserWindow module', () => { w.addTabbedWindow(tabbedWindow) }) - assert.equal(BrowserWindow.getAllWindows().length, 3) // Test window + w + tabbedWindow + assert.strictEqual(BrowserWindow.getAllWindows().length, 3) // Test window + w + tabbedWindow - closeWindow(tabbedWindow, {assertSingleWindow: false}).then(() => { - assert.equal(BrowserWindow.getAllWindows().length, 2) // Test window + w + closeWindow(tabbedWindow, { assertSingleWindow: false }).then(() => { + assert.strictEqual(BrowserWindow.getAllWindows().length, 2) // Test window + w done() }) }) @@ -927,12 +928,12 @@ describe('BrowserWindow module', () => { const iconPath = path.join(fixtures, 'assets', 'icon.ico') assert.doesNotThrow(() => { - w.setAppDetails({appId: 'my.app.id'}) - w.setAppDetails({appIconPath: iconPath, appIconIndex: 0}) - w.setAppDetails({appIconPath: iconPath}) - w.setAppDetails({relaunchCommand: 'my-app.exe arg1 arg2', relaunchDisplayName: 'My app name'}) - w.setAppDetails({relaunchCommand: 'my-app.exe arg1 arg2'}) - w.setAppDetails({relaunchDisplayName: 'My app name'}) + w.setAppDetails({ appId: 'my.app.id' }) + w.setAppDetails({ appIconPath: iconPath, appIconIndex: 0 }) + w.setAppDetails({ appIconPath: iconPath }) + w.setAppDetails({ relaunchCommand: 'my-app.exe arg1 arg2', relaunchDisplayName: 'My app name' }) + w.setAppDetails({ relaunchCommand: 'my-app.exe arg1 arg2' }) + w.setAppDetails({ relaunchDisplayName: 'My app name' }) w.setAppDetails({ appId: 'my.app.id', appIconPath: iconPath, @@ -951,7 +952,7 @@ describe('BrowserWindow module', () => { describe('BrowserWindow.fromId(id)', () => { it('returns the window with id', () => { - assert.equal(w.id, BrowserWindow.fromId(w.id).id) + assert.strictEqual(w.id, BrowserWindow.fromId(w.id).id) }) }) @@ -963,8 +964,8 @@ describe('BrowserWindow module', () => { afterEach(() => { contents.destroy() }) it('returns the window with the webContents', () => { - assert.equal(BrowserWindow.fromWebContents(w.webContents).id, w.id) - assert.equal(BrowserWindow.fromWebContents(contents), undefined) + assert.strictEqual(BrowserWindow.fromWebContents(w.webContents).id, w.id) + assert.strictEqual(BrowserWindow.fromWebContents(contents), undefined) }) }) @@ -977,9 +978,9 @@ describe('BrowserWindow module', () => { it('returns the window with the webContents', (done) => { w.webContents.once('devtools-opened', () => { - assert.equal(BrowserWindow.fromDevToolsWebContents(w.devToolsWebContents).id, w.id) - assert.equal(BrowserWindow.fromDevToolsWebContents(w.webContents), undefined) - assert.equal(BrowserWindow.fromDevToolsWebContents(contents), undefined) + assert.strictEqual(BrowserWindow.fromDevToolsWebContents(w.devToolsWebContents).id, w.id) + assert.strictEqual(BrowserWindow.fromDevToolsWebContents(w.webContents), undefined) + assert.strictEqual(BrowserWindow.fromDevToolsWebContents(contents), undefined) done() }) w.webContents.openDevTools() @@ -1008,12 +1009,12 @@ describe('BrowserWindow module', () => { }) it('returns the window with the browserView', () => { - assert.equal(BrowserWindow.fromBrowserView(bv).id, w.id) + assert.strictEqual(BrowserWindow.fromBrowserView(bv).id, w.id) }) it('returns undefined if not attached', () => { w.setBrowserView(null) - assert.equal(BrowserWindow.fromBrowserView(bv), undefined) + assert.strictEqual(BrowserWindow.fromBrowserView(bv), null) }) }) @@ -1026,16 +1027,16 @@ describe('BrowserWindow module', () => { height: 400, opacity: 0.5 }) - assert.equal(w.getOpacity(), 0.5) + assert.strictEqual(w.getOpacity(), 0.5) }) it('allows setting the opacity', () => { assert.doesNotThrow(() => { w.setOpacity(0.0) - assert.equal(w.getOpacity(), 0.0) + assert.strictEqual(w.getOpacity(), 0.0) w.setOpacity(0.5) - assert.equal(w.getOpacity(), 0.5) + assert.strictEqual(w.getOpacity(), 0.5) w.setOpacity(1.0) - assert.equal(w.getOpacity(), 1.0) + assert.strictEqual(w.getOpacity(), 1.0) }) }) }) @@ -1044,8 +1045,8 @@ describe('BrowserWindow module', () => { it('allows setting shape', () => { assert.doesNotThrow(() => { w.setShape([]) - w.setShape([{x: 0, y: 0, width: 100, height: 100}]) - w.setShape([{x: 0, y: 0, width: 100, height: 100}, {x: 0, y: 200, width: 1000, height: 100}]) + w.setShape([{ x: 0, y: 0, width: 100, height: 100 }]) + w.setShape([{ x: 0, y: 0, width: 100, height: 100 }, { x: 0, y: 200, width: 1000, height: 100 }]) w.setShape([]) }) }) @@ -1061,13 +1062,13 @@ describe('BrowserWindow module', () => { useContentSize: true }) const contentSize = w.getContentSize() - assert.equal(contentSize[0], 400) - assert.equal(contentSize[1], 400) + assert.strictEqual(contentSize[0], 400) + assert.strictEqual(contentSize[1], 400) }) it('make window created with window size when not used', () => { const size = w.getSize() - assert.equal(size[0], 400) - assert.equal(size[1], 400) + assert.strictEqual(size[0], 400) + assert.strictEqual(size[1], 400) }) it('works for a frameless window', () => { w.destroy() @@ -1079,11 +1080,11 @@ describe('BrowserWindow module', () => { useContentSize: true }) const contentSize = w.getContentSize() - assert.equal(contentSize[0], 400) - assert.equal(contentSize[1], 400) + assert.strictEqual(contentSize[0], 400) + assert.strictEqual(contentSize[1], 400) const size = w.getSize() - assert.equal(size[0], 400) - assert.equal(size[1], 400) + assert.strictEqual(size[0], 400) + assert.strictEqual(size[1], 400) }) }) @@ -1107,7 +1108,7 @@ describe('BrowserWindow module', () => { titleBarStyle: 'hidden' }) const contentSize = w.getContentSize() - assert.equal(contentSize[1], 400) + assert.strictEqual(contentSize[1], 400) }) it('creates browser window with hidden inset title bar', () => { w.destroy() @@ -1118,7 +1119,7 @@ describe('BrowserWindow module', () => { titleBarStyle: 'hiddenInset' }) const contentSize = w.getContentSize() - assert.equal(contentSize[1], 400) + assert.strictEqual(contentSize[1], 400) }) }) @@ -1142,8 +1143,8 @@ describe('BrowserWindow module', () => { it('can move the window out of screen', () => { w.setPosition(-10, -10) const after = w.getPosition() - assert.equal(after[0], -10) - assert.equal(after[1], -10) + assert.strictEqual(after[0], -10) + assert.strictEqual(after[1], -10) }) it('can set the window larger than screen', () => { const size = screen.getPrimaryDisplay().size @@ -1170,7 +1171,7 @@ describe('BrowserWindow module', () => { zoomToPageWidth: true }) w.maximize() - assert.equal(w.getSize()[0], 500) + assert.strictEqual(w.getSize()[0], 500) }) }) @@ -1195,7 +1196,7 @@ describe('BrowserWindow module', () => { it('loads the script before other scripts in window', (done) => { const preload = path.join(fixtures, 'module', 'set-global.js') ipcMain.once('answer', (event, test) => { - assert.equal(test, 'preload') + assert.strictEqual(test, 'preload') done() }) w.destroy() @@ -1210,7 +1211,7 @@ describe('BrowserWindow module', () => { it('can successfully delete the Buffer global', (done) => { const preload = path.join(fixtures, 'module', 'delete-buffer.js') ipcMain.once('answer', (event, test) => { - assert.equal(test.toString(), 'buffer') + assert.strictEqual(test.toString(), 'buffer') done() }) w.destroy() @@ -1232,7 +1233,7 @@ describe('BrowserWindow module', () => { const defaultSession = session.defaultSession beforeEach(() => { - assert.deepEqual(defaultSession.getPreloads(), []) + assert.deepStrictEqual(defaultSession.getPreloads(), []) defaultSession.setPreloads(preloads) }) afterEach(() => { @@ -1240,14 +1241,14 @@ describe('BrowserWindow module', () => { }) it('can set multiple session preload script', function () { - assert.deepEqual(defaultSession.getPreloads(), preloads) + assert.deepStrictEqual(defaultSession.getPreloads(), preloads) }) it('loads the script before other scripts in window including normal preloads', function (done) { ipcMain.once('vars', function (event, preload1, preload2, preload3) { - assert.equal(preload1, 'preload-1') - assert.equal(preload2, 'preload-1-2') - assert.equal(preload3, 'preload-1-2-3') + assert.strictEqual(preload1, 'preload-1') + assert.strictEqual(preload2, 'preload-1-2') + assert.strictEqual(preload3, 'preload-1-2-3') done() }) w.destroy() @@ -1301,8 +1302,8 @@ describe('BrowserWindow module', () => { it('disables node integration when specified to false', (done) => { const preload = path.join(fixtures, 'module', 'send-later.js') ipcMain.once('answer', (event, typeofProcess, typeofBuffer) => { - assert.equal(typeofProcess, 'undefined') - assert.equal(typeofBuffer, 'undefined') + assert.strictEqual(typeofProcess, 'undefined') + assert.strictEqual(typeofBuffer, 'undefined') done() }) w.destroy() @@ -1354,7 +1355,7 @@ describe('BrowserWindow module', () => { it('exposes ipcRenderer to preload script', (done) => { ipcMain.once('answer', function (event, test) { - assert.equal(test, 'preload') + assert.strictEqual(test, 'preload') done() }) w.destroy() @@ -1371,7 +1372,7 @@ describe('BrowserWindow module', () => { it('exposes ipcRenderer to preload script (path has special chars)', function (done) { const preloadSpecialChars = path.join(fixtures, 'module', 'preload-sandboxæø åü.js') ipcMain.once('answer', function (event, test) { - assert.equal(test, 'preload') + assert.strictEqual(test, 'preload') done() }) w.destroy() @@ -1402,7 +1403,7 @@ describe('BrowserWindow module', () => { if (process.platform === 'win32') { expectedUrl = 'file:///' + htmlPath.replace(/\\/g, '/') } - assert.equal(url, expectedUrl) + assert.strictEqual(url, expectedUrl) done() }) }) @@ -1425,12 +1426,12 @@ describe('BrowserWindow module', () => { if (process.platform === 'win32') { expectedUrl = 'file:///' + htmlPath.replace(/\\/g, '/') } - assert.equal(url, expectedUrl) - assert.equal(frameName, 'popup!') - assert.equal(options.width, 500) - assert.equal(options.height, 600) + assert.strictEqual(url, expectedUrl) + assert.strictEqual(frameName, 'popup!') + assert.strictEqual(options.width, 500) + assert.strictEqual(options.height, 600) ipcMain.once('answer', function (event, html) { - assert.equal(html, '

scripting from opener

') + assert.strictEqual(html, '

scripting from opener

') done() }) }) @@ -1447,19 +1448,19 @@ describe('BrowserWindow module', () => { }) ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preload) let popupWindow - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'window-open-external'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'window-open-external' }) w.webContents.once('new-window', (e, url, frameName, disposition, options) => { - assert.equal(url, 'http://www.google.com/#q=electron') - assert.equal(options.width, 505) - assert.equal(options.height, 605) + assert.strictEqual(url, 'http://www.google.com/#q=electron') + assert.strictEqual(options.width, 505) + assert.strictEqual(options.height, 605) ipcMain.once('child-loaded', function (event, openerIsNull, html) { assert(openerIsNull) - assert.equal(html, '

http://www.google.com/#q=electron

') + assert.strictEqual(html, '

http://www.google.com/#q=electron

') ipcMain.once('answer', function (event, exceptionMessage) { assert(/Blocked a frame with origin/.test(exceptionMessage)) // FIXME this popup window should be closed in sandbox.html - closeWindow(popupWindow, {assertSingleWindow: false}).then(() => { + closeWindow(popupWindow, { assertSingleWindow: false }).then(() => { popupWindow = null done() }) @@ -1485,7 +1486,7 @@ describe('BrowserWindow module', () => { const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js') ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath) ipcMain.once('answer', (event, args) => { - assert.equal(args.includes('--enable-sandbox'), true) + assert.strictEqual(args.includes('--enable-sandbox'), true) done() }) w.loadFile(path.join(fixtures, 'api', 'new-window.html')) @@ -1504,7 +1505,7 @@ describe('BrowserWindow module', () => { ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath) ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'foo', 'bar') ipcMain.once('answer', (event, args, webPreferences) => { - assert.equal(webPreferences.foo, 'bar') + assert.strictEqual(webPreferences.foo, 'bar') done() }) w.loadFile(path.join(fixtures, 'api', 'new-window.html')) @@ -1524,22 +1525,22 @@ describe('BrowserWindow module', () => { let childWc w.webContents.once('new-window', (e, url, frameName, disposition, options) => { childWc = options.webContents - assert.notEqual(w.webContents, childWc) + assert.notStrictEqual(w.webContents, childWc) }) ipcMain.once('parent-ready', function (event) { - assert.equal(w.webContents, event.sender) + assert.strictEqual(w.webContents, event.sender) event.sender.send('verified') }) ipcMain.once('child-ready', function (event) { assert(childWc) - assert.equal(childWc, event.sender) + assert.strictEqual(childWc, event.sender) event.sender.send('verified') }) waitForEvents(ipcMain, [ 'parent-answer', 'child-answer' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'verify-ipc-sender'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'verify-ipc-sender' }) }) describe('event handling', () => { @@ -1547,7 +1548,7 @@ describe('BrowserWindow module', () => { waitForEvents(w, [ 'page-title-updated' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'window-events'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'window-events' }) }) it('works for stop events', (done) => { @@ -1556,7 +1557,7 @@ describe('BrowserWindow module', () => { 'did-fail-load', 'did-stop-loading' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'webcontents-stop'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'webcontents-stop' }) }) it('works for web contents events', (done) => { @@ -1570,7 +1571,7 @@ describe('BrowserWindow module', () => { 'did-frame-finish-load', 'dom-ready' ], done) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'webcontents-events'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'webcontents-events' }) }) }) @@ -1586,7 +1587,7 @@ describe('BrowserWindow module', () => { w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E') w.webContents.once('did-finish-load', () => { const printers = w.webContents.getPrinters() - assert.equal(Array.isArray(printers), true) + assert.strictEqual(Array.isArray(printers), true) done() }) }) @@ -1603,9 +1604,9 @@ describe('BrowserWindow module', () => { w.loadURL('data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E') w.webContents.once('did-finish-load', () => { w.webContents.printToPDF({}, function (error, data) { - assert.equal(error, null) - assert.equal(data instanceof Buffer, true) - assert.notEqual(data.length, 0) + assert.strictEqual(error, null) + assert.strictEqual(data instanceof Buffer, true) + assert.notStrictEqual(data.length, 0) done() }) }) @@ -1625,7 +1626,7 @@ describe('BrowserWindow module', () => { // We need to give it some time so the windows get properly disposed (at least on OSX). setTimeout(() => { const currentWebContents = webContents.getAllWebContents().map((i) => i.id) - assert.deepEqual(currentWebContents, initialWebContents) + assert.deepStrictEqual(currentWebContents, initialWebContents) done() }, 100) }) @@ -1642,8 +1643,8 @@ describe('BrowserWindow module', () => { sandbox: true } }) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'allocate-memory'}) - ipcMain.once('answer', function (event, {bytesBeforeOpen, bytesAfterOpen, bytesAfterClose}) { + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'allocate-memory' }) + ipcMain.once('answer', function (event, { bytesBeforeOpen, bytesAfterOpen, bytesAfterClose }) { const memoryIncreaseByOpen = bytesAfterOpen - bytesBeforeOpen const memoryDecreaseByClose = bytesAfterOpen - bytesAfterClose // decreased memory should be less than increased due to factors we @@ -1665,7 +1666,7 @@ describe('BrowserWindow module', () => { sandbox: true } }) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'reload-remote'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'reload-remote' }) ipcMain.on('get-remote-module-path', (event) => { event.returnValue = path.join(fixtures, 'module', 'hello.js') @@ -1684,7 +1685,7 @@ describe('BrowserWindow module', () => { ipcMain.once('answer', (event, arg) => { ipcMain.removeAllListeners('reloaded') ipcMain.removeAllListeners('get-remote-module-path') - assert.equal(arg, 'hi') + assert.strictEqual(arg, 'hi') done() }) }) @@ -1700,7 +1701,7 @@ describe('BrowserWindow module', () => { }) ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preload) - w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), {search: 'reload-remote-child'}) + w.loadFile(path.join(fixtures, 'api', 'sandbox.html'), { search: 'reload-remote-child' }) ipcMain.on('get-remote-module-path', (event) => { event.returnValue = path.join(fixtures, 'module', 'hello-child.js') @@ -1719,23 +1720,23 @@ describe('BrowserWindow module', () => { ipcMain.once('answer', (event, arg) => { ipcMain.removeAllListeners('reloaded') ipcMain.removeAllListeners('get-remote-module-path') - assert.equal(arg, 'hi child window') + assert.strictEqual(arg, 'hi child window') done() }) }) it('validates process APIs access in sandboxed renderer', (done) => { ipcMain.once('answer', function (event, test) { - assert.equal(test.pid, w.webContents.getOSProcessId()) - assert.equal(test.arch, remote.process.arch) - assert.equal(test.platform, remote.process.platform) - assert.deepEqual(test.env, remote.process.env) - assert.equal(test.execPath, remote.process.helperExecPath) - assert.equal(test.resourcesPath, remote.process.resourcesPath) - assert.equal(test.sandboxed, true) - assert.equal(test.type, 'renderer') - assert.equal(test.version, remote.process.version) - assert.deepEqual(test.versions, remote.process.versions) + assert.strictEqual(test.pid, w.webContents.getOSProcessId()) + assert.strictEqual(test.arch, remote.process.arch) + assert.strictEqual(test.platform, remote.process.platform) + assert.deepStrictEqual(...resolveGetters(test.env, remote.process.env)) + assert.strictEqual(test.execPath, remote.process.helperExecPath) + assert.strictEqual(test.resourcesPath, remote.process.resourcesPath) + assert.strictEqual(test.sandboxed, true) + assert.strictEqual(test.type, 'renderer') + assert.strictEqual(test.version, remote.process.version) + assert.deepStrictEqual(test.versions, remote.process.versions) done() }) remote.process.env.sandboxmain = 'foo' @@ -1781,37 +1782,37 @@ describe('BrowserWindow module', () => { it('opens window of about:blank with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { - assert.equal(content, 'Hello') + assert.strictEqual(content, 'Hello') done() }) w.loadFile(path.join(fixtures, 'api', 'native-window-open-blank.html')) }) it('opens window of same domain with cross-scripting enabled', (done) => { ipcMain.once('answer', (event, content) => { - assert.equal(content, 'Hello') + assert.strictEqual(content, 'Hello') done() }) w.loadFile(path.join(fixtures, 'api', 'native-window-open-file.html')) }) it('blocks accessing cross-origin frames', (done) => { ipcMain.once('answer', (event, content) => { - assert.equal(content, 'Blocked a frame with origin "file://" from accessing a cross-origin frame.') + assert.strictEqual(content, 'Blocked a frame with origin "file://" from accessing a cross-origin frame.') done() }) w.loadFile(path.join(fixtures, 'api', 'native-window-open-cross-origin.html')) }) it('opens window from