D
D
DanyGersh2022-04-19 19:08:33
JavaScript
DanyGersh, 2022-04-19 19:08:33

How to use @electron/remote to create a new BrowserWindow in ReactJS?

There is an application on Electron and using ReactJS. There was a need to make a new window through the component, but this does not work, and the new window in the console has the error "@electron/remote is disabled for this WebContents. Call require("@electron/remote/main").enable(webContents) to enable it."

Main.js:

const mainWindow = new BrowserWindow({
    width: 1280,
    height: 720,
    show: false,
    webPreferences: {
      nodeIntegration: true,
      enableRemoteModule: true,
      contextIsolation: false,
      webSecurity: false
    },
  })
  require("@electron/remote/main").initialize();
  require("@electron/remote/main").enable(mainWindow.webContents);


Function in component:
function createWindow () {
    let win = new BrowserWindow({
      webPreferences: {
        nodeIntegration: true,
        contextIsolation: false,
        webSecurity: false
      },
    })
    window.require("@electron/remote/main").enable(win.webContents);
    win.loadURL('http://localhost:3000/overlay')
  }
  createWindow()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question