Javascript “window.onerror”能否用于记录错误';s堆栈跟踪作为全局错误处理程序

Javascript “window.onerror”能否用于记录错误';s堆栈跟踪作为全局错误处理程序,javascript,debugging,error-handling,tracking,stack-trace,Javascript,Debugging,Error Handling,Tracking,Stack Trace,我试图为浏览器中发生的任何javascript错误创建一个全局错误处理程序,因此我在页面的标记中使用了以下代码: window.onerror = function(msg, url, line, col, error) { // Note that col & error are new to the HTML 5 spec and may not be // supported in every browser. It worked for me in Chrome

我试图为浏览器中发生的任何javascript错误创建一个全局错误处理程序,因此我在页面的
标记中使用了以下代码:

window.onerror = function(msg, url, line, col, error) {
    // Note that col & error are new to the HTML 5 spec and may not be
    // supported in every browser.  It worked for me in Chrome.
    var extra = !col ? '' : '\ncolumn: ' + col;
    extra += !error ? '' : '\nerror: ' + error;

    // You can view the information in an alert to see things working like this:
    alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);

    // TODO: Report this error via ajax so you can keep track
    //       of what pages have JS issues

    var suppressErrorAlert = true;
    // If you return true, then error alerts (like in older versions of
    // Internet Explorer) will be suppressed.
    return suppressErrorAlert;
};
但由于我使用CDN缩小javascript文件,我总是将这些无用的值传递给函数:

msg:脚本错误

url:“”

行:0

col:0

错误:null

(结果来自Ubuntu上的Chrome版本
43.0.2357.125(64位)


那么,我是否可以从
窗口中获取错误的堆栈跟踪(甚至任何关于它的信息)。onerror

在没有CDN(缩小)的情况下是否可以工作?如果是,那么可能是缩小过程与变量名混合在一起。我尝试过禁用缩小,但没有任何更改,我总是得到相同的结果。请参阅,但大多数情况下,它会给我一个
null
错误,所以我不能用它来按照你提到的答案得到堆栈这个@AbdelHady的任何解决方案?