remote icon indicating copy to clipboard operation
remote copied to clipboard

Issue with Electon 16

Open exander77 opened this issue 2 years ago • 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.

exander77 avatar Nov 04 '21 01:11 exander77

@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.

exander77 avatar Nov 04 '21 02:11 exander77

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 [email protected] and no problems:

import { initialize, enable as enableRemote } from "@electron/remote/main";
initialize();
// ...
const win = new BrowserWindow({ ... });
enableRemote(win.webContents);

weedz avatar Nov 04 '21 08:11 weedz

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.

exander77 avatar Nov 04 '21 11:11 exander77

If you're on version 1.x of @electron/remote this error should trigger https://github.com/electron/remote/pull/75/files.

weedz avatar Nov 04 '21 15:11 weedz

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.

exander77 avatar Nov 04 '21 16:11 exander77

"@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;

oleg-tsybulsky avatar Nov 18 '21 11:11 oleg-tsybulsky

"@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;

huyinghuan avatar Nov 24 '21 09:11 huyinghuan

Electron 16 is completely unusable if using electron remote

DanielMcAssey avatar Dec 03 '21 10:12 DanielMcAssey

I have the similar problem, it works in Mac and it does not in ubuntu...

lluisemper avatar Dec 08 '21 16:12 lluisemper

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/')

S112 avatar Jan 05 '22 07:01 S112

I encounter the same problem with electron 15.3.5 btw.

johannesjo avatar Jan 15 '22 10:01 johannesjo

@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).

johannesjo avatar Jan 15 '22 10:01 johannesjo

I fixed this by upgrading electron remote version.

exander77 avatar Jan 15 '22 12:01 exander77

@exander77 do you mean to the latest commit on master?

johannesjo avatar Jan 15 '22 15:01 johannesjo

@johannesjo No. Read the above discussion.

exander77 avatar Jan 15 '22 15:01 exander77

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)
})

panthesingh avatar Jan 29 '22 06:01 panthesingh

thanks @panthesingh - your code worked for me for ferdium!

vraravam avatar Apr 18 '22 10:04 vraravam

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 avatar Apr 19 '22 07:04 sindbad75

@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 ... }

panthesingh avatar Apr 19 '22 11:04 panthesingh

Ok thanks, I will try it like this.

sindbad75 avatar Apr 20 '22 11:04 sindbad75