Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log javascript error

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?

like image 585
Sir Hally Avatar asked Apr 30 '12 11:04

Sir Hally


People also ask

What is log info in JavaScript?

log() The console. log() method outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.


1 Answers

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

like image 185
jp10k Avatar answered Oct 05 '22 22:10

jp10k