同样地,为了提出这问题,我试图将所有未处理的错误推到我们的遥测管道中,以便为工程师提供足够的信息来调试这些问题。
未处理异常处理程序的设置方式如下:
window.onerror = (event: Event | string, source?: string, lineno?: number, colno?: number, error?: Error) => {
const message: string = `src: ${source} line: ${lineno} col: ${colno}`;
logError(error || new Error(event.toString()), message);
};这似乎与文档是一致的。
在遥测开始流动后,我观察到:
error变量为空。lineno和colno也是null或0。我知道苏瑞金设置,它似乎是正确设置的。
我找不到任何严格的规则来描述在未处理的回调过程中提供了什么信息。我也在寻找反馈的方式,我们建立了未处理的回调和想法,为潜在的改进。
发布于 2021-04-11 01:49:04
<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {
const message: string = `src: ${source} line: ${lineno} col: ${colno}`;
logError(error || new Error(event.toString()), message);
// Send your telemetry info here
// Many browsers show alerts dialogs when errors are founded, so return true to suppress it.
return true;
};
</script>window.onerror什么时候开火?
事件将在下列任何一种
例如:
未明例外
编译错误
<script>{</script>
<script>for(;)</script>
<script>"oops</script>
setTimeout("{", 10);, it will attempt to compile the first argument as a script支持window.onerror的浏览器
https://stackoverflow.com/questions/66921749
复制相似问题