jsonserializationelectronipcrenderer

How does IPCRenderer.send() serialize data to JSON?


I am trying to send information about an error event using ipcRenderer.send("error", errorObject) but my Error object gets serialized to '{}' in the listener. Now, I know that ipcRenderer serializes objects to JSON internally (More information here: https://electronjs.org/docs/api/ipc-renderer) so I want to find out what method is called for serialization to JSON internally so that I can try to override it in my code. Can anyone help?


Solution

  • I guess it's using JSON.stringify() but it's probably serialized for security reason so maybe it's better to not override it. BTW I don't think override JSON.stringify() is a good practice in any way. I didn't notice ipcRenderer.send serialized data, I pass plain JavaScript Object as data and don't parse it on ipcMain side.