Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript :How to set a Conditional Break Point in Chrome debugger tools

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 ??

like image 483
Pawan Avatar asked Jan 30 '13 07:01

Pawan


People also ask

How do I apply a conditional breakpoint in Chrome?

Add a conditional breakpoint by right clicking a line number, selecting Add Conditional Breakpoint , and entering an expression. Note: Because the conditional breakpoint simply evaluates an expression, you can add useful logging statements within the expression.


2 Answers

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.

like image 45
madfriend Avatar answered Oct 12 '22 09:10

madfriend


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.

like image 127
Theraot Avatar answered Oct 12 '22 07:10

Theraot