是否可以检测到IE8调试器已附加
我的应用程序中有一些代码将 function.apply 和 function.call 包装在 try/catch 块中。它可以很方便地捕获错误并使用arguments.caller 构建伪堆栈,但它会对 IE 的调试器造成严重破坏。
我可以使用 url 参数关闭包装,但如果附加了调试器,我想自动关闭它。我找不到检测调试器的方法。有什么想法吗?
I have some code in my application that wraps function.apply and function.call in try/catch blocks. It's handy for catching errors and building up a pseudo-stack using arguments.caller but it plays havoc with IE's debugger.
I can turn off the wrapping with a url parameter but I'd like to turn it off automatically if the debugger is attached. I can't find a way to detect the debugger. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定是否适用于 IE8,但您可以通过检查来检测调试器是否在 IE9/IE10/IE11 中运行:
例如,请参阅 http: //jsbin.com/IJOwuje/5
但是,在 IE9/IE10 中,对于仅运行调试器一次的窗口,即使调试器现在已关闭,此值也会设置为 true。
此外,在 IE11 中,各种 window.__BROWSERTOOLS* 键似乎仅根据打开或使用的调试器选项卡而出现,因此对于检查调试框架是否打开而言不是 100% 可靠...
Not sure for IE8, but you can detect if the debugger is running in IE9/IE10/IE11 by checking:
e.g. see http://jsbin.com/IJOwuje/5
However, in IE9/IE10 this is set to true for a window that has run the debugger just once, even if the debugger now closed.
Also in IE11 the various window.__BROWSERTOOLS* keys seem to only appear depending upon which debugger tab is open or used, so not 100% reliable for checking if the debugging frame is open...
这不是你想要的答案,但我过去通过使用一小部分加载器 JS 来处理这个问题,首先检查 URL 中的哈希值(如果有)是否有秘密代码,例如:
mysite.com /#mXVa
因此,加载器会检查,如果 location.hash == 'mXVa',我的加载器会加载页面上所有脚本的调试版本(没有 try/catch 等),而不是缩小的、会出错的版本。
This isn't the answer you wanted, but I've handled this in the past by having a small bit of loader JS that begins by checking the hash, if any, in the URL, for a secret code, like:
mysite.com/#mXVa
So the loader checks and if location.hash == 'mXVa', my loader loads the debug versions of all the scripts on the page (no try/catch, etc) rather than the minified, error-eating variety.