码迷,mamicode.com
首页 > 其他好文 > 详细

前端异常日志记录

时间:2017-12-27 11:55:06      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:cat   cti   image   random   return   ima   href   str   math   

面对复杂的前端环境,进行前端异常日志记录很有必要,基于 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();
};

 

前端异常日志记录

标签:cat   cti   image   random   return   ima   href   str   math   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!