Debugger#
Debugger domain exposes JavaScript debugging capabilities. It allows setting and removing breakpoints, stepping through execution, exploring stack traces, etc.
Types#
Generally, you do not need to instantiate CDP types yourself. Instead, the API creates objects for you as return values from commands, and then you can use those objects as arguments to other commands.
- class LocationRange(script_id, start, end)[source]#
Location range within one script.
-
start:
ScriptPosition#
-
end:
ScriptPosition#
-
start:
- class CallFrame(call_frame_id, function_name, location, url, scope_chain, this, function_location=None, return_value=None, can_be_restarted=None)[source]#
JavaScript call frame. Array of call frames form the call stack.
-
call_frame_id:
CallFrameId# Call frame identifier. This identifier is only valid while the virtual machine is paused.
-
url:
str# JavaScript script name or url. Deprecated in favor of using the
location.scriptIdto resolve the URL via a previously sentDebugger.scriptParsedevent.
-
this:
RemoteObject# thisobject for this call frame.
-
return_value:
Optional[RemoteObject] = None# The value being returned, if the function is at return point.
-
call_frame_id:
- class Scope(type_, object_, name=None, start_location=None, end_location=None)[source]#
Scope description.
-
object_:
RemoteObject# Object representing the scope. For
globalandwithscopes it represents the actual object; for the rest of the scopes, it is artificial transient object enumerating scope variables as its properties.
-
object_:
- class ScriptLanguage(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Enum of possible script languages.
- JAVA_SCRIPT = 'JavaScript'#
- WEB_ASSEMBLY = 'WebAssembly'#
Commands#
Each command is a generator function. The return
type Generator[x, y, z] indicates that the generator
yields arguments of type x, it must be resumed with
an argument of type y, and it returns type z. In
this library, types x and y are the same for all
commands, and z is the return type you should pay attention
to. For more information, see
Getting Started: Commands.
- continue_to_location(location, target_call_frames=None)[source]#
Continues execution until specific location is reached.
- disassemble_wasm_module(script_id)[source]#
EXPERIMENTAL
- Parameters:
script_id (
ScriptId) – Id of the script to disassemble- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[Optional[str],int,List[int],WasmDisassemblyChunk]]- Returns:
A tuple with the following items:
streamId - (Optional) For large modules, return a stream from which additional chunks of disassembly can be read successively.
totalNumberOfLines - The total number of lines in the disassembly text.
functionBodyOffsets - The offsets of all function bodies, in the format [start1, end1, start2, end2, …] where all ends are exclusive.
chunk - The first chunk of disassembly.
- enable(max_scripts_cache_size=None)[source]#
Enables debugger for the given page. Clients should not assume that the debugging has been enabled until the result for this command is received.
- evaluate_on_call_frame(call_frame_id, expression, object_group=None, include_command_line_api=None, silent=None, return_by_value=None, generate_preview=None, throw_on_side_effect=None, timeout=None)[source]#
Evaluates expression on a given call frame.
- Parameters:
call_frame_id (
CallFrameId) – Call frame identifier to evaluate on.expression (
str) – Expression to evaluate.object_group (
Optional[str]) – (Optional) String object group name to put result into (allows rapid releasing resulting object handles using`releaseObjectGroup``).include_command_line_api (
Optional[bool]) – (Optional) Specifies whether command line API should be available to the evaluated expression, defaults to false.silent (
Optional[bool]) – (Optional) In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides``setPauseOnException`state.return_by_value (
Optional[bool]) – (Optional) Whether the result is expected to be a JSON object that should be sent by value.generate_preview (
Optional[bool]) – (EXPERIMENTAL) (Optional) Whether preview should be generated for the result.throw_on_side_effect (
Optional[bool]) – (Optional) Whether to throw an exception if side effect cannot be ruled out during evaluation.timeout (
Optional[TimeDelta]) – (EXPERIMENTAL) (Optional) Terminate execution after timing out (number of milliseconds).
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[RemoteObject,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Object wrapper for the evaluation result.
exceptionDetails - (Optional) Exception details.
- get_possible_breakpoints(start, end=None, restrict_to_function=None)[source]#
Returns possible locations for breakpoint. scriptId in start and end range locations should be the same.
- Parameters:
start (
Location) – Start of range to search possible breakpoint locations in.end (
Optional[Location]) – (Optional) End of range to search possible breakpoint locations in (excluding). When not specified, end of scripts is used as end of range.restrict_to_function (
Optional[bool]) – (Optional) Only consider locations which are in the same (non-nested) function as start.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],List[BreakLocation]]- Returns:
List of the possible breakpoint locations.
- get_script_source(script_id)[source]#
Returns source for the script with given id.
- Parameters:
script_id (
ScriptId) – Id of the script to get source for.- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[str,Optional[str]]]- Returns:
A tuple with the following items:
scriptSource - Script source (empty in case of Wasm bytecode).
bytecode - (Optional) Wasm bytecode. (Encoded as a base64 string when passed over JSON)
- get_stack_trace(stack_trace_id)[source]#
Returns stack trace with given
stackTraceId.EXPERIMENTAL
- Parameters:
stack_trace_id (
StackTraceId) –- Return type:
- Returns:
- get_wasm_bytecode(script_id)[source]#
This command is deprecated. Use getScriptSource instead.
Deprecated since version 1.3.
- Parameters:
script_id (
ScriptId) – Id of the Wasm script to get source for.- Return type:
- Returns:
Script source. (Encoded as a base64 string when passed over JSON)
Deprecated since version 1.3.
- next_wasm_disassembly_chunk(stream_id)[source]#
Disassemble the next chunk of lines for the module corresponding to the stream. If disassembly is complete, this API will invalidate the streamId and return an empty chunk. Any subsequent calls for the now invalid stream will return errors.
EXPERIMENTAL
- pause_on_async_call(parent_stack_trace_id)[source]#
Deprecated since version 1.3.
EXPERIMENTAL
- Parameters:
parent_stack_trace_id (
StackTraceId) – Debugger will pause when async call with given stack trace is started.- Return type:
Deprecated since version 1.3.
- restart_frame(call_frame_id, mode=None)[source]#
Restarts particular call frame from the beginning. The old, deprecated behavior of
restartFrameis to stay paused and allow further CDP commands after a restart was scheduled. This can cause problems with restarting, so we now continue execution immediatly after it has been scheduled until we reach the beginning of the restarted frame.To stay back-wards compatible,
restartFramenow expects amodeparameter to be present. If themodeparameter is missing,restartFrameerrors out.The various return values are deprecated and
callFramesis always empty. Use the call frames from theDebugger#pausedevents instead, that fires once V8 pauses at the beginning of the restarted function.- Parameters:
call_frame_id (
CallFrameId) – Call frame identifier to evaluate on.mode (
Optional[str]) – (EXPERIMENTAL) (Optional) The`mode``parameter must be present and set to ‘StepInto’, otherwise``restartFrame`will error out.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[List[CallFrame],Optional[StackTrace],Optional[StackTraceId]]]- Returns:
A tuple with the following items:
callFrames - New stack trace.
asyncStackTrace - (Optional) Async stack trace, if any.
asyncStackTraceId - (Optional) Async stack trace, if any.
- resume(terminate_on_resume=None)[source]#
Resumes JavaScript execution.
- Parameters:
terminate_on_resume (
Optional[bool]) – (Optional) Set to true to terminate execution upon resuming execution. In contrast to Runtime.terminateExecution, this will allows to execute further JavaScript (i.e. via evaluation) until execution of the paused code is actually resumed, at which point termination is triggered. If execution is currently not paused, this parameter has no effect.- Return type:
- search_in_content(script_id, query, case_sensitive=None, is_regex=None)[source]#
Searches for given string in script content.
- set_blackbox_execution_contexts(unique_ids)[source]#
Replace previous blackbox execution contexts with passed ones. Forces backend to skip stepping/pausing in scripts in these execution contexts. VM will try to leave blackboxed script by performing ‘step in’ several times, finally resorting to ‘step out’ if unsuccessful.
EXPERIMENTAL
- set_blackbox_patterns(patterns, skip_anonymous=None)[source]#
Replace previous blackbox patterns with passed ones. Forces backend to skip stepping/pausing in scripts with url matching one of the patterns. VM will try to leave blackboxed script by performing ‘step in’ several times, finally resorting to ‘step out’ if unsuccessful.
EXPERIMENTAL
- set_blackboxed_ranges(script_id, positions)[source]#
Makes backend skip steps in the script in blackboxed ranges. VM will try leave blacklisted scripts by performing ‘step in’ several times, finally resorting to ‘step out’ if unsuccessful. Positions array contains positions where blackbox state is changed. First interval isn’t blackboxed. Array should be sorted.
EXPERIMENTAL
- set_breakpoint(location, condition=None)[source]#
Sets JavaScript breakpoint at a given location.
- set_breakpoint_by_url(line_number, url=None, url_regex=None, script_hash=None, column_number=None, condition=None)[source]#
Sets JavaScript breakpoint at given location specified either by URL or URL regex. Once this command is issued, all existing parsed scripts will have breakpoints resolved and returned in
locationsproperty. Further matching script parsing will result in subsequentbreakpointResolvedevents issued. This logical breakpoint will survive page reloads.- Parameters:
line_number (
int) – Line number to set breakpoint at.url (
Optional[str]) – (Optional) URL of the resources to set breakpoint on.url_regex (
Optional[str]) – (Optional) Regex pattern for the URLs of the resources to set breakpoints on. Either`url``or``urlRegex`must be specified.script_hash (
Optional[str]) – (Optional) Script hash of the resources to set breakpoint on.column_number (
Optional[int]) – (Optional) Offset in the line to set breakpoint at.condition (
Optional[str]) – (Optional) Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[BreakpointId,List[Location]]]- Returns:
A tuple with the following items:
breakpointId - Id of the created breakpoint for further reference.
locations - List of the locations this breakpoint resolved into upon addition.
- set_breakpoint_on_function_call(object_id, condition=None)[source]#
Sets JavaScript breakpoint before each call to the given function. If another function was created from the same source as a given one, calling it will also trigger the breakpoint.
EXPERIMENTAL
- Parameters:
object_id (
RemoteObjectId) – Function object id.condition (
Optional[str]) – (Optional) Expression to use as a breakpoint condition. When specified, debugger will stop on the breakpoint if this expression evaluates to true.
- Return type:
- Returns:
Id of the created breakpoint for further reference.
- set_pause_on_exceptions(state)[source]#
Defines pause on exceptions state. Can be set to stop on all exceptions, uncaught exceptions, or caught exceptions, no exceptions. Initial pause on exceptions state is
none.
- set_return_value(new_value)[source]#
Changes return value in top frame. Available only at return break position.
EXPERIMENTAL
- set_script_source(script_id, script_source, dry_run=None, allow_top_frame_editing=None)[source]#
Edits JavaScript source live.
In general, functions that are currently on the stack can not be edited with a single exception: If the edited function is the top-most stack frame and that is the only activation of that function on the stack. In this case the live edit will be successful and a
Debugger.restartFramefor the top-most function is automatically triggered.- Parameters:
script_id (
ScriptId) – Id of the script to edit.script_source (
str) – New content of the script.dry_run (
Optional[bool]) – (Optional) If true the change will not actually be applied. Dry run may be used to get result description without actually modifying the code.allow_top_frame_editing (
Optional[bool]) – (EXPERIMENTAL) (Optional) If true, then`scriptSource``is allowed to change the function on top of the stack as long as the top-most stack frame is the only activation of that function.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[Optional[List[CallFrame]],Optional[bool],Optional[StackTrace],Optional[StackTraceId],str,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
callFrames - (Optional) New stack trace in case editing has happened while VM was stopped.
stackChanged - (Optional) Whether current call stack was modified after applying the changes.
asyncStackTrace - (Optional) Async stack trace, if any.
asyncStackTraceId - (Optional) Async stack trace, if any.
status - Whether the operation was successful or not. Only `` Ok`` denotes a successful live edit while the other enum variants denote why the live edit failed.
exceptionDetails - (Optional) Exception details if any. Only present when `` status`` is `` CompileError`.
- set_skip_all_pauses(skip)[source]#
Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc).
- set_variable_value(scope_number, variable_name, new_value, call_frame_id)[source]#
Changes value of variable in a callframe. Object-based scopes are not supported and must be mutated manually.
- Parameters:
scope_number (
int) – 0-based number of scope as was listed in scope chain. Only ‘local’, ‘closure’ and ‘catch’ scope types are allowed. Other scopes could be manipulated manually.variable_name (
str) – Variable name.new_value (
CallArgument) – New variable value.call_frame_id (
CallFrameId) – Id of callframe that holds variable.
- Return type:
- step_into(break_on_async_call=None, skip_list=None)[source]#
Steps into the function call.
- Parameters:
break_on_async_call (
Optional[bool]) – (EXPERIMENTAL) (Optional) Debugger will pause on the execution of the first async task which was scheduled before next pause.skip_list (
Optional[List[LocationRange]]) – (EXPERIMENTAL) (Optional) The skipList specifies location ranges that should be skipped on step into.
- Return type:
Events#
Generally, you do not need to instantiate CDP events yourself. Instead, the API creates events for you and then you use the event’s attributes.
- class BreakpointResolved(breakpoint_id, location)[source]#
Fired when breakpoint is resolved to an actual script and location. Deprecated in favor of
resolvedBreakpointsin thescriptParsedevent.Deprecated since version 1.3.
-
breakpoint_id:
BreakpointId# Breakpoint unique identifier.
-
breakpoint_id:
- class Paused(call_frames, reason, data, hit_breakpoints, async_stack_trace, async_stack_trace_id, async_call_stack_trace_id)[source]#
Fired when the virtual machine stopped on breakpoint or exception or any other stop criteria.
-
async_stack_trace:
Optional[StackTrace]# Async stack trace, if any.
-
async_stack_trace_id:
Optional[StackTraceId]# Async stack trace, if any.
-
async_call_stack_trace_id:
Optional[StackTraceId]# Never present, will be removed.
-
async_stack_trace:
- class ScriptFailedToParse(script_id, url, start_line, start_column, end_line, end_column, execution_context_id, hash_, build_id, execution_context_aux_data, source_map_url, has_source_url, is_module, length, stack_trace, code_offset, script_language, embedder_name)[source]#
Fired when virtual machine fails to parse the script.
-
execution_context_id:
ExecutionContextId# Specifies script creation context.
-
build_id:
str# For Wasm modules, the content of the
build_idcustom section. For JavaScript thedebugIdmagic comment.
-
execution_context_aux_data:
Optional[dict]# ‘default’``’isolated’``’worker’, frameId: string}
- Type:
Embedder-specific auxiliary data likely matching {isDefault
- Type:
boolean, type
-
stack_trace:
Optional[StackTrace]# JavaScript top stack frame of where the script parsed event was triggered if available.
-
code_offset:
Optional[int]# If the scriptLanguage is WebAssembly, the code section offset in the module.
-
script_language:
Optional[ScriptLanguage]# The language of the script.
-
execution_context_id:
- class ScriptParsed(script_id, url, start_line, start_column, end_line, end_column, execution_context_id, hash_, build_id, execution_context_aux_data, is_live_edit, source_map_url, has_source_url, is_module, length, stack_trace, code_offset, script_language, debug_symbols, embedder_name, resolved_breakpoints)[source]#
Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger.
-
execution_context_id:
ExecutionContextId# Specifies script creation context.
-
build_id:
str# For Wasm modules, the content of the
build_idcustom section. For JavaScript thedebugIdmagic comment.
-
execution_context_aux_data:
Optional[dict]# ‘default’``’isolated’``’worker’, frameId: string}
- Type:
Embedder-specific auxiliary data likely matching {isDefault
- Type:
boolean, type
-
is_live_edit:
Optional[bool]# True, if this script is generated as a result of the live edit operation.
-
stack_trace:
Optional[StackTrace]# JavaScript top stack frame of where the script parsed event was triggered if available.
-
code_offset:
Optional[int]# If the scriptLanguage is WebAssembly, the code section offset in the module.
-
script_language:
Optional[ScriptLanguage]# The language of the script.
-
debug_symbols:
Optional[List[DebugSymbols]]# If the scriptLanguage is WebAssembly, the source of debug symbols for the module.
-
resolved_breakpoints:
Optional[List[ResolvedBreakpoint]]# The list of set breakpoints in this script if calls to
setBreakpointByUrlmatches this script’s URL or hash. Clients that use this list can ignore thebreakpointResolvedevent. They are equivalent.
-
execution_context_id: