您的位置:首页 > Web前端

前端错误信息收集(errorEruda)解析

2017-08-24 22:38 183 查看
github:errorEruda移动调试,bug收集工具

img[src],script[src],link[href]请求链接错误监控:

document.addEventListener("error", function (e) {
let error = '';
if (e.target.localName == 'link') {
error = e.target.href;
}
else {
error = e.target.src;
}
}, true);
通过js委托事件实现,监控所有的外链error错误信息;(注:该方法应该第一个执行)

监控js错误:

window.onerror = function (msg, url, line, col, error) {
console.log(error.stack)
};
一般js错误会通过window.onerror进行触发,error.stack包含了具体错误信息

监控XHR接口请求:

var open = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function (method, url) {
this.addEventListener('readystatechange', function () {
if (this.readyState == 4 && this.status != 200) {
//url请求链接完整,method请求方式,status:http状态码
}
})
open.apply(this, arguments);
}

这样一个简单的错误收集就完成了

在移动端真机测试:

demo:http://jqvue.com/demo/errorEruda/index.html

点击按钮6次即可调起模拟控制台

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐