前端异常监控window.onerror unhandledrejection

前端异常监控window.onerror unhandledrejection
捕获JS异常
window.onerror = function(message, source, lineno, colno, error) { … }
函数参数:

message:错误信息(字符串)。可用于HTML οnerrοr=""处理程序中的event。
source:发生错误的脚本URL(字符串)
lineno:发生错误的行号(数字)
colno:发生错误的列号(数字)
error:Error对象(对象)
若该函数返回true,则阻止执行默认事件处理函数。

window.addEventListener(‘error’, function(event) { … })

window.onerror = function (message, url, line, column, error) {
console.log(‘log—onerror::::’,message, url, line, column, error);
}
window.addEventListener(‘unhandledrejection’, event => {
console.log(event.reason);
});

window.addEventListener(‘unhandledrejection’, event =>
{
console.log(event.reason); // 打印"Unhandle Promise Error!"
});

window.addEventListener(‘rejectionhandled’, event => {
console.log(‘rejection handled’); // 1秒后打印"rejection handled"
});在这里插入代码片

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值