Overview
The Debugger class provides programmatic access to Chrome DevTools debugging features via CDP. You can:- Set breakpoints in browser scripts by file URL and line number
- Pause execution and inspect local variables
- Step through code (step over, into, out)
- Evaluate expressions in the current scope
- Access call stacks and source code context
- Blackbox framework code to focus on your own scripts
Quick Start
Creating a Debugger
enable() method:
- Enables the Debugger and Runtime CDP domains
- Resumes execution if the target was started with
--inspect-brk - Waits for scripts to be parsed and ready
Breakpoints
Setting Breakpoints
file- Script URL (use the URL fromlistScripts())line- Line number (1-based)condition- Optional JavaScript expression; only pause when it evaluates to true
Listing Breakpoints
Removing Breakpoints
Inspecting Execution State
Check if Paused
Get Current Location
When paused at a breakpoint, get execution location with call stack and source context:url- Script URLlineNumber- Current line (1-based)columnNumber- Current columncallstack- Array of stack frames with function names, URLs, and positionssourceContext- Surrounding source code (±3 lines) with current line marked
Inspect Variables
evaluate() for full control.
Evaluate Expressions
- When paused: evaluates in the current stack frame scope (access to local variables)
- Otherwise: evaluates in global scope
- Values are not truncated
Inspect Global Variables
Stepping Through Code
All stepping methods require the debugger to be paused:Exception Handling
Configure the debugger to pause on exceptions:Finding Scripts
List Available Scripts
Blackboxing Scripts
Blackbox scripts to skip framework/library code when stepping:- Hidden from the call stack
- Stepped over automatically when stepping through code
- Not paused at when stepping
Managing Blackbox Patterns
XHR/Fetch Breakpoints
Pause when specific network requests are made:Complete Example
Use Cases
Debugging production issues:- Set breakpoints in minified code to understand execution flow
- Inspect variable values at specific points
- Pause on exceptions to see where errors occur
- Step through library functions to see how they work
- Inspect internal state of frameworks
- Blackbox known-good code to focus on problem areas
- Verify code execution paths
- Extract runtime state for assertions
- Debug flaky tests by inspecting variables at failure points