107

I have this simple a js file , which prints date continosly .

I am using Google Chrome Debugger tools (F12)

My question is , Is it possible to set a conditional break point in Google Chrome ??

In my code , i want to set a break point if the seconds value is equal to 50 ??

s = date.getSeconds();

This is the jsfiddle where my source is

(Not sure why its not working in jsfiddle)

Anyway my question is ,Is it possible to Set a Conditinal Break Point in chrome Debugger tools ??

1
  • 1
    +1 because I didn't know it was possible until went to check the documentation to answer this question. Thanks!
    – Theraot
    Commented Jan 30, 2013 at 7:28

3 Answers 3

151

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 Breakpoints at developers.google.com (Emphasis mine):

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.

7
  • Thanks , i did as you mentioned , edited break point and set if(s==50) but why its not stopping at that condition ??
    – Pawan
    Commented Jan 30, 2013 at 7:31
  • 2
    @PreethiJain write just the condition "s == 50" (without the quotes). By the way, I managed to make work the jsfiddle at: jsfiddle.net/nVpXN/6
    – Theraot
    Commented Jan 30, 2013 at 8:12
  • 7
    You don't even need to add a breakpoint to begin with. Just right-click on a line right away and click "Add conditional breakpoint...". Commented Sep 18, 2013 at 14:27
  • 2
    Man, it's 2017, and I'm learning new basic things about Chrome. #Awesomeness Commented Jan 25, 2017 at 14:50
  • 1
    This will just check the statement at this point in the code execution and then break if it is so, the same as a breakpoint within an if statement. I think the OP wanted to know if the debugger checks on each statement execution whether the condition is met and if it is the debugger breaks on this line. This behavior is much more useful since you don't have to play detective to find out when a variable does something unexpected. Commented Jan 11, 2018 at 16:36
29

Take a look at debugger statement. Basically it invokes any debugger tools available, and in Chrome it acts as if interpreter met a breakpoint.

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.

2
  • While this is in fact more in the spirit of the original way the original question was asked, and it's great information; I think the real question was about Chrome Tools, not ECMAscript. That being said; there is a caveat that should be added: remove all debugger calls in production code. (I'm pretty sure linting will throw an error if debugger is around, but it's worth calling out whenever the topic is raised). Commented Oct 18, 2014 at 22:32
  • 1
    you don't need the debugger statement, you can also have an empty statement inside the if and just add a breakpoint there. Commented Jan 11, 2018 at 16:32
8

You can set a conditional break point in Google Chrome, by following these steps:

1.right click the breakpoint where u want to stop,please chk on enter image description here

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 enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.