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!
I had the same issue. I believe that when you use ipcRenderer.sendSync
it's expecting a return value.
e.g.
sendSync
messageipcRenderer.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.
.on
ListeneripcMain.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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With