I'm writing a bug reporter for my app. When something goes wrong, the user fills out a form and describes the problem and this is sent to the server. As part of the data collected in this form, I'd like to include the last javascript error. Is there any way to do this?
I'm writing a bug reporter for my app. When something goes wrong, the user fills out a form and describes the problem and this is sent to the server. As part of the data collected in this form, I'd like to include the last javascript error. Is there any way to do this?
Share Improve this question asked Jun 25, 2012 at 12:19 JudsonJudson 2,3254 gold badges19 silver badges20 bronze badges 1- you could insert your whole code in a try/catch block, which would catch everything that failed and didn't get catched before. – K.. Commented Jun 25, 2012 at 12:21
3 Answers
Reset to default 8You could implement a function to capture errors by using window.onerror
(MDN documentation). That way the last error could be stored in window.localStorage
or wherever you want and you could retrieve it again, when the bug report is filled.
you can use window.onerror
window.onerror = function(error, url, line) {
//save errors here
};
You can assign a function to window.onerror
and store the error information from the arguments.