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?
Asked
Active
Viewed 1,556 times
1 Answers
0
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.

Damien
- 3,915
- 1
- 17
- 18
-
Hey! Thanks for the suggestion, it would work for most objects, however, in this case, I want to send and Error object which gets serialized as an empty object '{}'. As far as I know JSON.stringify() calls toJSON() method in the object, I wrote a CustomError class extending Error and tried to override the toJSON() method - but it does not work so I am guessing it is not using JSON.stringify(). – ybs May 24 '19 at 10:21
-
Maybe this can help: https://stackoverflow.com/questions/18391212/is-it-not-possible-to-stringify-an-error-using-json-stringify – Damien May 24 '19 at 10:23
-
That is a very insightful post, I will try some of the suggestions there. Thank you so much! :) – ybs May 27 '19 at 02:36