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
cdp.debugger.
BreakpointId
¶ Breakpoint identifier.
-
class
cdp.debugger.
CallFrameId
¶ Call frame identifier.
-
class
cdp.debugger.
Location
(script_id, line_number, column_number=None)¶ Location in the source code.
-
column_number
= None¶ Column number in the script (0-based).
-
line_number
= None¶ Line number in the script (0-based).
-
script_id
= None¶ Script identifier as reported in the
Debugger.scriptParsed
.
-
-
class
cdp.debugger.
ScriptPosition
(line_number, column_number)¶ Location in the source code.
-
class
cdp.debugger.
CallFrame
(call_frame_id, function_name, location, url, scope_chain, this, function_location=None, return_value=None)¶ JavaScript call frame. Array of call frames form the call stack.
-
call_frame_id
= None¶ Call frame identifier. This identifier is only valid while the virtual machine is paused.
-
function_location
= None¶ Location in the source code.
-
function_name
= None¶ Name of the JavaScript function called on this call frame.
-
location
= None¶ Location in the source code.
-
return_value
= None¶ The value being returned, if the function is at return point.
-
scope_chain
= None¶ Scope chain for this call frame.
-
this
= None¶ this
object for this call frame.
-
url
= None¶ JavaScript script name or url.
-
-
class
cdp.debugger.
Scope
(type_, object_, name=None, start_location=None, end_location=None)¶ Scope description.
-
end_location
= None¶ Location in the source code where scope ends
-
name
= None¶
-
object_
= None¶ Object representing the scope. For
global
andwith
scopes it represents the actual object; for the rest of the scopes, it is artificial transient object enumerating scope variables as its properties.
-
start_location
= None¶ Location in the source code where scope starts
-
type_
= None¶ Scope type.
-
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.
-
cdp.debugger.
continue_to_location
(location, target_call_frames=None)¶ Continues execution until specific location is reached.
Parameters: - location (
Location
) – Location to continue to. - target_call_frames (
Optional
[str
]) – (Optional)
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- location (
-
cdp.debugger.
disable
()¶ Disables debugger for given page.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
enable
(max_scripts_cache_size=None)¶ Enables debugger for the given page. Clients should not assume that the debugging has been enabled until the result for this command is received.
Parameters: max_scripts_cache_size ( Optional
[float
]) – (EXPERIMENTAL) (Optional) The maximum size in bytes of collected scripts (not referenced by other heap objects) the debugger can hold. Puts no limit if paramter is omitted.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],UniqueDebuggerId
]Returns: Unique identifier of the debugger.
-
cdp.debugger.
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)¶ 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.
- call_frame_id (
-
cdp.debugger.
get_possible_breakpoints
(start, end=None, restrict_to_function=None)¶ 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.
- start (
-
cdp.debugger.
get_script_source
(script_id)¶ 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
],str
]Returns: Script source.
-
cdp.debugger.
get_stack_trace
(stack_trace_id)¶ Returns stack trace with given
stackTraceId
.EXPERIMENTAL
Parameters: stack_trace_id ( StackTraceId
) –Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],StackTrace
]Returns:
-
cdp.debugger.
pause
()¶ Stops on the next JavaScript statement.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
pause_on_async_call
(parent_stack_trace_id)¶ EXPERIMENTAL
Parameters: parent_stack_trace_id ( StackTraceId
) – Debugger will pause when async call with given stack trace is started.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
remove_breakpoint
(breakpoint_id)¶ Removes JavaScript breakpoint.
Parameters: breakpoint_id ( BreakpointId
) –Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
restart_frame
(call_frame_id)¶ Restarts particular call frame from the beginning.
Parameters: call_frame_id ( CallFrameId
) – Call frame identifier to evaluate on.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.
-
cdp.debugger.
resume
()¶ Resumes JavaScript execution.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
search_in_content
(script_id, query, case_sensitive=None, is_regex=None)¶ Searches for given string in script content.
Parameters: - script_id (
ScriptId
) – Id of the script to search in. - query (
str
) – String to search for. - case_sensitive (
Optional
[bool
]) – (Optional) If true, search is case sensitive. - is_regex (
Optional
[bool
]) – (Optional) If true, treats string parameter as regex.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],List
[SearchMatch
]]Returns: List of search matches.
- script_id (
-
cdp.debugger.
set_async_call_stack_depth
(max_depth)¶ Enables or disables async call stacks tracking.
Parameters: max_depth ( int
) – Maximum depth of async call stacks. Setting to`0`
will effectively disable collecting async call stacks (default).Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_blackbox_patterns
(patterns)¶ 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
Parameters: patterns ( List
[str
]) – Array of regexps that will be used to check script url for blackbox state.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_blackboxed_ranges
(script_id, positions)¶ 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
Parameters: - script_id (
ScriptId
) – Id of the script. - positions (
List
[ScriptPosition
]) –
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- script_id (
-
cdp.debugger.
set_breakpoint
(location, condition=None)¶ Sets JavaScript breakpoint at a given location.
Parameters: - location (
Location
) – Location to set breakpoint in. - 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
,Location
]]Returns: A tuple with the following items:
- breakpointId - Id of the created breakpoint for further reference.
- actualLocation - Location this breakpoint resolved into.
- location (
-
cdp.debugger.
set_breakpoint_by_url
(line_number, url=None, url_regex=None, script_hash=None, column_number=None, condition=None)¶ 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
locations
property. Further matching script parsing will result in subsequentbreakpointResolved
events 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.
- line_number (
-
cdp.debugger.
set_breakpoint_on_function_call
(object_id, condition=None)¶ 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: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],BreakpointId
]Returns: Id of the created breakpoint for further reference.
- object_id (
-
cdp.debugger.
set_breakpoints_active
(active)¶ Activates / deactivates all breakpoints on the page.
Parameters: active ( bool
) – New value for breakpoints active state.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_instrumentation_breakpoint
(instrumentation)¶ Sets instrumentation breakpoint.
Parameters: instrumentation ( str
) – Instrumentation name.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],BreakpointId
]Returns: Id of the created breakpoint for further reference.
-
cdp.debugger.
set_pause_on_exceptions
(state)¶ Defines pause on exceptions state. Can be set to stop on all exceptions, uncaught exceptions or no exceptions. Initial pause on exceptions state is
none
.Parameters: state ( str
) – Pause on exceptions mode.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_return_value
(new_value)¶ Changes return value in top frame. Available only at return break position.
EXPERIMENTAL
Parameters: new_value ( CallArgument
) – New return value.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_script_source
(script_id, script_source, dry_run=None)¶ Edits JavaScript source live.
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.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],Tuple
[Optional
[List
[CallFrame
]],Optional
[bool
],Optional
[StackTrace
],Optional
[StackTraceId
],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.
- exceptionDetails - (Optional) Exception details if any.
- script_id (
-
cdp.debugger.
set_skip_all_pauses
(skip)¶ Makes page not interrupt on any pauses (breakpoint, exception, dom exception etc).
Parameters: skip ( bool
) – New value for skip pauses state.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
set_variable_value
(scope_number, variable_name, new_value, call_frame_id)¶ 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: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]- scope_number (
-
cdp.debugger.
step_into
(break_on_async_call=None)¶ Steps into the function call.
Parameters: break_on_async_call ( Optional
[bool
]) – (EXPERIMENTAL) (Optional) Debugger will issue additional Debugger.paused notification if any async task is scheduled before next pause.Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
step_out
()¶ Steps out of the function call.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
-
cdp.debugger.
step_over
()¶ Steps over the statement.
Return type: Generator
[Dict
[str
,Any
],Dict
[str
,Any
],None
]
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
cdp.debugger.
BreakpointResolved
(breakpoint_id, location)¶ Fired when breakpoint is resolved to an actual script and location.
-
breakpoint_id
= None¶ Breakpoint unique identifier.
-
location
= None¶ Actual breakpoint location.
-
-
class
cdp.debugger.
Paused
(call_frames, reason, data, hit_breakpoints, async_stack_trace, async_stack_trace_id, async_call_stack_trace_id)¶ Fired when the virtual machine stopped on breakpoint or exception or any other stop criteria.
-
async_call_stack_trace_id
= None¶ Just scheduled async call will have this stack trace as parent stack during async execution. This field is available only after
Debugger.stepInto
call withbreakOnAsynCall
flag.
-
async_stack_trace
= None¶ Async stack trace, if any.
-
async_stack_trace_id
= None¶ Async stack trace, if any.
-
call_frames
= None¶ Call stack the virtual machine stopped on.
-
data
= None¶ Object containing break-specific auxiliary properties.
-
hit_breakpoints
= None¶ Hit breakpoints IDs
-
reason
= None¶ Pause reason.
-
-
class
cdp.debugger.
Resumed
¶ Fired when the virtual machine resumed execution.
-
class
cdp.debugger.
ScriptFailedToParse
(script_id, url, start_line, start_column, end_line, end_column, execution_context_id, hash_, execution_context_aux_data, source_map_url, has_source_url, is_module, length, stack_trace)¶ Fired when virtual machine fails to parse the script.
-
end_column
= None¶ Length of the last line of the script.
-
end_line
= None¶ Last line of the script.
-
execution_context_aux_data
= None¶ Embedder-specific auxiliary data.
-
execution_context_id
= None¶ Specifies script creation context.
-
has_source_url
= None¶ True, if this script has sourceURL.
-
hash_
= None¶ Content hash of the script.
-
is_module
= None¶ True, if this script is ES6 module.
-
length
= None¶ This script length.
-
script_id
= None¶ Identifier of the script parsed.
-
source_map_url
= None¶ URL of source map associated with script (if any).
-
stack_trace
= None¶ JavaScript top stack frame of where the script parsed event was triggered if available.
-
start_column
= None¶ Column offset of the script within the resource with given URL.
-
start_line
= None¶ Line offset of the script within the resource with given URL (for script tags).
-
url
= None¶ URL or name of the script parsed (if any).
-
-
class
cdp.debugger.
ScriptParsed
(script_id, url, start_line, start_column, end_line, end_column, execution_context_id, hash_, execution_context_aux_data, is_live_edit, source_map_url, has_source_url, is_module, length, stack_trace)¶ Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger.
-
end_column
= None¶ Length of the last line of the script.
-
end_line
= None¶ Last line of the script.
-
execution_context_aux_data
= None¶ Embedder-specific auxiliary data.
-
execution_context_id
= None¶ Specifies script creation context.
-
has_source_url
= None¶ True, if this script has sourceURL.
-
hash_
= None¶ Content hash of the script.
-
is_live_edit
= None¶ True, if this script is generated as a result of the live edit operation.
-
is_module
= None¶ True, if this script is ES6 module.
-
length
= None¶ This script length.
-
script_id
= None¶ Identifier of the script parsed.
-
source_map_url
= None¶ URL of source map associated with script (if any).
-
stack_trace
= None¶ JavaScript top stack frame of where the script parsed event was triggered if available.
-
start_column
= None¶ Column offset of the script within the resource with given URL.
-
start_line
= None¶ Line offset of the script within the resource with given URL (for script tags).
-
url
= None¶ URL or name of the script parsed (if any).
-