brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Add a condition to a Chrome DevTools breakpoint

Devtools
~/tips/tip-devtools-conditional-breakpoint

user.id === 42

Pauses the debugger on a line only when your condition is true.

A breakpoint inside a loop is annoying. It stops on every pass, and the one you care about is number 847. A condition fixes that.

In the Sources panel, right-click the line number and choose the option to add a conditional breakpoint. Type an expression in the box that appears, for example:

user.id === 42

Press Enter. The line gets an orange marker with a question mark, and the debugger only pauses there when the expression is true.

The same menu has a related entry, Never pause here. It adds a breakpoint with a condition of false, which mutes pauses from debugger statements and most other breakpoint types on that line. It’s handy when a library keeps stopping you in a place you don’t care about.

A caveat: the condition runs every time the line executes, so a heavy expression in a hot loop slows the page down. If you only want to print a value without stopping, use a logpoint instead.

The condition can use anything in scope at that line, including local variables and function arguments. You can edit or remove it later from the Breakpoints list in the Sources sidebar, so you don’t have to hunt for the line again.

Further reading: Breakpoints in Chrome DevTools

More Devtools tips Clear site data for one site from Chrome DevTools $x(path [, startNode]) @media (prefers-color-scheme: dark) { queryObjects(Promise) inspect(document.querySelector('footer')) All Devtools tips (22) All topics

Link