改进我们的 javascript 错误报告
所以现在我们有一些通用代码来报告来自我们的代码或第三方代码的错误。我们的项目是 iOS 的 JQM/Phonegap 项目。发生的事情是我们几乎总是遇到相同的无用错误... TypeError: 'undefined' is not a function... 没有行号或其他有用的信息。有没有办法可以更改代码以获取未定义的内容或它在哪里?
window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
//Handle errors not in a jquery event handler
//DebugMessage(errorMSg + " "+ url + " " + lineNumber);
var ex = new Error(errorMsg, url, lineNumber);
HandleError(ex, "window.onerror");
//HandleError sends the error object to
//a webservice to log the error.
return true;
};
任何有关调试 javascript 错误的提示也会有所帮助。
So right now we have some generic code to report errors either from our code or third party code. Our project is a JQM/Phonegap project for iOS. What is happening is we pretty much always get the same useless error... TypeError: 'undefined' is not a function... with no line number or other helpful information. Is there a way I could change the code to maybe get WHAT is undefined or WHERE it is?
window.onerror = function myErrorHandler(errorMsg, url, lineNumber) {
//Handle errors not in a jquery event handler
//DebugMessage(errorMSg + " "+ url + " " + lineNumber);
var ex = new Error(errorMsg, url, lineNumber);
HandleError(ex, "window.onerror");
//HandleError sends the error object to
//a webservice to log the error.
return true;
};
Any tips on debugging javascript errors would help as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
近几个月来,浏览器扩展了
window.onerror
签名以提供更多信息。这应该会给您提供更多信息。但仍有一些事情需要更好的背景。您应该检查一些第三方工具,例如 TrackJS,它会自动为您提供此信息,以及有关错误如何发生的额外信息。
免责声明:我是 TrackJS 的原作者之一,所以我知道很多关于 JavaScript 错误的知识:)
In recent months, browsers have extended the signature of
window.onerror
to provide more information.This should give you a lot more information. But there are still things where you need better context. You should check out some third-party tools for this like TrackJS that automatically give you this, plus extra information on how the error occurred.
Disclaimer: I am one of the original authors of TrackJS, so I know a bunch about JavaScript errors :)
您听说过瑞波币吗?它是一款 Chrome 移动模拟器,专为测试 PhoneGap 应用程序而设计。
这可能会帮助您在设备上进行调试之前发现错误。
Have you heard of Ripple? It is a mobile emulator for Chrome designed for testing PhoneGap applications.
That might help you find your errors before you debug on the devices.