16

I want to log all JS errors in my project during the beta-testing time. Now I do it in the following way:

window.onerror = myErrHandler;

function myErrHandler(message, url, line)
{
    $.ajax({
        cache: false,
        type: "post",
        data: {error:message, url:url, line:line, brouser:navigator.userAgent},
        url: "/Home/LogJavaScript/",
        async: true
    });
    return true;
}

But this way couldn't help to get any information about call stack. So, information about errors inside jQuery or any other outer scripts couldn't help a lot.

Is there any way to improve such logging?

Sir Hally
  • 2,318
  • 3
  • 31
  • 48
  • 3
    :this link would help http://stackoverflow.com/questions/147891/javascript-exception-stack-trace – dhinesh Apr 30 '12 at 11:41

5 Answers5

10

Take a look at stacktrace.js, that should do the trick.

jp10k
  • 374
  • 2
  • 8
  • Are there any examples where you can store the stacktrace to some datastore (ajax)? – Max Alexander Jan 10 '13 at 19:27
  • 2
    `stacktrace.js` will not help you with `window.onerror`. It gives you the stack of the onerror, not the actual error. If you want the stack, you must try/catch. https://github.com/eriwen/javascript-stacktrace/issues/26#issuecomment-2410664 – bendytree Apr 30 '13 at 21:20
0

ExceptionHub is another good drop-in (paid) service that logs JS errors, with stack traces, groups them, etc.

thaddeusmt
  • 15,410
  • 9
  • 67
  • 67
0

You could also try https://www.atatus.com/. Along with stack traces, Atatus captures all of your visitors' actions in one clear picture which lead to the error. Apart from JavaScript error tracking, Atatus also provides Real User Monitoring, AJAX(XHR) Monitoring and Transactions monitoring.

Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
-1

[EDIT]: This project was sold long ago and is a paid service now.

You could also take a look at my project called Muscula that logs your JavaScript errors It's easy to set up, just add a script snippet and you're logging. It's free :-)

Allan Ebdrup
  • 142
  • 5
-1

Take a look at JsLog.me service. It catches errors and collects whole client logs which can be helpful for recovering bug reproduction while beta-testing. Also it works for hybrid (PhoneGap/Cordova) applications.

Alexey Petushkov
  • 2,010
  • 19
  • 19