I have an error code on my website that saves Javascript errors to a file, so later I can see if there are problems with my code in some browsers.
Sometimes I get an error message, for example the message: [object Event] url: undefined string: undefined , so I don’t know where the error is.
How to get additional information from the message when it is [object Event], so I can find out from which file and line number the error is sent.
window.onerror = error;
function error(message, url, line) {
}
I think something like this.
window.onerror = error;
function error(message, url, line) {
if (typeof message === 'object') {
message = message
+ ' + '
+ message.url
+ ' + '
+ message.lineno;
}
}
Trying, but I get Uncaught TypeError: Object # does not have a 'serialize' method
if (typeof message === 'object') {
message = JSON.serialize(message);
}
With JSON.stringify (message) I get Uncaught TypeError: convert circular structure to JSON
if (typeof message === 'object') {
message = JSON.stringify(message);
}