diff --git a/docs/api/app.md b/docs/api/app.md index fd0823c27f24..35b6da350e91 100755 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -971,7 +971,7 @@ app.setJumpList([ title: 'Tool A', program: process.execPath, args: '--run-tool-a', - icon: process.execPath, + iconPath: process.execPath, iconIndex: 0, description: 'Runs Tool A' }, @@ -980,7 +980,7 @@ app.setJumpList([ title: 'Tool B', program: process.execPath, args: '--run-tool-b', - icon: process.execPath, + iconPath: process.execPath, iconIndex: 0, description: 'Runs Tool B' } @@ -1418,8 +1418,8 @@ const fs = require('fs') let filepath let bookmark -dialog.showOpenDialog(null, { securityScopedBookmarks: true }, (filepaths, bookmarks) => { - filepath = filepaths[0] +dialog.showOpenDialog(null, { securityScopedBookmarks: true }).then(({ filePaths, bookmarks }) => { + filepath = filePaths[0] bookmark = bookmarks[0] fs.readFileSync(filepath) }) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 0816cd101896..d1a36589ae22 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -104,6 +104,7 @@ window, you have to set both `parent` and `modal` options: ```javascript const { BrowserWindow } = require('electron') +const top = new BrowserWindow() const child = new BrowserWindow({ parent: top, modal: true, show: false }) child.loadURL('https://github.com') child.once('ready-to-show', () => { @@ -597,7 +598,7 @@ On Linux the setter is a no-op, although the getter returns `true`. A `boolean` property that determines whether the window is excluded from the application’s Windows menu. `false` by default. -```js +```js @ts-expect-error=[11] const win = new BrowserWindow({ height: 600, width: 600 }) const template = [ @@ -1200,6 +1201,9 @@ Node's [`url.format`](https://nodejs.org/api/url.html#url_url_format_urlobject) method: ```javascript +const { BrowserWindow } = require('electron') +const win = new BrowserWindow() + const url = require('url').format({ protocol: 'file', slashes: true, @@ -1213,6 +1217,9 @@ You can load a URL using a `POST` request with URL-encoded data by doing the following: ```javascript +const { BrowserWindow } = require('electron') +const win = new BrowserWindow() + win.loadURL('http://localhost:8000/post', { postData: [{ type: 'rawData', diff --git a/docs/api/client-request.md b/docs/api/client-request.md index 1ba3ec89321b..3bbbe6ced404 100644 --- a/docs/api/client-request.md +++ b/docs/api/client-request.md @@ -104,7 +104,7 @@ The `callback` function is expected to be called back with user credentials: * `username` string * `password` string -```javascript +```javascript @ts-type={request:Electron.ClientRequest} request.on('login', (authInfo, callback) => { callback('username', 'password') }) @@ -113,7 +113,7 @@ request.on('login', (authInfo, callback) => { Providing empty credentials will cancel the request and report an authentication error on the response object: -```javascript +```javascript @ts-type={request:Electron.ClientRequest} request.on('response', (response) => { console.log(`STATUS: ${response.statusCode}`) response.on('error', (error) => { diff --git a/docs/api/clipboard.md b/docs/api/clipboard.md index b0602c40d31d..ea5345f0719f 100644 --- a/docs/api/clipboard.md +++ b/docs/api/clipboard.md @@ -148,10 +148,7 @@ clipboard. ```js const { clipboard } = require('electron') -clipboard.writeBookmark({ - text: 'https://electronjs.org', - bookmark: 'Electron Homepage' -}) +clipboard.writeBookmark('Electron Homepage', 'https://electronjs.org') ``` ### `clipboard.readFindText()` _macOS_ diff --git a/docs/api/context-bridge.md b/docs/api/context-bridge.md index 738de98bb6a1..b2921aff723d 100644 --- a/docs/api/context-bridge.md +++ b/docs/api/context-bridge.md @@ -18,7 +18,7 @@ contextBridge.exposeInMainWorld( ) ``` -```javascript +```javascript @ts-nocheck // Renderer (Main World) window.electron.doThing() @@ -104,7 +104,7 @@ contextBridge.exposeInIsolatedWorld( ) ``` -```javascript +```javascript @ts-nocheck // Renderer (In isolated world id1004) window.electron.doThing() diff --git a/docs/api/desktop-capturer.md b/docs/api/desktop-capturer.md index 96c1b6cd0fa1..32b881516ae5 100644 --- a/docs/api/desktop-capturer.md +++ b/docs/api/desktop-capturer.md @@ -10,7 +10,9 @@ title is `Electron`: ```javascript // In the main process. -const { desktopCapturer } = require('electron') +const { BrowserWindow, desktopCapturer } = require('electron') + +const mainWindow = new BrowserWindow() desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources => { for (const source of sources) { @@ -22,7 +24,7 @@ desktopCapturer.getSources({ types: ['window', 'screen'] }).then(async sources = }) ``` -```javascript +```javascript @ts-nocheck // In the preload script. const { ipcRenderer } = require('electron') diff --git a/docs/api/dialog.md b/docs/api/dialog.md index 04960ed2dcf8..7d1879c340db 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -72,7 +72,7 @@ and a directory selector, so if you set `properties` to `['openFile', 'openDirectory']` on these platforms, a directory selector will be shown. -```js +```js @ts-type={mainWindow:Electron.BrowserWindow} dialog.showOpenDialogSync(mainWindow, { properties: ['openFile', 'openDirectory'] }) @@ -139,7 +139,7 @@ and a directory selector, so if you set `properties` to `['openFile', 'openDirectory']` on these platforms, a directory selector will be shown. -```js +```js @ts-type={mainWindow:Electron.BrowserWindow} dialog.showOpenDialog(mainWindow, { properties: ['openFile', 'openDirectory'] }).then(result => { diff --git a/docs/api/incoming-message.md b/docs/api/incoming-message.md index 92b9dec58f16..904b4bfe123b 100644 --- a/docs/api/incoming-message.md +++ b/docs/api/incoming-message.md @@ -89,7 +89,7 @@ tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. Header names are not lowercased, and duplicates are not merged. -```javascript +```javascript @ts-type={response:Electron.IncomingMessage} // Prints something like: // // [ 'user-agent', @@ -100,5 +100,5 @@ duplicates are not merged. // '127.0.0.1:8000', // 'ACCEPT', // '*/*' ] -console.log(request.rawHeaders) +console.log(response.rawHeaders) ``` diff --git a/docs/api/ipc-main.md b/docs/api/ipc-main.md index 2b42afe2834c..3b3e14e7cdd6 100644 --- a/docs/api/ipc-main.md +++ b/docs/api/ipc-main.md @@ -83,14 +83,14 @@ If `listener` returns a Promise, the eventual result of the promise will be returned as a reply to the remote caller. Otherwise, the return value of the listener will be used as the value of the reply. -```js title='Main Process' +```js title='Main Process' @ts-type={somePromise:(...args:unknown[])=>Promise} ipcMain.handle('my-invokable-ipc', async (event, ...args) => { const result = await somePromise(...args) return result }) ``` -```js title='Renderer Process' +```js title='Renderer Process' @ts-type={arg1:unknown} @ts-type={arg2:unknown} async () => { const result = await ipcRenderer.invoke('my-invokable-ipc', arg1, arg2) // ... diff --git a/docs/api/ipc-renderer.md b/docs/api/ipc-renderer.md index 3045eba6396f..29dd5ff79cae 100644 --- a/docs/api/ipc-renderer.md +++ b/docs/api/ipc-renderer.md @@ -101,7 +101,7 @@ The main process should listen for `channel` with For example: -```javascript +```javascript @ts-type={someArgument:unknown} @ts-type={doSomeWork:(arg:unknown)=>Promise} // Renderer process ipcRenderer.invoke('some-name', someArgument).then((result) => { // ... diff --git a/docs/api/menu.md b/docs/api/menu.md index 735fefce7e93..93c794ec9493 100644 --- a/docs/api/menu.md +++ b/docs/api/menu.md @@ -147,7 +147,7 @@ can have a submenu. An example of creating the application menu with the simple template API: -```javascript +```javascript @ts-expect-error=[107] const { app, Menu } = require('electron') const isMac = process.platform === 'darwin' @@ -267,7 +267,7 @@ menu on behalf of the renderer. Below is an example of showing a menu when the user right clicks the page: -```js +```js @ts-expect-error=[21] // renderer window.addEventListener('contextmenu', (e) => { e.preventDefault() @@ -289,7 +289,7 @@ ipcMain.on('show-context-menu', (event) => { { label: 'Menu Item 2', type: 'checkbox', checked: true } ] const menu = Menu.buildFromTemplate(template) - menu.popup(BrowserWindow.fromWebContents(event.sender)) + menu.popup({ window: BrowserWindow.fromWebContents(event.sender) }) }) ``` diff --git a/docs/api/message-channel-main.md b/docs/api/message-channel-main.md index 670cda868f59..18339848db6a 100644 --- a/docs/api/message-channel-main.md +++ b/docs/api/message-channel-main.md @@ -17,7 +17,8 @@ Example: ```js // Main process -const { MessageChannelMain } = require('electron') +const { BrowserWindow, MessageChannelMain } = require('electron') +const w = new BrowserWindow() const { port1, port2 } = new MessageChannelMain() w.webContents.postMessage('port', null, [port2]) port1.postMessage({ some: 'message' }) @@ -26,9 +27,9 @@ port1.postMessage({ some: 'message' }) const { ipcRenderer } = require('electron') ipcRenderer.on('port', (e) => { // e.ports is a list of ports sent along with this message - e.ports[0].on('message', (messageEvent) => { + e.ports[0].onmessage = (messageEvent) => { console.log(messageEvent.data) - }) + } }) ``` diff --git a/docs/api/net-log.md b/docs/api/net-log.md index fec5f3d14432..db16c11193f8 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 { app, netLog } = require('electron') app.whenReady().then(async () => { await netLog.startLogging('/path/to/net-log') diff --git a/docs/api/protocol.md b/docs/api/protocol.md index 4ca6b5ebb063..e5d726f79c21 100644 --- a/docs/api/protocol.md +++ b/docs/api/protocol.md @@ -32,7 +32,7 @@ To have your custom protocol work in combination with a custom session, you need to register it to that session explicitly. ```javascript -const { session, app, protocol } = require('electron') +const { app, BrowserWindow, net, protocol, session } = require('electron') const path = require('path') const url = require('url') @@ -41,11 +41,11 @@ app.whenReady().then(() => { const ses = session.fromPartition(partition) ses.protocol.handle('atom', (request) => { - const path = request.url.slice('atom://'.length) - return net.fetch(url.pathToFileURL(path.join(__dirname, path))) + const filePath = request.url.slice('atom://'.length) + return net.fetch(url.pathToFileURL(path.join(__dirname, filePath)).toString()) }) - mainWindow = new BrowserWindow({ webPreferences: { partition } }) + const mainWindow = new BrowserWindow({ webPreferences: { partition } }) }) ``` @@ -121,9 +121,9 @@ Either a `Response` or a `Promise` can be returned. Example: ```js -import { app, protocol } from 'electron' -import { join } from 'path' -import { pathToFileURL } from 'url' +const { app, net, protocol } = require('electron') +const { join } = require('path') +const { pathToFileURL } = require('url') protocol.registerSchemesAsPrivileged([ { @@ -131,7 +131,7 @@ protocol.registerSchemesAsPrivileged([ privileges: { standard: true, secure: true, - supportsFetchAPI: true + supportFetchAPI: true } } ]) @@ -147,7 +147,7 @@ app.whenReady().then(() => { } // NB, this does not check for paths that escape the bundle, e.g. // app://bundle/../../secret_file.txt - return net.fetch(pathToFileURL(join(__dirname, pathname))) + return net.fetch(pathToFileURL(join(__dirname, pathname)).toString()) } else if (host === 'api') { return net.fetch('https://api.my-server.com/' + pathname, { method: req.method, diff --git a/docs/api/session.md b/docs/api/session.md index 334a2a4e4d2b..e999a5207b91 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -98,7 +98,7 @@ Emitted when Electron is about to download `item` in `webContents`. Calling `event.preventDefault()` will cancel the download and `item` will not be available from next tick of the process. -```javascript +```javascript @ts-expect-error=[4] const { session } = require('electron') session.defaultSession.on('will-download', (event, item, webContents) => { event.preventDefault() @@ -214,7 +214,7 @@ cancel the request. Additionally, permissioning on `navigator.hid` can be further managed by using [`ses.setPermissionCheckHandler(handler)`](#sessetpermissioncheckhandlerhandler) and [`ses.setDevicePermissionHandler(handler)`](#sessetdevicepermissionhandlerhandler). -```javascript +```javascript @ts-type={fetchGrantedDevices:()=>(Array)} const { app, BrowserWindow } = require('electron') let win = null @@ -253,7 +253,7 @@ app.whenReady().then(() => { win.webContents.session.on('select-hid-device', (event, details, callback) => { event.preventDefault() const selectedDevice = details.deviceList.find((device) => { - return device.vendorId === '9025' && device.productId === '67' + return device.vendorId === 9025 && device.productId === 67 }) callback(selectedDevice?.deviceId) }) @@ -320,7 +320,7 @@ cancel the request. Additionally, permissioning on `navigator.serial` can be managed by using [ses.setPermissionCheckHandler(handler)](#sessetpermissioncheckhandlerhandler) with the `serial` permission. -```javascript +```javascript @ts-type={fetchGrantedDevices:()=>(Array)} const { app, BrowserWindow } = require('electron') let win = null @@ -463,7 +463,7 @@ cancel the request. Additionally, permissioning on `navigator.usb` can be further managed by using [`ses.setPermissionCheckHandler(handler)`](#sessetpermissioncheckhandlerhandler) and [`ses.setDevicePermissionHandler(handler)`](#sessetdevicepermissionhandlerhandler). -```javascript +```javascript @ts-type={fetchGrantedDevices:()=>(Array)} @ts-type={updateGrantedDevices:(devices:Array)=>void} const { app, BrowserWindow } = require('electron') let win = null @@ -502,7 +502,7 @@ app.whenReady().then(() => { win.webContents.session.on('select-usb-device', (event, details, callback) => { event.preventDefault() const selectedDevice = details.deviceList.find((device) => { - return device.vendorId === '9025' && device.productId === '67' + return device.vendorId === 9025 && device.productId === 67 }) if (selectedDevice) { // Optionally, add this to the persisted devices (updateGrantedDevices needs to be implemented by developer to persist permissions) @@ -755,15 +755,17 @@ Sets download saving directory. By default, the download directory will be the Emulates network with the given configuration for the `session`. ```javascript +const win = new BrowserWindow() + // To emulate a GPRS connection with 50kbps throughput and 500 ms latency. -window.webContents.session.enableNetworkEmulation({ +win.webContents.session.enableNetworkEmulation({ latency: 500, downloadThroughput: 6400, uploadThroughput: 6400 }) // To emulate a network outage. -window.webContents.session.enableNetworkEmulation({ offline: true }) +win.webContents.session.enableNetworkEmulation({ offline: true }) ``` #### `ses.preconnect(options)` @@ -1036,7 +1038,7 @@ Additionally, the default behavior of Electron is to store granted device permis If longer term storage is needed, a developer can store granted device permissions (eg when handling the `select-hid-device` event) and then read from that storage with `setDevicePermissionHandler`. -```javascript +```javascript @ts-type={fetchGrantedDevices:()=>(Array)} const { app, BrowserWindow } = require('electron') let win = null @@ -1084,9 +1086,9 @@ app.whenReady().then(() => { win.webContents.session.on('select-hid-device', (event, details, callback) => { event.preventDefault() const selectedDevice = details.deviceList.find((device) => { - return device.vendorId === '9025' && device.productId === '67' + return device.vendorId === 9025 && device.productId === 67 }) - callback(selectedPort?.deviceId) + callback(selectedDevice?.deviceId) }) }) ``` @@ -1174,32 +1176,32 @@ macOS does not require a handler because macOS handles the pairing automatically. To clear the handler, call `setBluetoothPairingHandler(null)`. ```javascript - -const { app, BrowserWindow, ipcMain, session } = require('electron') - -let bluetoothPinCallback = null +const { app, BrowserWindow, session } = require('electron') +const path = require('path') function createWindow () { + let bluetoothPinCallback = null + const mainWindow = new BrowserWindow({ webPreferences: { preload: path.join(__dirname, 'preload.js') } }) + + mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => { + bluetoothPinCallback = callback + // Send a IPC message to the renderer to prompt the user to confirm the pairing. + // Note that this will require logic in the renderer to handle this message and + // display a prompt to the user. + mainWindow.webContents.send('bluetooth-pairing-request', details) + }) + + // Listen for an IPC message from the renderer to get the response for the Bluetooth pairing. + mainWindow.webContents.ipc.on('bluetooth-pairing-response', (event, response) => { + bluetoothPinCallback(response) + }) } -// Listen for an IPC message from the renderer to get the response for the Bluetooth pairing. -ipcMain.on('bluetooth-pairing-response', (event, response) => { - bluetoothPinCallback(response) -}) - -mainWindow.webContents.session.setBluetoothPairingHandler((details, callback) => { - bluetoothPinCallback = callback - // Send a IPC message to the renderer to prompt the user to confirm the pairing. - // Note that this will require logic in the renderer to handle this message and - // display a prompt to the user. - mainWindow.webContents.send('bluetooth-pairing-request', details) -}) - app.whenReady().then(() => { createWindow() }) diff --git a/docs/api/touch-bar.md b/docs/api/touch-bar.md index 10bf400ab47b..7cbcc83ddd23 100644 --- a/docs/api/touch-bar.md +++ b/docs/api/touch-bar.md @@ -87,12 +87,12 @@ const { TouchBarLabel, TouchBarButton, TouchBarSpacer } = TouchBar let spinning = false // Reel labels -const reel1 = new TouchBarLabel() -const reel2 = new TouchBarLabel() -const reel3 = new TouchBarLabel() +const reel1 = new TouchBarLabel({ label: '' }) +const reel2 = new TouchBarLabel({ label: '' }) +const reel3 = new TouchBarLabel({ label: '' }) // Spin result label -const result = new TouchBarLabel() +const result = new TouchBarLabel({ label: '' }) // Spin button const spin = new TouchBarButton({ diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 43e1a522c69f..abcbac0ef112 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -98,7 +98,7 @@ async function lookupTargetId (browserWindow) { await wc.debugger.attach('1.3') const { targetInfo } = await wc.debugger.sendCommand('Target.getTargetInfo') const { targetId } = targetInfo - const targetWebContents = await webContents.fromDevToolsTargetId(targetId) + const targetWebContents = await wc.fromDevToolsTargetId(targetId) } ``` @@ -1020,9 +1020,9 @@ 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 win = new BrowserWindow() const options = { extraHeaders: 'pragma: no-cache\n' } -webContents.loadURL('https://github.com', options) +win.webContents.loadURL('https://github.com', options) ``` #### `contents.loadFile(filePath[, options])` @@ -1052,6 +1052,7 @@ an app structure like this: Would require code like this ```js +const win = new BrowserWindow() win.loadFile('src/index.html') ``` @@ -1188,7 +1189,9 @@ when this process is unstable or unusable, for instance in order to recover from the `unresponsive` event. ```js -contents.on('unresponsive', async () => { +const win = new BrowserWindow() + +win.webContents.on('unresponsive', async () => { const { response } = await dialog.showMessageBox({ message: 'App X has become unresponsive', title: 'Do you want to try forcefully reloading the app?', @@ -1196,8 +1199,8 @@ contents.on('unresponsive', async () => { cancelId: 1 }) if (response === 0) { - contents.forcefullyCrashRenderer() - contents.reload() + win.webContents.forcefullyCrashRenderer() + win.webContents.reload() } }) ``` @@ -1224,8 +1227,9 @@ Injects CSS into the current web page and returns a unique key for the inserted stylesheet. ```js -contents.on('did-finish-load', () => { - contents.insertCSS('html, body { background-color: #f00; }') +const win = new BrowserWindow() +win.webContents.on('did-finish-load', () => { + win.webContents.insertCSS('html, body { background-color: #f00; }') }) ``` @@ -1239,9 +1243,11 @@ Removes the inserted CSS from the current web page. The stylesheet is identified by its key, which is returned from `contents.insertCSS(css)`. ```js -contents.on('did-finish-load', async () => { - const key = await contents.insertCSS('html, body { background-color: #f00; }') - contents.removeInsertedCSS(key) +const win = new BrowserWindow() + +win.webContents.on('did-finish-load', async () => { + const key = await win.webContents.insertCSS('html, body { background-color: #f00; }') + win.webContents.removeInsertedCSS(key) }) ``` @@ -1262,7 +1268,9 @@ this limitation. Code execution will be suspended until web page stop loading. ```js -contents.executeJavaScript('fetch("https://jsonplaceholder.typicode.com/users/1").then(resp => resp.json())', true) +const win = new BrowserWindow() + +win.webContents.executeJavaScript('fetch("https://jsonplaceholder.typicode.com/users/1").then(resp => resp.json())', true) .then((result) => { console.log(result) // Will be the JSON object from the fetch call }) @@ -1373,7 +1381,8 @@ Sets the maximum and minimum pinch-to-zoom level. > **NOTE**: Visual zoom is disabled by default in Electron. To re-enable it, call: > > ```js -> contents.setVisualZoomLevelLimits(1, 3) +> const win = new BrowserWindow() +> win.webContents.setVisualZoomLevelLimits(1, 3) > ``` #### `contents.undo()` @@ -1508,12 +1517,12 @@ 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') -webContents.on('found-in-page', (event, result) => { - if (result.finalUpdate) webContents.stopFindInPage('clearSelection') +const win = new BrowserWindow() +win.webContents.on('found-in-page', (event, result) => { + if (result.finalUpdate) win.webContents.stopFindInPage('clearSelection') }) -const requestId = webContents.findInPage('api') +const requestId = win.webContents.findInPage('api') console.log(requestId) ``` @@ -1593,6 +1602,7 @@ Use `page-break-before: always;` CSS style to force to print to a new page. Example usage: ```js +const win = new BrowserWindow() const options = { silent: true, deviceName: 'My-Printer', @@ -1889,8 +1899,9 @@ For example: ```js // Main process +const win = new BrowserWindow() const { port1, port2 } = new MessageChannelMain() -webContents.postMessage('port', { message: 'hello' }, [port1]) +win.webContents.postMessage('port', { message: 'hello' }, [port1]) // Renderer process ipcRenderer.on('port', (e, msg) => { diff --git a/docs/api/web-frame-main.md b/docs/api/web-frame-main.md index 34033a85645f..53a5f1f8b6e0 100644 --- a/docs/api/web-frame-main.md +++ b/docs/api/web-frame-main.md @@ -128,8 +128,9 @@ For example: ```js // Main process +const win = new BrowserWindow() const { port1, port2 } = new MessageChannelMain() -webContents.mainFrame.postMessage('port', { message: 'hello' }, [port1]) +win.webContents.mainFrame.postMessage('port', { message: 'hello' }, [port1]) // Renderer process ipcRenderer.on('port', (e, msg) => { diff --git a/docs/api/web-frame.md b/docs/api/web-frame.md index 06bf313547d0..db4ec1c31a33 100644 --- a/docs/api/web-frame.md +++ b/docs/api/web-frame.md @@ -96,13 +96,12 @@ with an array of misspelt words when complete. An example of using [node-spellchecker][spellchecker] as provider: -```javascript +```javascript @ts-expect-error=[2,6] const { webFrame } = require('electron') const spellChecker = require('spellchecker') webFrame.setSpellCheckProvider('en-US', { spellCheck (words, callback) { setTimeout(() => { - const spellchecker = require('spellchecker') const misspelled = words.filter(x => spellchecker.isMisspelled(x)) callback(misspelled) }, 0) diff --git a/docs/api/webview-tag.md b/docs/api/webview-tag.md index bc81fa8ed6da..4a71c998f54b 100644 --- a/docs/api/webview-tag.md +++ b/docs/api/webview-tag.md @@ -255,7 +255,7 @@ The `webview` tag has the following methods: **Example** -```javascript +```javascript @ts-expect-error=[3] const webview = document.querySelector('webview') webview.addEventListener('dom-ready', () => { webview.openDevTools() @@ -799,7 +799,7 @@ Fired when the guest window logs a console message. The following example code forwards all log messages to the embedder's console without regard for log level or other properties. -```javascript +```javascript @ts-expect-error=[3] const webview = document.querySelector('webview') webview.addEventListener('console-message', (e) => { console.log('Guest page logged a message:', e.message) @@ -820,7 +820,7 @@ Returns: Fired when a result is available for [`webview.findInPage`](#webviewfindinpagetext-options) request. -```javascript +```javascript @ts-expect-error=[3,6] const webview = document.querySelector('webview') webview.addEventListener('found-in-page', (e) => { webview.stopFindInPage('keepSelection') @@ -945,7 +945,7 @@ Fired when the guest page attempts to close itself. The following example code navigates the `webview` to `about:blank` when the guest attempts to close itself. -```javascript +```javascript @ts-expect-error=[3] const webview = document.querySelector('webview') webview.addEventListener('close', () => { webview.src = 'about:blank' @@ -965,7 +965,7 @@ Fired when the guest page has sent an asynchronous message to embedder page. With `sendToHost` method and `ipc-message` event you can communicate between guest page and embedder page: -```javascript +```javascript @ts-expect-error=[4,7] // In embedder page. const webview = document.querySelector('webview') webview.addEventListener('ipc-message', (event) => { diff --git a/docs/tutorial/asar-archives.md b/docs/tutorial/asar-archives.md index 23b987f42ee5..d010bc960350 100644 --- a/docs/tutorial/asar-archives.md +++ b/docs/tutorial/asar-archives.md @@ -55,7 +55,7 @@ fs.readdirSync('/path/to/example.asar') Use a module from the archive: -```javascript +```javascript @ts-nocheck require('./path/to/example.asar/dir/module.js') ``` diff --git a/docs/tutorial/asar-integrity.md b/docs/tutorial/asar-integrity.md index 63320cea3133..2bbf3ec84052 100644 --- a/docs/tutorial/asar-integrity.md +++ b/docs/tutorial/asar-integrity.md @@ -40,7 +40,7 @@ Valid `algorithm` values are currently `SHA256` only. The `hash` is a hash of t ASAR integrity checking is currently disabled by default and can be enabled by toggling a fuse. See [Electron Fuses](fuses.md) for more information on what Electron Fuses are and how they work. When enabling this fuse you typically also want to enable the `onlyLoadAppFromAsar` fuse otherwise the validity checking can be bypassed via the Electron app code search path. -```js +```js @ts-nocheck require('@electron/fuses').flipFuses( // E.g. /a/b/Foo.app pathToPackagedApp, diff --git a/docs/tutorial/automated-testing.md b/docs/tutorial/automated-testing.md index bb80b00365a3..650d5ca882cc 100644 --- a/docs/tutorial/automated-testing.md +++ b/docs/tutorial/automated-testing.md @@ -90,7 +90,7 @@ Usage of `selenium-webdriver` with Electron is the same as with normal websites, except that you have to manually specify how to connect ChromeDriver and where to find the binary of your Electron app: -```js title='test.js' +```js title='test.js' @ts-expect-error=[1] const webdriver = require('selenium-webdriver') const driver = new webdriver.Builder() // The "9515" is the port opened by ChromeDriver. @@ -155,7 +155,7 @@ Playwright launches your app in development mode through the `_electron.launch` To point this API to your Electron app, you can pass the path to your main process entry point (here, it is `main.js`). -```js {5} +```js {5} @ts-nocheck const { _electron: electron } = require('playwright') const { test } = require('@playwright/test') @@ -169,7 +169,7 @@ test('launch app', async () => { After that, you will access to an instance of Playwright's `ElectronApp` class. This is a powerful class that has access to main process modules for example: -```js {6-11} +```js {6-11} @ts-nocheck const { _electron: electron } = require('playwright') const { test } = require('@playwright/test') @@ -189,7 +189,7 @@ test('get isPackaged', async () => { It can also create individual [Page][playwright-page] objects from Electron BrowserWindow instances. For example, to grab the first BrowserWindow and save a screenshot: -```js {6-7} +```js {6-7} @ts-nocheck const { _electron: electron } = require('playwright') const { test } = require('@playwright/test') @@ -205,7 +205,7 @@ test('save screenshot', async () => { Putting all this together using the PlayWright Test runner, let's create a `example.spec.js` test file with a single test and assertion: -```js title='example.spec.js' +```js title='example.spec.js' @ts-nocheck const { _electron: electron } = require('playwright') const { test, expect } = require('@playwright/test') @@ -259,7 +259,7 @@ expose custom methods to your test suite. To create a custom driver, we'll use Node.js' [`child_process`](https://nodejs.org/api/child_process.html) API. The test suite will spawn the Electron process, then establish a simple messaging protocol: -```js title='testDriver.js' +```js title='testDriver.js' @ts-nocheck const childProcess = require('child_process') const electronPath = require('electron') @@ -296,7 +296,7 @@ For convenience, you may want to wrap `appProcess` in a driver object that provi high-level functions. Here is an example of how you can do this. Let's start by creating a `TestDriver` class: -```js title='testDriver.js' +```js title='testDriver.js' @ts-nocheck class TestDriver { constructor ({ path, args, env }) { this.rpcCalls = [] @@ -378,7 +378,7 @@ framework of your choosing. The following example uses [`ava`](https://www.npmjs.com/package/ava), but other popular choices like Jest or Mocha would work as well: -```js title='test.js' +```js title='test.js' @ts-nocheck const test = require('ava') const electronPath = require('electron') const { TestDriver } = require('./testDriver') diff --git a/docs/tutorial/code-signing.md b/docs/tutorial/code-signing.md index d52267ad9e14..e4ac634260f9 100644 --- a/docs/tutorial/code-signing.md +++ b/docs/tutorial/code-signing.md @@ -67,7 +67,7 @@ are likely using [`electron-packager`][], which includes [`@electron/osx-sign`][ If you're using Packager's API, you can pass [in configuration that both signs and notarizes your application](https://electron.github.io/electron-packager/main/interfaces/electronpackager.options.html). -```js +```js @ts-nocheck const packager = require('electron-packager') packager({ @@ -116,7 +116,7 @@ Electron app. This is the tool used under the hood by Electron Forge's `electron-winstaller` directly, use the `certificateFile` and `certificatePassword` configuration options when creating your installer. -```js {10-11} +```js {10-11} @ts-nocheck const electronInstaller = require('electron-winstaller') // NB: Use this syntax within an async function, Node does not have support for // top-level await as of Node 12. @@ -146,7 +146,7 @@ If you're not using Electron Forge and want to use `electron-wix-msi` directly, `certificateFile` and `certificatePassword` configuration options or pass in parameters directly to [SignTool.exe][] with the `signWithParams` option. -```js {12-13} +```js {12-13} @ts-nocheck import { MSICreator } from 'electron-wix-msi' // Step 1: Instantiate the MSICreator diff --git a/docs/tutorial/context-isolation.md b/docs/tutorial/context-isolation.md index c68c62faca8a..5615d4d9b3cf 100644 --- a/docs/tutorial/context-isolation.md +++ b/docs/tutorial/context-isolation.md @@ -16,7 +16,7 @@ Context isolation has been enabled by default since Electron 12, and it is a rec Exposing APIs from your preload script to a loaded website in the renderer process is a common use-case. With context isolation disabled, your preload script would share a common global `window` object with the renderer. You could then attach arbitrary properties to a preload script: -```javascript title='preload.js' +```javascript title='preload.js' @ts-nocheck // preload with contextIsolation disabled window.myAPI = { doAThing: () => {} @@ -25,7 +25,7 @@ window.myAPI = { The `doAThing()` function could then be used directly in the renderer process: -```javascript title='renderer.js' +```javascript title='renderer.js' @ts-nocheck // use the exposed API in the renderer window.myAPI.doAThing() ``` @@ -43,7 +43,7 @@ contextBridge.exposeInMainWorld('myAPI', { }) ``` -```javascript title='renderer.js' +```javascript title='renderer.js' @ts-nocheck // use the exposed API in the renderer window.myAPI.doAThing() ``` @@ -98,7 +98,7 @@ declare global { Doing so will ensure that the TypeScript compiler will know about the `electronAPI` property on your global `window` object when writing scripts in your renderer process: -```typescript title='renderer.ts' +```typescript title='renderer.ts' @ts-nocheck window.electronAPI.loadPreferences() ``` diff --git a/docs/tutorial/dark-mode.md b/docs/tutorial/dark-mode.md index 0e53d42e02bb..73134fcb95be 100644 --- a/docs/tutorial/dark-mode.md +++ b/docs/tutorial/dark-mode.md @@ -116,7 +116,7 @@ Now the renderer process can communicate with the main process securely and perf The `renderer.js` file is responsible for controlling the `