Display a noticeable error message when a JavaScript error occurs (for development use)

Whenever my JavaScript dies while registering an error message in the console, I'd like to report it immediately. The console is too invisible and often hidden or obscured by other windows.

Can I have something as important as the .NET dialog? For me, these JavaScript errors are completely fatal; they arent something that can be ignored, and I'd like to know about them before I spend time wondering why something is not happening.

Are there any addons that do this for Firefox or Chrome?

+7
source share
1 answer

I think the window.onerror handler will provide you with such functionality where you can notify erorr, url and line number,

Demo

Note. Make sure the window.onerror function is in a separate script tag, as shown below. Any error registered in the error console will be warned.

<script> window.onerror = function(msg, url, lineNo) { alert(msg + '\n' + url + '\n Line No: ' + lineNo); } </script> <script> document.getElementById('test').asd = 123; //will throw an error </script> <script> var s = [{]}; </script> <script> throw "Custom Error"; </script> 
+2
source

All Articles