Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all errors shown in the Chrome console JavaScript errors?

Google Chrome, Firefox, and other browsers have a developer console to show errors. Are these the same errors that are triggered by window.onerror?

like image 596
Ashwani Avatar asked Oct 03 '22 20:10

Ashwani


1 Answers

The Chrome developer console is a superset of the information that is made available to window.onerror. The developer console will show JavaScript errors, security errors, CSS errors, deprecation warnings, and many other internal faults in rendering the document.

window.onerror is only unhandled global JavaScript errors.

Another important difference is that the Developer Console will show the real, original error information whereas window.onerror might obfuscate the error message to "Script Error" if the error violates the Same Origin Policy.

The Chrome Developer console is a better set of information during development. Once you release your app, you should continue to trap and record errors from window.onerror so that you can be sure to know when your users run into problems. The browser landscape is constantly changing, and you should know when something starts breaking. There are some good tools to help you do this automatically, like TrackJS. Disclosure: I am one of the founding developers of TrackJS, so I've fixed a lot of js errors :)

like image 146
Todd Gardner Avatar answered Oct 05 '22 11:10

Todd Gardner