Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Electron: Error: Unable to deserialize cloned data due to invalid or unsupported version

I have an angular application running standalone, and am trying to create an electron app that then just does: mainWindow.loadURL('http://localhost:4200/'); It is only localhost for my dev environment, it real conditions it will not be.

In electron I'm setting nodeIntegration to true, which is allowing my angular app to access ipc.

const mainWindow = new BrowserWindow({
    webPreferences: {
      nodeIntegration: true,
    }
  });

In angular I have my ping-pong function:

  public playPingPong() {
    if(this._electronService.isElectronApp) {
      console.log('Is electron.')
      console.log(this._electronService.ipcRenderer);
      let pong: any = this._electronService.ipcRenderer.sendSync('ping', 'ping');
      console.log(pong);
    }
  }

The application errors out though after logging the ipcRenderer with the error from the title:

core.js:5845 ERROR Error: Unable to deserialize cloned data due to invalid or unsupported version.
    at EventEmitter../lib/renderer/api/ipc-renderer.ts.ipcRenderer.sendSync (ipc-renderer.ts:13)
    at ArcMapComponent.playPingPong (arc-map.component.ts:61)
    at ArcMapComponent.ngOnInit (arc-map.component.ts:164)
    at callHook (core.js:3909)
    at callHooks (core.js:3873)
    at executeInitAndCheckHooks (core.js:3814)
    at refreshView (core.js:11723)
    at refreshDynamicEmbeddedViews (core.js:13070)
    at refreshView (core.js:11728)
    at refreshComponent (core.js:13145)

Thank you in advance!

like image 248
John Wyant Avatar asked Mar 14 '20 13:03

John Wyant


2 Answers

I had the same issue. I believe that when you use ipcRenderer.sendSync it's expecting a return value.

e.g.

Renderer sendSync message

ipcRenderer.sendSync("pong_channel", { type: "ping"});

This code just sent a message to the main process with a channel identifier of pong_channel and a json object.

Main .on Listener

ipcMain.on("pong_channel", (event, args) => {
    if(args.type === "pong") {
        print("Received pong successfully!")
    }
    event.returnValue = "received";
});

The main process is listening on the channel and executed a side-effect. But the key point is that it returned a value by event.returnValue. I was facing the same issue but it went away once I set the returnValue.

I also usually have my channel names in two enums. One that has all of the messages to the main process and the other all of the messages to the renderer. This keeps things tidier than a string.

I hope this helps!

like image 164
b-zurg Avatar answered Nov 05 '22 05:11

b-zurg


I had the error because I was calling ipcRenderer.sendSync without a listener set on the main side.

In my code it was caused by an Exception stopping the execution on the main thread and preventing the listener to be registered. But I imagine this same error would pop if you have a typo on the channel parameter of either the sender or the listener.

like image 20
Mark E Avatar answered Nov 05 '22 06:11

Mark E