OptionalatLocation-level hooks (precise instrumentation points)
Allows attaching handlers to specific script locations.
Location in the form "line:column" Example: "164894:2"
Called when the breakpoint at this location is hit.
Runs in the current call frame (local scope access; use ctx.eval for this).
See "Execution model" for full details.
Must be declared as an object method, for example:
onHit(ctx) { ... }
Do not use arrow functions here.
OptionalonCalled at function entry.
Runs in the current call frame (local scope access; use ctx.eval for this).
See "Execution model" for full details.
Must be declared as an object method, for example:
onEnter(ctx) { ... }
Do not use arrow functions here.
OptionalonCalled at function leave / return breakpoint.
Runs in the current call frame (local scope access; use ctx.eval for this).
See "Execution model" for full details.
Must be declared as an object method, for example:
onLeave(ctx) { ... }
Do not use arrow functions here.
OptionalonCalled when a step is executed.
previousStep contains data captured from the leave step that requested
the follow.
Runs in the current call frame (local scope access; use ctx.eval for this).
See "Execution model" for full details.
Must be declared as an object method, for example:
onReturnFollowed(ctx, previousStep) { ... }
Do not use arrow functions here.
OptionalonCalled after followReturn() when a continuation is found.
previousStep contains data captured from the leave step that requested
the follow.
Runs in the current call frame (local scope access; use ctx.eval for this).
See "Execution model" for full details.
Must be declared as an object method, for example:
onStep(ctx, previousStep) { ... }
Do not use arrow functions here.
Execution model
Handlers run against the current call frame and have direct access to the local JavaScript scope, including locals, arguments, and closures.
Inline JavaScript executes immediately and follows standard JS semantics.
The
ctxmethods, instead, do not execute immediately: they schedule actions that are applied after the handler returns.Key differences:
ctx.setVariable(...)to modify bindings that cannot be changed via normal JS semantics (e.g.const).ctx.eval(...)to evaluate expressions in the frame and accessthis.Scope resolution for
ctx.setVariablefollows the CDP scope chain and only supportslocal,closure, andcatchscopes.