You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`@electron/remote` is an [Electron](https://electronjs.org) module that bridges
4
7
JavaScript objects from the main process to the renderer process. This lets you
5
8
access main-process-only objects as if they were available in the renderer
6
9
process.
7
10
8
11
> ⚠️ **Warning!** This module has [many subtle
9
12
> pitfalls][remote-considered-harmful]. There is almost always a better way to
10
-
> accomplish your task than using this module. For example, [`ipcRenderer.invoke`](https://www.electronjs.org/docs/api/ipc-renderer#ipcrendererinvokechannel-args) can serve many common use cases.
13
+
> accomplish your task than using this module. For example, [`ipcRenderer.invoke`](https://www.electronjs.org/docs/latest/api/ipc-renderer#ipcrendererinvokechannel-args) can serve many common use cases.
11
14
12
15
`@electron/remote` is a replacement for the built-in `remote` module in
13
16
Electron, which is deprecated and will eventually be removed.
@@ -52,12 +55,13 @@ configure your bundler appropriately to package the code of `@electron/remote`
52
55
in the preload script. Of course, [using `@electron/remote` makes the sandbox
53
56
much less effective][remote-considered-harmful].
54
57
55
-
**Note:**`@electron/remote` respects the `enableRemoteModule` WebPreferences
58
+
**Note:** In `electron >= 14.0.0`, you must use the new `enable` API to enable the remote module for each desired `WebContents` separately: `require("@electron/remote/main").enable(webContents)`.
59
+
60
+
In `electron < 14.0.0`, `@electron/remote` respects the `enableRemoteModule` WebPreferences
56
61
value. You must pass `{ webPreferences: { enableRemoteModule: true } }` to
57
62
the constructor of `BrowserWindow`s that should be granted permission to use
58
63
`@electron/remote`.
59
64
60
-
61
65
# API Reference
62
66
63
67
The `remote` module provides a simple way to do inter-process communication
@@ -85,9 +89,11 @@ of the remote module:
85
89
require('@electron/remote/main').initialize()
86
90
```
87
91
88
-
**Note:** The remote module can be disabled for security reasons in the following contexts:
89
-
-[`BrowserWindow`](browser-window.md) - by setting the `enableRemoteModule` option to `false`.
90
-
-[`<webview>`](webview-tag.md) - by setting the `enableremotemodule` attribute to `false`.
92
+
**Note:** In `electron >= 14.0.0` the remote module is disabled by default for any `WebContents` instance and is only enabled for specified `WebContents` after explicitly calling `require("@electron/remote/main").enable(webContents)`.
93
+
94
+
In `electron < 14.0.0` the remote module can be disabled for security reasons in the following contexts:
95
+
-[`BrowserWindow`](https://www.electronjs.org/docs/latest/api/browser-window) - by setting the `enableRemoteModule` option to `false`.
96
+
-[`<webview>`](https://www.electronjs.org/docs/latest/api/webview-tag) - by setting the `enableremotemodule` attribute to `false`.
value: valueToMeta(event.sender,contextId,newError('@electron/remote is disabled for this WebContents. Set {enableRemoteModule: true} in WebPreferences to enable it.'))
318
+
value: valueToMeta(event.sender,contextId,newError('@electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.'))
309
319
};
310
320
return;
311
321
}
@@ -338,8 +348,6 @@ let initialized = false;
338
348
functioninitialize(){
339
349
if(initialized)
340
350
thrownewError('@electron/remote has already been initialized');
thrownewError('@electron/remote >= 2.x is required for Electron >= 14. See https://github.com/electron/remote/blob/main/docs/migration-2.md for migration instructions.');
consterr=newError(`Could not call remote function '${func.name||'anonymous'}'. Check that the function signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
444
+
consterr=newError(`Could not call remote function '${func.name||"anonymous"}'. Check that the function signature is correct. Underlying error: ${error}\n`+
consterr=newError(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error.message}\nUnderlying stack: ${error.stack}\n`);
468
+
consterr=newError(`Could not call remote method '${method}'. Check that the method signature is correct. Underlying error: ${error}`+
0 commit comments