Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monitoring js errors

Tags:

javascript

I am interested in monitoring javascript errors and logging the errors with the callstack.

I am not interested to wrap everything in try-catch blocks.

According to this article http://blog.errorception.com/2011/12/call-stacks-in-ie.html it's possible inside window.onerror "recursively call .caller for each function in the stack to know the previous function in the stack"

I tried to get the callstack:

window.onerror = function(errorMsg, url, lineNumber)
{
    var stk = [], clr = arguments.callee.caller;
    while(clr)
    {
        stk.push("" + clr);
        clr = clr.caller;
    }
    // Logging stk
    send_callstack_to_log(stk);
}

but only one step is possible even if the callstack was much longer:

(function()
{
function inside() {it.will.be.exception;};
function middle() {inside()};
function outside() {middle()}
outside();
})();

One step isn't interesting because onerror arguments give me even more information about it.

Yes, I tried it with IE according the article I mentioned above.

Remark: I also tried to open an account on "ERRORCAEPTION" to gather error log. I tested it with IE and "ERRORCAEPTION" recognize that the errors are coming from IE, but I can't find any callstack information in the log I've got there.

like image 605
Alexander Avatar asked Mar 17 '13 12:03

Alexander


3 Answers

Unfortunately this log will not always be available, it lacks line numbers, you can not really rely on it.

Try https://qbaka.com

Qbaka automatically overload bunch of JavaScript functions like addEventListener, setTimeout, XMLHtppRequest, etc so that errors happening in callbacks are automatically wrapped with try-catch and you will get stacktraces without any code modification.

like image 131
Daniil Avatar answered Nov 10 '22 16:11

Daniil


Take a look here: https://github.com/eriwen/javascript-stacktrace

That's the one I use on Muscula, a service like trackjs.

like image 34
Allan Ebdrup Avatar answered Nov 10 '22 16:11

Allan Ebdrup


You can try atatus which provides javascript contextual error tracking: https://www.atatus.com/

like image 24
Fizer Khan Avatar answered Nov 10 '22 18:11

Fizer Khan