Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Last Javascript Error

Tags:

javascript

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?

like image 344
Judson Avatar asked Jun 25 '12 12:06

Judson


People also ask

How do I get JavaScript errors?

Right-click anywhere in the webpage and then select Inspect. Or, press F12 . DevTools opens next to the webpage. In the top right of DevTools, the Open Console to view errors button displays an error about the webpage.

How do I fix JavaScript console error?

Go to the screen where you are experiencing the error. In Chrome, navigate to View > Developer > JavaScript Console or More Tools > JavaScript Console or press Ctrl + Shift + J. The error console will open. If you don't see any errors try reloading the page.

What is error captureStackTrace?

Error.captureStackTrace() A non-standard V8 function that creates the stack property on an Error instance.

Why do I have a JavaScript error?

There are two types of JavaScript error: Syntax Error: Occurs when there is a mistake in the way the code is written; for example, a typo or missing character. Runtime error: Occurs when the script is unable to complete its instructions; for example, if a specified object cannot be found.


1 Answers

You could implement a function to capture errors by using window.onerror (MDN docu). That way the last error could be stored in window.localStorage or wherever you want and you could retrieve it again, when the bugreport is filled.

like image 115
Sirko Avatar answered Oct 19 '22 22:10

Sirko