jlongster / electron-with-server-example

An example Electron app with a backend server all wired up via IPC
1.01k stars 68 forks source link

The renderer's node-ipc works in the {contextIsolation: true} ? #11

Open zicjin opened 3 years ago

zicjin commented 3 years ago

Electron 12 it will be enabled contextIsolation by default. https://www.electronjs.org/docs/tutorial/context-isolation

contextBridge.exposeInMainWorld('electron', {
  getSocketId: () => socketPromise,
  ipcConnect: (id, func) => {
    ipc.config.silent = true
    ipc.connectTo(id, () => {
      func(ipc.of[id])
    })
  },
  ...
})

got error: image

const connectSocket = (socketId: string) => {
  window.electron.ipcConnect(socketId, (client) => {
    client.on('message', (data: string) => {
      const msg = JSON.parse(data)
  ...