Issue with Electon 16
exander77 opened this issue ยท 20 comments
node:electron/js2c/renderer_init:73 Error: @electron/remote is disabled for this WebContents. Set {enableRemoteModule: true} in WebPreferences to enable it.
enableRemoteModule
is set true and remote is initialized in main. Worked fine with Electron 15.
@MarshallOfSound Electron remote may be a separate module, but as it worked in the previous version of Electron and I can't seem to find any changes regarding breaking changes between Electron 15 => Electron 16, I would assume that it is Electron issue and not Electron Remote issue.
As stated in https://github.com/electron/remote/blob/main/docs/migration-2.md you now need to call remoteMain.initialize()
and then remoteMain.enable(win.webContents)
to enable the remote module.
Just tested this with electron@16.0.0-beta.6 and no problems:
import { initialize, enable as enableRemote } from "@electron/remote/main";
initialize();
// ...
const win = new BrowserWindow({ ... });
enableRemote(win.webContents);
Remote main is initialized.
I already was on version 15 without any issues, so this change:
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).`
Does not apply for moving from 15 to 16?
I am still on electron-remote 1. So the migration to electron-remote 2 does not apply either?
From what you are telling it seems that I need to migrate from electron-remote 1 to electon-remote 2 if I upgrade from electon 15 to electron 16. If that is so, the issue is documentation.
If you're on version 1.x of @electron/remote this error should trigger https://github.com/electron/remote/pull/75/files.
I only got:
node:electron/js2c/renderer_init:73 Error: @electron/remote is disabled for this WebContents. Set {enableRemoteModule: true} in WebPreferences to enable it.
So either a different check catches the problem and issues the message I got or the check was not present in my version.
My remote version was 1.0.4.
"@electron/remote": "^2.0.1",
"electron": "^16.0.0",
I received such errors
Error: node_modules/@electron/remote/index.d.ts:8:43 - error TS2339: Property 'ClientRequest' does not exist on type 'typeof CrossProcessExports'.
8 export var ClientRequest: typeof Electron.ClientRequest;
Error: node_modules/@electron/remote/index.d.ts:10:41 - error TS2339: Property 'CommandLine' does not exist on type 'typeof CrossProcessExports'.
10 export var CommandLine: typeof Electron.CommandLine;
Error: node_modules/@electron/remote/index.d.ts:12:37 - error TS2339: Property 'Cookies' does not exist on type 'typeof CrossProcessExports'.
12 export var Cookies: typeof Electron.Cookies;
Error: node_modules/@electron/remote/index.d.ts:14:38 - error TS2339: Property 'Debugger' does not exist on type 'typeof CrossProcessExports'.
14 export var Debugger: typeof Electron.Debugger;
Error: node_modules/@electron/remote/index.d.ts:17:34 - error TS2339: Property 'Dock' does not exist on type 'typeof CrossProcessExports'.
17 export var Dock: typeof Electron.Dock;
Error: node_modules/@electron/remote/index.d.ts:18:42 - error TS2339: Property 'DownloadItem' does not exist on type 'typeof CrossProcessExports'.
18 export var DownloadItem: typeof Electron.DownloadItem;
Error: node_modules/@electron/remote/index.d.ts:21:45 - error TS2339: Property 'IncomingMessage' does not exist on type 'typeof CrossProcessExports'.
21 export var IncomingMessage: typeof Electron.IncomingMessage;
Error: node_modules/@electron/remote/index.d.ts:26:45 - error TS2339: Property 'MessagePortMain' does not exist on type 'typeof CrossProcessExports'.
26 export var MessagePortMain: typeof Electron.MessagePortMain;
Error: node_modules/@electron/remote/index.d.ts:27:41 - error TS2551: Property 'NativeImage' does not exist on type 'typeof CrossProcessExports'. Did you mean 'nativeImage'?
27 export var nativeImage: typeof Electron.NativeImage;
node_modules/electron/electron.d.ts:16950:11
16950 const nativeImage: typeof NativeImage;
'nativeImage' is declared here.
Error: node_modules/@electron/remote/index.d.ts:36:44 - error TS2339: Property 'ServiceWorkers' does not exist on type 'typeof CrossProcessExports'.
36 export var ServiceWorkers: typeof Electron.ServiceWorkers;
Error: node_modules/@electron/remote/index.d.ts:37:37 - error TS2551: Property 'Session' does not exist on type 'typeof CrossProcessExports'. Did you mean 'session'?
37 export var session: typeof Electron.Session;
node_modules/electron/electron.d.ts:16970:11
16970 const session: typeof Session;
'session' is declared here.
Error: node_modules/@electron/remote/index.d.ts:41:44 - error TS2339: Property 'TouchBarButton' does not exist on type 'typeof CrossProcessExports'.
41 export var TouchBarButton: typeof Electron.TouchBarButton;
Error: node_modules/@electron/remote/index.d.ts:42:49 - error TS2339: Property 'TouchBarColorPicker' does not exist on type 'typeof CrossProcessExports'.
42 export var TouchBarColorPicker: typeof Electron.TouchBarColorPicker;
Error: node_modules/@electron/remote/index.d.ts:43:43 - error TS2339: Property 'TouchBarGroup' does not exist on type 'typeof CrossProcessExports'.
43 export var TouchBarGroup: typeof Electron.TouchBarGroup;
Error: node_modules/@electron/remote/index.d.ts:44:43 - error TS2339: Property 'TouchBarLabel' does not exist on type 'typeof CrossProcessExports'.
44 export var TouchBarLabel: typeof Electron.TouchBarLabel;
46 export var TouchBarPopover: typeof Electron.TouchBarPopover;
Error: node_modules/@electron/remote/index.d.ts:47:46 - error TS2339: Property 'TouchBarScrubber' does not exist on type 'typeof CrossProcessExports'.
47 export var TouchBarScrubber: typeof Electron.TouchBarScrubber;
Error: node_modules/@electron/remote/index.d.ts:48:54 - error TS2339: Property 'TouchBarSegmentedControl' does not exist on type 'typeof CrossProcessExports'.
48 export var TouchBarSegmentedControl: typeof Electron.TouchBarSegmentedControl;
Error: node_modules/@electron/remote/index.d.ts:49:44 - error TS2339: Property 'TouchBarSlider' does not exist on type 'typeof CrossProcessExports'.
49 export var TouchBarSlider: typeof Electron.TouchBarSlider;
Error: node_modules/@electron/remote/index.d.ts:50:44 - error TS2339: Property 'TouchBarSpacer' does not exist on type 'typeof CrossProcessExports'.
50 export var TouchBarSpacer: typeof Electron.TouchBarSpacer;
Error: node_modules/@electron/remote/index.d.ts:52:41 - error TS2551: Property 'WebContents' does not exist on type 'typeof CrossProcessExports'. Did you mean 'webContents'?
52 export var webContents: typeof Electron.WebContents;
node_modules/electron/electron.d.ts:16989:11
16989 const webContents: typeof WebContents;
'webContents' is declared here.
Error: node_modules/@electron/remote/index.d.ts:53:40 - error TS2339: Property 'WebRequest' does not exist on type 'typeof CrossProcessExports'.
53 export var WebRequest: typeof Electron.WebRequest;
"@electron/remote": "^2.0.1", "electron": "^16.0.0",
I received such errors
Error: node_modules/@electron/remote/index.d.ts:8:43 - error TS2339: Property 'ClientRequest' does not exist on type 'typeof CrossProcessExports'. 8 export var ClientRequest: typeof Electron.ClientRequest; Error: node_modules/@electron/remote/index.d.ts:10:41 - error TS2339: Property 'CommandLine' does not exist on type 'typeof CrossProcessExports'. 10 export var CommandLine: typeof Electron.CommandLine; Error: node_modules/@electron/remote/index.d.ts:12:37 - error TS2339: Property 'Cookies' does not exist on type 'typeof CrossProcessExports'. 12 export var Cookies: typeof Electron.Cookies; Error: node_modules/@electron/remote/index.d.ts:14:38 - error TS2339: Property 'Debugger' does not exist on type 'typeof CrossProcessExports'. 14 export var Debugger: typeof Electron.Debugger; Error: node_modules/@electron/remote/index.d.ts:17:34 - error TS2339: Property 'Dock' does not exist on type 'typeof CrossProcessExports'. 17 export var Dock: typeof Electron.Dock; Error: node_modules/@electron/remote/index.d.ts:18:42 - error TS2339: Property 'DownloadItem' does not exist on type 'typeof CrossProcessExports'. 18 export var DownloadItem: typeof Electron.DownloadItem; Error: node_modules/@electron/remote/index.d.ts:21:45 - error TS2339: Property 'IncomingMessage' does not exist on type 'typeof CrossProcessExports'. 21 export var IncomingMessage: typeof Electron.IncomingMessage; Error: node_modules/@electron/remote/index.d.ts:26:45 - error TS2339: Property 'MessagePortMain' does not exist on type 'typeof CrossProcessExports'. 26 export var MessagePortMain: typeof Electron.MessagePortMain; Error: node_modules/@electron/remote/index.d.ts:27:41 - error TS2551: Property 'NativeImage' does not exist on type 'typeof CrossProcessExports'. Did you mean 'nativeImage'? 27 export var nativeImage: typeof Electron.NativeImage; node_modules/electron/electron.d.ts:16950:11 16950 const nativeImage: typeof NativeImage; 'nativeImage' is declared here. Error: node_modules/@electron/remote/index.d.ts:36:44 - error TS2339: Property 'ServiceWorkers' does not exist on type 'typeof CrossProcessExports'. 36 export var ServiceWorkers: typeof Electron.ServiceWorkers; Error: node_modules/@electron/remote/index.d.ts:37:37 - error TS2551: Property 'Session' does not exist on type 'typeof CrossProcessExports'. Did you mean 'session'? 37 export var session: typeof Electron.Session; node_modules/electron/electron.d.ts:16970:11 16970 const session: typeof Session; 'session' is declared here. Error: node_modules/@electron/remote/index.d.ts:41:44 - error TS2339: Property 'TouchBarButton' does not exist on type 'typeof CrossProcessExports'. 41 export var TouchBarButton: typeof Electron.TouchBarButton; Error: node_modules/@electron/remote/index.d.ts:42:49 - error TS2339: Property 'TouchBarColorPicker' does not exist on type 'typeof CrossProcessExports'. 42 export var TouchBarColorPicker: typeof Electron.TouchBarColorPicker; Error: node_modules/@electron/remote/index.d.ts:43:43 - error TS2339: Property 'TouchBarGroup' does not exist on type 'typeof CrossProcessExports'. 43 export var TouchBarGroup: typeof Electron.TouchBarGroup; Error: node_modules/@electron/remote/index.d.ts:44:43 - error TS2339: Property 'TouchBarLabel' does not exist on type 'typeof CrossProcessExports'. 44 export var TouchBarLabel: typeof Electron.TouchBarLabel; 46 export var TouchBarPopover: typeof Electron.TouchBarPopover; Error: node_modules/@electron/remote/index.d.ts:47:46 - error TS2339: Property 'TouchBarScrubber' does not exist on type 'typeof CrossProcessExports'. 47 export var TouchBarScrubber: typeof Electron.TouchBarScrubber; Error: node_modules/@electron/remote/index.d.ts:48:54 - error TS2339: Property 'TouchBarSegmentedControl' does not exist on type 'typeof CrossProcessExports'. 48 export var TouchBarSegmentedControl: typeof Electron.TouchBarSegmentedControl; Error: node_modules/@electron/remote/index.d.ts:49:44 - error TS2339: Property 'TouchBarSlider' does not exist on type 'typeof CrossProcessExports'. 49 export var TouchBarSlider: typeof Electron.TouchBarSlider; Error: node_modules/@electron/remote/index.d.ts:50:44 - error TS2339: Property 'TouchBarSpacer' does not exist on type 'typeof CrossProcessExports'. 50 export var TouchBarSpacer: typeof Electron.TouchBarSpacer; Error: node_modules/@electron/remote/index.d.ts:52:41 - error TS2551: Property 'WebContents' does not exist on type 'typeof CrossProcessExports'. Did you mean 'webContents'? 52 export var webContents: typeof Electron.WebContents; node_modules/electron/electron.d.ts:16989:11 16989 const webContents: typeof WebContents; 'webContents' is declared here. Error: node_modules/@electron/remote/index.d.ts:53:40 - error TS2339: Property 'WebRequest' does not exist on type 'typeof CrossProcessExports'. 53 export var WebRequest: typeof Electron.WebRequest;
electron v16.x had modify export ๏ผ @electron/remote need update index.d.ts
import * as Electron from 'electron';
import * as Main from 'electron/main'
// Taken from `RemoteMainInterface`
export var app: Electron.App;
export var autoUpdater: Electron.AutoUpdater;
export var BrowserView: typeof Electron.BrowserView;
export var BrowserWindow: typeof Electron.BrowserWindow;
export var ClientRequest: Main.ClientRequest;
export var clipboard: Electron.Clipboard;
export var CommandLine: Main.CommandLine;
export var contentTracing: Electron.ContentTracing;
export var Cookies: Main.Cookies;
export var crashReporter: Electron.CrashReporter;
export var Debugger: Main.Debugger;
export var desktopCapturer: Electron.DesktopCapturer;
export var dialog: Electron.Dialog;
export var Dock: Main.Dock;
export var DownloadItem: Main.DownloadItem;
export var globalShortcut: Electron.GlobalShortcut;
export var inAppPurchase: Electron.InAppPurchase;
export var IncomingMessage: Main.IncomingMessage;
export var ipcMain: Electron.IpcMain;
export var Menu: typeof Electron.Menu;
export var MenuItem: typeof Electron.MenuItem;
export var MessageChannelMain: typeof Electron.MessageChannelMain;
export var MessagePortMain: Main.MessagePortMain;
export var nativeImage: Electron.NativeImage;
export var nativeTheme: Electron.NativeTheme;
export var net: Electron.Net;
export var netLog: Electron.NetLog;
export var Notification: typeof Electron.Notification;
export var powerMonitor: Electron.PowerMonitor;
export var powerSaveBlocker: Electron.PowerSaveBlocker;
export var protocol: Electron.Protocol;
export var screen: Electron.Screen;
export var ServiceWorkers: Main.ServiceWorkers;
export var session: Main.Session;
export var shell: Electron.Shell;
export var systemPreferences: Electron.SystemPreferences;
export var TouchBar: typeof Electron.TouchBar;
export var TouchBarButton: Main.TouchBarButton;
export var TouchBarColorPicker: Main.TouchBarColorPicker;
export var TouchBarGroup: Main.TouchBarGroup;
export var TouchBarLabel: Main.TouchBarLabel;
export var TouchBarOtherItemsProxy: Main.TouchBarOtherItemsProxy;
export var TouchBarPopover: Main.TouchBarPopover;
export var TouchBarScrubber: Main.TouchBarScrubber;
export var TouchBarSegmentedControl: Main.TouchBarSegmentedControl;
export var TouchBarSlider: Main.TouchBarSlider;
export var TouchBarSpacer: Main.TouchBarSpacer;
export var Tray: typeof Electron.Tray;
export var webContents: typeof Electron.webContents;
export var WebRequest: Main.WebRequest;
// Taken from `Remote`
export function getCurrentWebContents(): Electron.WebContents;
export function getCurrentWindow(): Electron.BrowserWindow;
export function getGlobal(name: string): any;
export var process: NodeJS.Process;
export var require: NodeJS.Require;
Electron 16 is completely unusable if using electron remote
I have the similar problem, it works in Mac and it does not in ubuntu...
Electron 16 is completely unusable if using electron remote
Just tested this with electron@^16.0.5 and it works in Mac:
"electron": "^16.0.5",
"@electron/remote": "^2.0.1"
main.js
require('@electron/remote/main').initialize()
const mainWindow = new BrowserWindow({
.........
})
require("@electron/remote/main").enable(mainWindow.webContents)
renderer.js
const { BrowserWindow } = require('@electron/remote')
let win = new BrowserWindow({ width: 1800, height: 1600 })
win.loadURL('https://www.google.com/')
I encounter the same problem with electron 15.3.5 btw.
@huyinghuan does it maybe make sense to open a new issue? I think we're all encountering the problem you describe, but the issue description indicates a completely different problem (not initializing the remote module).
I fixed this by upgrading electron remote version.
@exander77 do you mean to the latest commit on master?
@johannesjo No. Read the above discussion.
Think I found a possible fix for now.
Enabling the remote module within renderer doesn't do anything. It seems to only have an effect in main.
Calling it within a 'browser-window-created' event should work.
app.on('browser-window-created', (_, window) => {
require("@electron/remote/main").enable(window.webContents)
})
thanks @panthesingh - your code worked for me for ferdium!
Same thing for me, thanks @panthesingh, as It seems not possible to "enbale" from a preload file.
But do you think it is possible to filter windows not to enable remote on every opened windows?
@sindbad75 @vraravam ๐ glad it helped!
@sindbad75 The main way I can think of would be to filter using some window object property.
if (window.property === x) { then ... }
Ok thanks, I will try it like this.