JavaScript : 如何在 Chrome 调试器工具中设置条件断点
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14598561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript :How to set a Conditional Break Point in Chrome debugger tools
提问by Pawan
I have this simple a js file , which prints date continosly .
我有一个简单的 js 文件,它连续打印日期。
I am using Google Chrome Debugger tools (F12)
我正在使用 Google Chrome 调试器工具 (F12)
My question is , Is it possible to set a conditional break point in Google Chrome ??
我的问题是,是否可以在 Google Chrome 中设置条件断点?
In my code , i want to set a break point if the seconds value is equal to 50 ??
在我的代码中,如果秒值等于 50,我想设置一个断点?
s = date.getSeconds();
Thisis the jsfiddle where my source is
这是我的来源所在的 jsfiddle
(Not sure why its not working in jsfiddle)
(不知道为什么它在 jsfiddle 中不起作用)
Anyway my question is ,Is it possible to Set a Conditinal Break Point in chrome Debugger tools ??
无论如何,我的问题是,是否可以在 chrome 调试器工具中设置条件断点?
回答by Theraot
Yes, it is possible.
对的,这是可能的。
Right click the marker of the breakpoint and select "Edit breakpoint..." there you can set the condition.
右键单击断点的标记并选择“编辑断点...”,您可以在那里设置条件。
From Chrome Developer Tools on Breakpointsat developers.google.com (Emphasis mine):
来自developer.google.com 上 Breakpoints上的Chrome 开发者工具(重点是我的):
Note: All the breakpoints you have set appear under Breakpoints in the right-hand sidebar. Clicking on the entry jumps to the highlighted line in the source file. Once you have a breakpoint set, right click on the blue tag breakpoint indicator to set a conditional statement for that breakpoint. Type an expression and the breakpoint will only pause only if the condition is true.
注意:您设置的所有断点都出现在右侧边栏中的断点下。单击条目会跳转到源文件中突出显示的行。设置断点后,右键单击蓝色标记断点指示器为该断点设置条件语句。输入一个表达式,只有当条件为真时,断点才会暂停。
回答by madfriend
Take a look at debuggerstatement. Basically it invokes any debugger tools available, and in Chrome it acts as if interpreter met a breakpoint.
看看debugger声明。基本上它调用任何可用的调试器工具,在 Chrome 中它就像解释器遇到断点一样。
Your code would be:
您的代码将是:
s = date.getSeconds();
if (s == 50) {
debugger;
}
From reference:
从参考:
[debugger] Invokes any available debugging functionality. If no debugging functionality is available, this statement has no effect.
[调试器] 调用任何可用的调试功能。如果没有可用的调试功能,则此语句无效。
回答by Deepan Raj
You can set a conditional break point in Google Chrome, by following these steps:
您可以按照以下步骤在 Google Chrome 中设置条件断点:
1.right click the breakpoint where u want to stop,please chk on

2.click "Add conditional breakpoint",one text will be appear,there u can add condition (the result will be 'true' if the condition satisfied ,else 'false'),
the breakpoint color will goto orange after the condition added,chk on

2.点击“添加条件断点”,会出现一个文本,在那里你可以添加条件(如果条件满足则结果为“真”,否则为“假”),条件添加后断点颜色变为橙色,继续

3.reload same page u can see the breakpoint will work if the condition is satisfied like


