Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reporting document-wide Javascript errors

Tags:

javascript

I need a way to log all Javascript errors that may happen in a document. Obviously, an Ajax call to the logging script is no problem, but the window.onerror event doesn't fire for errors inside functions or in some other cases where the browser or web developer toolbar would report an error.

I'd rather not use try/catch because there's a lot of code in many places and I'd like a document-wide solution that would report all Javascript errors.

Is this even possible? I see so many high profile sites with Javascript errors, so obviously many developers either don't care or don't know about the errors.

like image 549
DMIL Avatar asked Aug 25 '12 17:08

DMIL


2 Answers

First, sorry if I misunderstood your question and your qualifications.

Seems to be you are not familliar with DeveloperTools, and you better should be : ) For example, in Chrome you can open DeveloperTools by pressing F12 or Ctrl+Shift+J. All your previous and upcoming JavaScript errors will be displayed in the Console tab as they occur.

like image 167
gvlasov Avatar answered Nov 05 '22 08:11

gvlasov


It is actually possible to do some automatic try-catch insertion, in a way where you do not need to alter your code. It's not easy.

You could try my project Muscula, that logs JavaScript errors with try-catch insertion and falls back on onerror when it's not possible.

like image 37
Allan Ebdrup Avatar answered Nov 05 '22 10:11

Allan Ebdrup