ipcRenderer not receiving message from main process

后端 未结 1 1186
鱼传尺愫
鱼传尺愫 2020-12-04 04:02

I can see the \"Hello from renderer\" alert, but not the \"Goodbye from renderer\" alert.

Running in Windows 10.

And I can\'t see the \"received!\" alert, wh

相关标签:
1条回答
  • 2020-12-04 04:41
    let mainWindow = new BrowserWindow(
      {
        width: 800,
        height: 600,
        webPreferences:{
          nodeIntegration:true
        }
      });
    

    Please add nodeIntegration when you are creating the browser window. You are using the Node API at your renderer. When you don't enable nodeIntegration then you won't be able to use any node modules at your renderer js.

    To confirm this you can see this error message from your app debug console.

    mainWindow.webContents.on('did-finish-load', () => {
        // open dev tools
        mainWindow.webContents.openDevTools()
        mainWindow.webContents.send("from-main", "teste");
      });
    

    Uncaught ReferenceError: require is not defined

    This means you didn't enable the nodeIntegration when you are creating the browserWindow.

    0 讨论(0)
提交回复
热议问题