[Solved] Uncaught Error: @electron/remote is disabled for this WebContents

There is an error using the remote module:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.
at IpcMainImpl.<anonymous>
Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it. at IpcMainImpl.<anonymous>
Uncaught Error: @electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it.
    at IpcMainImpl.<anonymous>

 

according to the prompt, you need to add a line: require(“@electron/remote/main”).enable(webContents) in main.js, but if it is added directly, the webcontents is not defined error will be displayed.

You can’t add it directly, webContents should be preceded by the defined variable name, as follows, webContents should be replaced with mainWindow.webContents.

Read More: