diff --git a/docs/api/app.md b/docs/api/app.md index 9c690899a3..cd566c8dc5 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -501,7 +501,7 @@ Returns: Emitted when `desktopCapturer.getSources()` is called in the renderer process of `webContents`. Calling `event.preventDefault()` will make it return empty sources. -### Event: 'remote-require' +### Event: 'remote-require' _Deprecated_ Returns: @@ -513,7 +513,7 @@ Emitted when `remote.require()` is called in the renderer process of `webContent Calling `event.preventDefault()` will prevent the module from being returned. Custom value can be returned by setting `event.returnValue`. -### Event: 'remote-get-global' +### Event: 'remote-get-global' _Deprecated_ Returns: @@ -525,7 +525,7 @@ Emitted when `remote.getGlobal()` is called in the renderer process of `webConte Calling `event.preventDefault()` will prevent the global from being returned. Custom value can be returned by setting `event.returnValue`. -### Event: 'remote-get-builtin' +### Event: 'remote-get-builtin' _Deprecated_ Returns: @@ -537,7 +537,7 @@ Emitted when `remote.getBuiltin()` is called in the renderer process of `webCont Calling `event.preventDefault()` will prevent the module from being returned. Custom value can be returned by setting `event.returnValue`. -### Event: 'remote-get-current-window' +### Event: 'remote-get-current-window' _Deprecated_ Returns: @@ -548,7 +548,7 @@ Emitted when `remote.getCurrentWindow()` is called in the renderer process of `w Calling `event.preventDefault()` will prevent the object from being returned. Custom value can be returned by setting `event.returnValue`. -### Event: 'remote-get-current-web-contents' +### Event: 'remote-get-current-web-contents' _Deprecated_ Returns: diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8889656f54..f00179ca9c 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -8,9 +8,6 @@ Process: [Main](../glossary.md#main-process) // In the main process. const { BrowserWindow } = require('electron') -// Or use `remote` from the renderer process. -// const { BrowserWindow } = require('electron').remote - const win = new BrowserWindow({ width: 800, height: 600 }) // Load a remote URL diff --git a/docs/api/dialog.md b/docs/api/dialog.md index d12f72b73a..a0ed591d8c 100644 --- a/docs/api/dialog.md +++ b/docs/api/dialog.md @@ -11,14 +11,6 @@ const { dialog } = require('electron') console.log(dialog.showOpenDialog({ properties: ['openFile', '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 -console.log(dialog) -``` - ## Methods The `dialog` module has the following methods: diff --git a/docs/api/frameless-window.md b/docs/api/frameless-window.md index 48a41d6be2..fcdb1cc5d2 100644 --- a/docs/api/frameless-window.md +++ b/docs/api/frameless-window.md @@ -112,13 +112,19 @@ optional parameter can be used to forward mouse move messages to the web page, allowing events such as `mouseleave` to be emitted: ```javascript -const win = require('electron').remote.getCurrentWindow() +const { ipcRenderer } = require('electron') const el = document.getElementById('clickThroughElement') el.addEventListener('mouseenter', () => { - win.setIgnoreMouseEvents(true, { forward: true }) + ipcRenderer.send('set-ignore-mouse-events', true, { forward: true }) }) el.addEventListener('mouseleave', () => { - win.setIgnoreMouseEvents(false) + ipcRenderer.send('set-ignore-mouse-events', false) +}) + +// Main process +const { ipcMain } = require('electron') +ipcMain.on('set-ignore-mouse-events', (event, ...args) => { + BrowserWindow.fromWebContents(event.sender).setIgnoreMouseEvents(...args) }) ``` diff --git a/docs/api/sandbox-option.md b/docs/api/sandbox-option.md index 9503dd8a4c..da8b530911 100644 --- a/docs/api/sandbox-option.md +++ b/docs/api/sandbox-option.md @@ -88,26 +88,17 @@ and preload.js: ```js // This file is loaded whenever a javascript context is created. It runs in a -// 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 { ipcRenderer, remote } = require('electron') -const fs = remote.require('fs') - -// read a configuration file using the `fs` module -const buf = fs.readFileSync('allowed-popup-urls.json') -const allowedUrls = JSON.parse(buf.toString('utf8')) +// private scope that can access a subset of Electron renderer APIs. Without +// contextIsolation enabled, it's possible to accidentally leak privileged +// globals like ipcRenderer to web content. +const { ipcRenderer } = require('electron') const defaultWindowOpen = window.open -function customWindowOpen (url, ...args) { - if (allowedUrls.indexOf(url) === -1) { - ipcRenderer.sendSync('blocked-popup-notification', location.origin, url) - return null - } - return defaultWindowOpen(url, ...args) +window.open = function customWindowOpen (url, ...args) { + ipcRenderer.send('report-window-open', location.origin, url, args) + return defaultWindowOpen(url + '?from_electron=1', ...args) } - -window.open = customWindowOpen ``` Important things to notice in the preload script: @@ -115,8 +106,6 @@ Important things to notice in the preload script: - Even though the sandboxed renderer doesn't have Node.js running, it still has access to a limited node-like environment: `Buffer`, `process`, `setImmediate`, `clearImmediate` and `require` are available. -- The preload script can indirectly access all APIs from the main process through the - `remote` and `ipcRenderer` modules. - The preload script must be contained in a single script, but it is possible to have complex preload code composed with multiple modules by using a tool like webpack or browserify. An example of using browserify is below. @@ -144,15 +133,12 @@ following modules: - `desktopCapturer` - `ipcRenderer` - `nativeImage` - - `remote` - `webFrame` - `events` - `timers` - `url` -More may be added as needed to expose more Electron APIs in the sandbox, but any -module in the main process can already be used through -`electron.remote.require`. +More may be added as needed to expose more Electron APIs in the sandbox. ## Rendering untrusted content diff --git a/docs/api/synopsis.md b/docs/api/synopsis.md index 6ee64e6762..535e08caa1 100644 --- a/docs/api/synopsis.md +++ b/docs/api/synopsis.md @@ -9,7 +9,7 @@ the [native modules](../tutorial/using-native-node-modules.md)). Electron also provides some extra built-in modules for developing native desktop applications. Some modules are only available in the main process, some are only available in the renderer process (web page), and some can be used in -both processes. +either process type. The basic rule is: if a module is [GUI][gui] or low-level system related, then it should be only available in the main process. You need to be familiar with @@ -29,15 +29,15 @@ app.whenReady().then(() => { ``` The renderer process is no different than a normal web page, except for the -extra ability to use node modules: +extra ability to use node modules if `nodeIntegration` is enabled: ```html
diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 7380529fca..59d8e55b80 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -784,7 +784,7 @@ Returns: Emitted when `desktopCapturer.getSources()` is called in the renderer process. Calling `event.preventDefault()` will make it return empty sources. -#### Event: 'remote-require' +#### Event: 'remote-require' _Deprecated_ Returns: @@ -795,7 +795,7 @@ Emitted when `remote.require()` is called in the renderer process. Calling `event.preventDefault()` will prevent the module from being returned. Custom value can be returned by setting `event.returnValue`. -#### Event: 'remote-get-global' +#### Event: 'remote-get-global' _Deprecated_ Returns: @@ -806,7 +806,7 @@ Emitted when `remote.getGlobal()` is called in the renderer process. Calling `event.preventDefault()` will prevent the global from being returned. Custom value can be returned by setting `event.returnValue`. -#### Event: 'remote-get-builtin' +#### Event: 'remote-get-builtin' _Deprecated_ Returns: @@ -817,7 +817,7 @@ Emitted when `remote.getBuiltin()` is called in the renderer process. Calling `event.preventDefault()` will prevent the module from being returned. Custom value can be returned by setting `event.returnValue`. -#### Event: 'remote-get-current-window' +#### Event: 'remote-get-current-window' _Deprecated_ Returns: @@ -827,7 +827,7 @@ Emitted when `remote.getCurrentWindow()` is called in the renderer process. Calling `event.preventDefault()` will prevent the object from being returned. Custom value can be returned by setting `event.returnValue`. -#### Event: 'remote-get-current-web-contents' +#### Event: 'remote-get-current-web-contents' _Deprecated_ Returns: @@ -1457,7 +1457,7 @@ An example of showing devtools in a `