如何在不尝试捕获的情况下在全球捕获JavaScript错误
我有一个带有闪电网络组件的水疗中心。我的基本要求是捕获任何类型的JavaScript异常或错误并记录它们,而无需转到每个内部组件并包装中的每一块JS代码,请尝试catch 。
我尝试使用window.onerror
,但我没有收到正确的错误消息,它将消息以“脚本错误”提供。和第1号线,col no as 0 。看起来像其他来源策略的问题
可以提出其他有效的方法来捕获任何类型的JavaScript错误?
I have a SPA built with Lightning web components. My basic requirement is to catch any kind of JavaScript exceptions or errors and log them, without having to go to each inner component and wrap every piece of JS code in try catch.
I have tried using window.onerror
but I am not getting the proper error message with this, it gives message as "Script error." and line no, col no as 0. Looks like some issue with same origin policy
Can any of you please suggest some other effective way to catch any kind of JavaScript errors globally ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,这是唯一的方法。
您能提供您当前正在使用的代码吗?
我将按照我实施的方式包括这里。
输出:
错误:X未在行上定义:17完整消息:ReferenceError:X未定义
As far as I know, this is the only way.
Could you please provide the code that you are currently using?
I'll include here the way that i had implemented it.
Output:
Error: x is not defined on line: 17 full message: ReferenceError: x is not defined