如何在chrome中访问开发工具中的js-file / lib时设置断点? [英] How to set a breakpoint on access a js-file/lib in dev tools in chrome?

查看:99
本文介绍了如何在chrome中访问开发工具中的js-file / lib时设置断点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调试时是否可以获得断点,以便每次访问某个类时停止,否则它会正常运行。

当人们不想停留在jquery函数或其他常用的libs函数上,而是想停留在特定的js文件上时,这是非常常见的用例,但不知道可能会触发一个错误,所以不需要明确地在js文件的每一行中设置一个断点来捕获该文件上的所有访问。 Chrome DevTools是否有用于该调试功能的选项?



更新:



或者还有另一种方法通过忽略整个库如jquery来获得类似的功能,如果应该有一个断点,以便只有其他文件将被调试器处理?这仍然不是最好的解决方案,但无论如何可以节省很多时间。

Update2:



第二种方法描述为此处,但我拥有Chrome 26,但不幸在接下来的一两个月内无法更新它,所以此功能现在不适用于我的浏览器。 解决方案

执行此操作的唯一方法是在文件中添加调试器; 语句。在文件的开头和每个函数体的开始处应该就足够了。



参考: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/debugger


Is it possible to get a breakpoint when debugging, so that it stops each time when the certain class is accessed, otherwise it runs normally.

It's very common use case when one don't want to stop on jquery functions or other common libs functions, and want rather to stay on a specific js-file, but has no idea of what there could fire a bug, so one don't want explicitly to set a breakpoint on every line in the js file to catch all accesses on that file. Are there any options for Chrome DevTools for that debugging functionality?

Update:

Or maybe there is another way to get the similar functionality by ignoring whole libraries such as jquery, if there should be a breakpoint, so that only other files will be handled with debugger? That would be still not the best solution for the case, but anyway saves much time.

Update2:

the second approach is described here, but I have Chrome 26, and unfortunately cannot update it in the next one-two months, so this feature doesn't work for my browser now.

解决方案

The only way to do it would be to sprinkle debugger; statements inside your file. At the begining of the file and at the begining of every function body should be enough.

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger

这篇关于如何在chrome中访问开发工具中的js-file / lib时设置断点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆