简体   繁体   English

从Chrome开发者工具暂停警报框上的JavaScript执行

[英]Pause JavaScript execution on alert box from Chrome Developer Tools

I am debugging a complex webpage which is throwing an alert box on clicking a particular element. 我正在调试一个复杂的网页,该网页在单击特定元素时会引发警报框。 I want to locate the code which is causing this. 我想找到导致这种情况的代码。 It is difficult to search my codebase by looking for message shown in alert box as it is very vague and dynamic. 通过查找警报框中显示的消息很难搜索我的代码库,因为它非常模糊且动态。 Is it possible to pause JS execution on alert in debugger from the Chrome dev tools or any other debugger? 是否可以通过Chrome开发者工具或任何其他调试器在调试器中以警报方式暂停JS执行? (In a similar way like Chrome allows to pause JS execution on events like click, etc). (以类似的方式,例如Chrome允许在诸如click等事件上暂停JS执行)。

I already tried reaching the code by pausing on click event, but there are too many JS files to step through and the code is minified and complex. 我已经尝试通过暂停click事件来到达代码,但是要执行的JS文件太多,因此代码精简而复杂。

Thanks. 谢谢。

Take a look at this snippet 看看这个片段

 (function() { var _old_alert = window.alert; window.alert = function() { //breakpoint _old_alert.apply(window,arguments); }; })(); alert('hey'); alert('you'); alert('there'); 

You can try to override alert function, put a breakpoint and take a look at Call Stack to figure out where it comes from. 您可以尝试覆盖警报功能,放置断点并查看“调用堆栈”以找出其来源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM