Is it possible to start debugging when a watch expression matches certain value or values?

3,129 views
Skip to first unread message

Sebastián Balay

unread,
Apr 8, 2016, 12:05:39 PM4/8/16
to Google Chrome Developer Tools
Hi there, I'm debugging a long while loop and right now I put a breakpoint inside the while loop to check the variable values. But I'm not interested in those values during the whole loop, I just want to check that when one of those variables matches certain value. Is it possible to accomplish that using the watch expressions?.

I'll add a quick and simple example to try to make my point clear:
while (true) {
  var a = getValue('a');
  var b = getValue('b'); 
  var c = getValue('c');
  var d = getValue('d'); 
  doSomething(a, b, c, d); 
}

So, I only want the execution to stop when c === 3. Debugging the entire while loop and check the variable value until it is 3 takes a lot of time.

This code is in production, so I can not change it to do something like: 
if (c === 3) debugger

Thanks! 

PhistucK

unread,
Apr 8, 2016, 12:08:56 PM4/8/16
to Google Chrome Developer Tools
Not through watch expressions, but using conditional breakpoints -
Set a breakpoint, right click on it and select "Edit breakpoint...". Type an expression (c === 3) and press Enter. It will break only when the expression is truthy.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-develo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-chrome-developer-tools/657aaaa6-705c-4e3d-8d7e-155999d876f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Watts

unread,
Jan 17, 2018, 7:40:08 AM1/17/18
to Google Chrome Developer Tools
You might as well set a breakpoint within an if statement, since this would result in the same behavior. Its a shame the Chrome team didn't implement a conditional watch break imo


On Friday, 8 April 2016 18:08:56 UTC+2, PhistucK wrote:
Not through watch expressions, but using conditional breakpoints -
Set a breakpoint, right click on it and select "Edit breakpoint...". Type an expression (c === 3) and press Enter. It will break only when the expression is truthy.


PhistucK

On Fri, Apr 8, 2016 at 4:53 PM, Sebastián Balay <sebasti...@wolox.com.ar> wrote:
Hi there, I'm debugging a long while loop and right now I put a breakpoint inside the while loop to check the variable values. But I'm not interested in those values during the whole loop, I just want to check that when one of those variables matches certain value. Is it possible to accomplish that using the watch expressions?.

I'll add a quick and simple example to try to make my point clear:
while (true) {
  var a = getValue('a');
  var b = getValue('b'); 
  var c = getValue('c');
  var d = getValue('d'); 
  doSomething(a, b, c, d); 
}

So, I only want the execution to stop when c === 3. Debugging the entire while loop and check the variable value until it is 3 takes a lot of time.

This code is in production, so I can not change it to do something like: 
if (c === 3) debugger

Thanks! 

--
You received this message because you are subscribed to the Google Groups "Google Chrome Developer Tools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-chrome-developer-tools+unsub...@googlegroups.com.

PhistucK

unread,
Jan 17, 2018, 7:44:07 AM1/17/18
to Google Chrome Developer Tools
Does adding a watch expression such as -
condition && (function() { debugger; }())
Work?


PhistucK

Kayce Basques

unread,
Jan 22, 2018, 3:22:18 PM1/22/18
to Google Chrome Developer Tools
Cool idea, Phistuck!

Kayce Basques

unread,
Jan 22, 2018, 3:32:57 PM1/22/18
to Google Chrome Developer Tools
Doesn't seem to be working though... I feel like we should be able to hack something together...

Victor Combal-Weiss

unread,
Jun 13, 2019, 12:52:04 PM6/13/19
to Chrome DevTools
Reply all
Reply to author
Forward
0 new messages