I'm trying to send an error event object from the content script:
catch (error) {
chrome.runtime.sendMessage(sender.id, error);
}
to the background script:
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
console.log(msg)
});
in order to log it there with the full stack trace and all the relevant data,
but it always arrives as undefined
.
I tried to JSON.Stringify
the error and send it in an object, but it arrives as an empty object.
From https://developer.chrome.com/docs/extensions/reference/runtime/:
If I'm sending error.message
and error.stack
separately, creating a new Error
object works fine:
let error = new Error();
error.message = msg.message
error.stack = msg.stack;
How can I send the error object and receive it as-is?