For automated testing reasons I want to detect if the browser has encountered JavaScript errors for a page. The type of things that would cause the red numbers in the bottom right in Firebug or yellow warning icon in the Internet Explorer status bar. These JS errors could come from any one of a large numbers of scripts.
How in JavaScript can I detect these browser errors? Cross browser solutions prefered, but hey, I'll take anything!
As a bonus it would also be great to know the script that caused the error.
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.
In Chrome, navigate to Tools > Advanced > Error Console. The error console will open. Select JavaScript and Errors from the two drop downs. To find the error location, expand one of the errors.
To show the menu bar, click Settings > Show Menu Bar. The menu bar can be removed at any point by clicking Settings > Hide Menu Bar. To use the console, open Safari and in the menu bar choose Develop > Show Error Console.
window.onerror handler is the answer. Read this - http://www.javascriptkit.com/javatutors/error.shtml
To get more information about the script that caused the error, read this - http://www.javascriptkit.com/javatutors/error3.shtml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With