首页 > 其他 > 详细

前端异常日志记录

时间:2017-12-27 11:07:43      阅读:223      评论:0      收藏:0      [点我收藏+]

面对复杂的前端环境,进行前端异常日志记录很有必要,基于 window.onerror 实现:

// 基于window.onerror 收集前端错误信息
window.onerror = function (message, url, line) {
    if (!url) return;

    var msg = {
        ua: window.navigator.userAgent,
        message: message,
        url: url,
        line: line,
        page: window.location.href
    };

    new Image().src = ‘/Home/UiErrorLog?error=‘ + encodeURIComponent(JSON.stringify(msg)) + ‘&t=‘ + Math.random();
};

 

前端异常日志记录

原文:https://www.cnblogs.com/tangchun/p/8124409.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!