Search code examples
javascriptgoogle-chromegoogle-chrome-devtools

Conditional Logpoint in Chrome Devtools


If there a way to do a Conditional Logpoint in Chrome Devtools?

  • I KNOW how to add a logpoint or a conditional breakpoint;
  • I DON'T KNOW if is there a way to add a conditional logpoint (a logpoint logging only when a specific condition is meet).

Solution

  • There's no way to add a conditional logpoint in Chrome Devtools.

    The workaround is to add a non-breaking conditional breakpoint with console.log:

    foo.bar===123 && console.log('foo!', foo)
    

    The result of this expression is always falsy: either false (for the condition) or undefined (for console.log) so the breakpoint doesn't trigger and only prints the message on condition.