JS error log capture

Recently in the process of doing the project, found that many JS error did not pay attention, I wanted to capture the wanted JS error, and then show us on a platform

Specific implementation code:

window.onerror = function(message, url, lineNumber,columnNo,error) {
    var data = {
        'message':message,
        'url':url,
        'error':error.stack
    };
    $.ajax({
        url:"/error/capture",
        type:'post',
        data:data,
        success:function(){

        }
    });
    return true;
};


Platform effect (you can visually see what the problem with a)

2.pic.jpg




Original Address: Capture JS error log
Tags: window    onerror    Capture    error   

Intelligent Recommendation

Reproduced in: https: //my.oschina.net/54php/blog/687099

Guess you like

Origin blog.csdn.net/weixin_33737134/article/details/91634642