DMIL
DMIL

Reputation: 703

Reporting document-wide Javascript errors

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.

Upvotes: 8

Views: 142

Answers (2)

Allan Ebdrup
Allan Ebdrup

Reputation: 142

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.

Upvotes: 1

gvlasov
gvlasov

Reputation: 20035

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.

Upvotes: 1

Related Questions