Runtime#
Runtime domain exposes JavaScript runtime by means of remote evaluation and mirror objects. Evaluation results are returned as mirror object that expose object type, string representation and unique identifier that can be used for further object reference. Original objects are maintained in memory unless they are either explicitly released or are released along with the other objects in their object group.
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 SerializationOptions(serialization, max_depth=None, additional_parameters=None)[source]#
Represents options for serialization. Overrides
generatePreviewandreturnByValue.
- class DeepSerializedValue(type_, value=None, object_id=None, weak_local_object_reference=None)[source]#
Represents deep serialized value.
- class UnserializableValue[source]#
Primitive value which cannot be JSON-stringified. Includes values
-0,NaN,Infinity,-Infinity, and bigint literals.
- class RemoteObject(type_, subtype=None, class_name=None, value=None, unserializable_value=None, description=None, deep_serialized_value=None, object_id=None, preview=None, custom_preview=None)[source]#
Mirror object referencing original JavaScript object.
-
subtype:
Optional[str] = None# Object subtype hint. Specified for
objecttype values only. NOTE: If you change anything here, make sure to also updatesubtypeinObjectPreviewandPropertyPreviewbelow.
-
class_name:
Optional[str] = None# Object class (constructor) name. Specified for
objecttype values only.
-
value:
Optional[Any] = None# Remote object value in case of primitive values or JSON values (if it was requested).
-
unserializable_value:
Optional[UnserializableValue] = None# Primitive value which can not be JSON-stringified does not have
value, but gets this property.
-
deep_serialized_value:
Optional[DeepSerializedValue] = None# Deep serialized value.
-
object_id:
Optional[RemoteObjectId] = None# Unique object identifier (for non-primitive values).
-
preview:
Optional[ObjectPreview] = None# Preview containing abbreviated property values. Specified for
objecttype values only.
-
custom_preview:
Optional[CustomPreview] = None#
-
subtype:
- class CustomPreview(header, body_getter_id=None)[source]#
-
header:
str# The JSON-stringified result of formatter.header(object, config) call. It contains json ML array that represents RemoteObject.
-
body_getter_id:
Optional[RemoteObjectId] = None# If formatter returns true as a result of formatter.hasBody call then bodyGetterId will contain RemoteObjectId for the function that returns result of formatter.body(object, config) call. The result value is json ML array.
-
header:
- class ObjectPreview(type_, overflow, properties, subtype=None, description=None, entries=None)[source]#
Object containing abbreviated remote object value.
-
properties:
List[PropertyPreview]# List of the properties.
-
entries:
Optional[List[EntryPreview]] = None# List of the entries. Specified for
mapandsetsubtype values only.
-
properties:
- class PropertyPreview(name, type_, value=None, value_preview=None, subtype=None)[source]#
-
-
value_preview:
Optional[ObjectPreview] = None# Nested value preview.
-
value_preview:
- class EntryPreview(value, key=None)[source]#
-
value:
ObjectPreview# Preview of the value.
-
key:
Optional[ObjectPreview] = None# Preview of the key. Specified for map-like collection entries.
-
value:
- class PropertyDescriptor(name, configurable, enumerable, value=None, writable=None, get=None, set_=None, was_thrown=None, is_own=None, symbol=None)[source]#
Object property descriptor.
-
configurable:
bool# True if the type of this property descriptor may be changed and if the property may be deleted from the corresponding object.
-
enumerable:
bool# True if this property shows up during enumeration of the properties on the corresponding object.
-
value:
Optional[RemoteObject] = None# The value associated with the property.
-
writable:
Optional[bool] = None# True if the value associated with the property may be changed (data descriptors only).
-
get:
Optional[RemoteObject] = None# A function which serves as a getter for the property, or
undefinedif there is no getter (accessor descriptors only).
-
set_:
Optional[RemoteObject] = None# A function which serves as a setter for the property, or
undefinedif there is no setter (accessor descriptors only).
-
symbol:
Optional[RemoteObject] = None# Property symbol object, if the property is of the
symboltype.
-
configurable:
- class InternalPropertyDescriptor(name, value=None)[source]#
Object internal property descriptor. This property isn’t normally visible in JavaScript code.
-
value:
Optional[RemoteObject] = None# The value associated with the property.
-
value:
- class PrivatePropertyDescriptor(name, value=None, get=None, set_=None)[source]#
Object private field descriptor.
-
value:
Optional[RemoteObject] = None# The value associated with the private property.
-
get:
Optional[RemoteObject] = None# A function which serves as a getter for the private property, or
undefinedif there is no getter (accessor descriptors only).
-
set_:
Optional[RemoteObject] = None# A function which serves as a setter for the private property, or
undefinedif there is no setter (accessor descriptors only).
-
value:
- class CallArgument(value=None, unserializable_value=None, object_id=None)[source]#
Represents function call argument. Either remote object id
objectId, primitivevalue, unserializable primitive value or neither of (for undefined) them should be specified.-
unserializable_value:
Optional[UnserializableValue] = None# Primitive value which can not be JSON-stringified.
-
object_id:
Optional[RemoteObjectId] = None# Remote object handle.
-
unserializable_value:
- class ExecutionContextDescription(id_, origin, name, unique_id, aux_data=None)[source]#
Description of an isolated world.
-
id_:
ExecutionContextId# Unique id of the execution context. It can be used to specify in which execution context script evaluation should be performed.
-
id_:
- class ExceptionDetails(exception_id, text, line_number, column_number, script_id=None, url=None, stack_trace=None, exception=None, execution_context_id=None, exception_meta_data=None)[source]#
Detailed information about exception (or error) that was thrown during script compilation or execution.
-
url:
Optional[str] = None# URL of the exception location, to be used when the script was not reported.
-
stack_trace:
Optional[StackTrace] = None# JavaScript stack trace if available.
-
exception:
Optional[RemoteObject] = None# Exception object if available.
-
execution_context_id:
Optional[ExecutionContextId] = None# Identifier of the context where exception happened.
-
url:
- class CallFrame(function_name, script_id, url, line_number, column_number)[source]#
Stack entry for runtime errors and assertions.
- class StackTrace(call_frames, description=None, parent=None, parent_id=None)[source]#
Call frames for assertions or error messages.
-
description:
Optional[str] = None# String label of this stack trace. For async traces this may be a name of the function that initiated the async call.
-
parent:
Optional[StackTrace] = None# Asynchronous JavaScript stack trace that preceded this stack, if available.
-
parent_id:
Optional[StackTraceId] = None# Asynchronous JavaScript stack trace that preceded this stack, if available.
-
description:
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.
- add_binding(name, execution_context_id=None, execution_context_name=None)[source]#
If executionContextId is empty, adds binding with the given name on the global objects of all inspected contexts, including those created later, bindings survive reloads. Binding function takes exactly one argument, this argument should be string, in case of any other input, function throws an exception. Each binding function call produces Runtime.bindingCalled notification.
- Parameters:
name (
str) –execution_context_id (
Optional[ExecutionContextId]) – (DEPRECATED) (EXPERIMENTAL) (Optional) If specified, the binding would only be exposed to the specified execution context. If omitted and`executionContextName``is not set, the binding is exposed to all execution contexts of the target. This parameter is mutually exclusive with``executionContextName``. Deprecated in favor of``executionContextName``due to an unclear use case and bugs in implementation (crbug.com/1169639).``executionContextId``will be removed in the future.execution_context_name (
Optional[str]) – (Optional) If specified, the binding is exposed to the executionContext with matching name, even for contexts created after the binding is added. See also``ExecutionContext.name``and``worldName``parameter to``Page.addScriptToEvaluateOnNewDocument``. This parameter is mutually exclusive with``executionContextId`.
- Return type:
- await_promise(promise_object_id, return_by_value=None, generate_preview=None)[source]#
Add handler to promise with given promise object id.
- Parameters:
promise_object_id (
RemoteObjectId) – Identifier of the promise.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]) – (Optional) Whether preview should be generated for the result.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[RemoteObject,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Promise result. Will contain rejected value if promise was rejected.
exceptionDetails - (Optional) Exception details if stack strace is available.
- call_function_on(function_declaration, object_id=None, arguments=None, silent=None, return_by_value=None, generate_preview=None, user_gesture=None, await_promise=None, execution_context_id=None, object_group=None, throw_on_side_effect=None, unique_context_id=None, serialization_options=None)[source]#
Calls function with given declaration on the given object. Object group of the result is inherited from the target object.
- Parameters:
function_declaration (
str) – Declaration of the function to call.object_id (
Optional[RemoteObjectId]) – (Optional) Identifier of the object to call function on. Either objectId or executionContextId should be specified.arguments (
Optional[List[CallArgument]]) – (Optional) Call arguments. All call arguments must belong to the same JavaScript world as the target object.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 which should be sent by value. Can be overriden by``serializationOptions``.generate_preview (
Optional[bool]) – (EXPERIMENTAL) (Optional) Whether preview should be generated for the result.user_gesture (
Optional[bool]) – (Optional) Whether execution should be treated as initiated by user in the UI.await_promise (
Optional[bool]) – (Optional) Whether execution should``await``for resulting value and return once awaited promise is resolved.execution_context_id (
Optional[ExecutionContextId]) – (Optional) Specifies execution context which global object will be used to call function on. Either executionContextId or objectId should be specified.object_group (
Optional[str]) – (Optional) Symbolic group name that can be used to release multiple objects. If objectGroup is not specified and objectId is, objectGroup will be inherited from object.throw_on_side_effect (
Optional[bool]) – (EXPERIMENTAL) (Optional) Whether to throw an exception if side effect cannot be ruled out during evaluation.unique_context_id (
Optional[str]) – (EXPERIMENTAL) (Optional) An alternative way to specify the execution context to call function on. Compared to contextId that may be reused across processes, this is guaranteed to be system-unique, so it can be used to prevent accidental function call in context different than intended (e.g. as a result of navigation across process boundaries). This is mutually exclusive with``executionContextId``.serialization_options (
Optional[SerializationOptions]) – (EXPERIMENTAL) (Optional) Specifies the result serialization. If provided, overrides``generatePreview``and``returnByValue`.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[RemoteObject,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Call result.
exceptionDetails - (Optional) Exception details.
- compile_script(expression, source_url, persist_script, execution_context_id=None)[source]#
Compiles expression.
- Parameters:
expression (
str) – Expression to compile.source_url (
str) – Source url to be set for the script.persist_script (
bool) – Specifies whether the compiled script should be persisted.execution_context_id (
Optional[ExecutionContextId]) – (Optional) Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[Optional[ScriptId],Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
scriptId - (Optional) Id of the script.
exceptionDetails - (Optional) Exception details.
- enable()[source]#
Enables reporting of execution contexts creation by means of
executionContextCreatedevent. When the reporting gets enabled the event will be sent immediately for each existing execution context.
- evaluate(expression, object_group=None, include_command_line_api=None, silent=None, context_id=None, return_by_value=None, generate_preview=None, user_gesture=None, await_promise=None, throw_on_side_effect=None, timeout=None, disable_breaks=None, repl_mode=None, allow_unsafe_eval_blocked_by_csp=None, unique_context_id=None, serialization_options=None)[source]#
Evaluates expression on global object.
- Parameters:
expression (
str) – Expression to evaluate.object_group (
Optional[str]) – (Optional) Symbolic group name that can be used to release multiple objects.include_command_line_api (
Optional[bool]) – (Optional) Determines whether Command Line API should be available during the evaluation.silent (
Optional[bool]) – (Optional) In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides`setPauseOnException``state.context_id (
Optional[ExecutionContextId]) – (Optional) Specifies in which execution context to perform evaluation. If the parameter is omitted the evaluation will be performed in the context of the inspected page. This is mutually exclusive with``uniqueContextId``, which offers an alternative way to identify the execution context that is more reliable in a multi-process environment.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.user_gesture (
Optional[bool]) – (Optional) Whether execution should be treated as initiated by user in the UI.await_promise (
Optional[bool]) – (Optional) Whether execution should``await``for resulting value and return once awaited promise is resolved.throw_on_side_effect (
Optional[bool]) – (EXPERIMENTAL) (Optional) Whether to throw an exception if side effect cannot be ruled out during evaluation. This implies``disableBreaks``below.timeout (
Optional[TimeDelta]) – (EXPERIMENTAL) (Optional) Terminate execution after timing out (number of milliseconds).disable_breaks (
Optional[bool]) – (EXPERIMENTAL) (Optional) Disable breakpoints during execution.repl_mode (
Optional[bool]) – (EXPERIMENTAL) (Optional) Setting this flag to true enables``let``re-declaration and top-level``await``. Note that``let``variables can only be re-declared if they originate from``replMode``themselves.allow_unsafe_eval_blocked_by_csp (
Optional[bool]) – (EXPERIMENTAL) (Optional) The Content Security Policy (CSP) for the target might block ‘unsafe-eval’ which includes eval(), Function(), setTimeout() and setInterval() when called with non-callable arguments. This flag bypasses CSP for this evaluation and allows unsafe-eval. Defaults to true.unique_context_id (
Optional[str]) – (EXPERIMENTAL) (Optional) An alternative way to specify the execution context to evaluate in. Compared to contextId that may be reused across processes, this is guaranteed to be system-unique, so it can be used to prevent accidental evaluation of the expression in context different than intended (e.g. as a result of navigation across process boundaries). This is mutually exclusive with``contextId``.serialization_options (
Optional[SerializationOptions]) – (EXPERIMENTAL) (Optional) Specifies the result serialization. If provided, overrides``generatePreview``and``returnByValue`.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[RemoteObject,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Evaluation result.
exceptionDetails - (Optional) Exception details.
- get_exception_details(error_object_id)[source]#
This method tries to lookup and populate exception details for a JavaScript Error object. Note that the stackTrace portion of the resulting exceptionDetails will only be populated if the Runtime domain was enabled at the time when the Error was thrown.
EXPERIMENTAL
- Parameters:
error_object_id (
RemoteObjectId) – The error object for which to resolve the exception details.- Return type:
Generator[Dict[str,Any],Dict[str,Any],Optional[ExceptionDetails]]- Returns:
- get_heap_usage()[source]#
Returns the JavaScript heap usage. It is the total usage of the corresponding isolate not scoped to a particular Runtime.
EXPERIMENTAL
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[float,float,float,float]]- Returns:
A tuple with the following items:
usedSize - Used JavaScript heap size in bytes.
totalSize - Allocated JavaScript heap size in bytes.
embedderHeapUsedSize - Used size in bytes in the embedder’s garbage-collected heap.
backingStorageSize - Size in bytes of backing storage for array buffers and external strings.
- get_properties(object_id, own_properties=None, accessor_properties_only=None, generate_preview=None, non_indexed_properties_only=None)[source]#
Returns properties of a given object. Object group of the result is inherited from the target object.
- Parameters:
object_id (
RemoteObjectId) – Identifier of the object to return properties for.own_properties (
Optional[bool]) – (Optional) If true, returns properties belonging only to the element itself, not to its prototype chain.accessor_properties_only (
Optional[bool]) – (EXPERIMENTAL) (Optional) If true, returns accessor properties (with getter/setter) only; internal properties are not returned either.generate_preview (
Optional[bool]) – (EXPERIMENTAL) (Optional) Whether preview should be generated for the results.non_indexed_properties_only (
Optional[bool]) – (EXPERIMENTAL) (Optional) If true, returns non-indexed properties only.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[List[PropertyDescriptor],Optional[List[InternalPropertyDescriptor]],Optional[List[PrivatePropertyDescriptor]],Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Object properties.
internalProperties - (Optional) Internal object properties (only of the element itself).
privateProperties - (Optional) Object private properties.
exceptionDetails - (Optional) Exception details.
- global_lexical_scope_names(execution_context_id=None)[source]#
Returns all let, const and class variables from global scope.
- query_objects(prototype_object_id, object_group=None)[source]#
- Parameters:
prototype_object_id (
RemoteObjectId) – Identifier of the prototype to return objects for.object_group (
Optional[str]) – (Optional) Symbolic group name that can be used to release the results.
- Return type:
- Returns:
Array with objects.
- release_object_group(object_group)[source]#
Releases all remote objects that belong to a given group.
- remove_binding(name)[source]#
This method does not remove binding function from global object but unsubscribes current runtime agent from Runtime.bindingCalled notifications.
- run_if_waiting_for_debugger()[source]#
Tells inspected instance to run if it was waiting for debugger to attach.
- run_script(script_id, execution_context_id=None, object_group=None, silent=None, include_command_line_api=None, return_by_value=None, generate_preview=None, await_promise=None)[source]#
Runs script with given id in a given context.
- Parameters:
script_id (
ScriptId) – Id of the script to run.execution_context_id (
Optional[ExecutionContextId]) – (Optional) Specifies in which execution context to perform script run. If the parameter is omitted the evaluation will be performed in the context of the inspected page.object_group (
Optional[str]) – (Optional) Symbolic group name that can be used to release multiple objects.silent (
Optional[bool]) – (Optional) In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides`setPauseOnException``state.include_command_line_api (
Optional[bool]) – (Optional) Determines whether Command Line API should be available during the evaluation.return_by_value (
Optional[bool]) – (Optional) Whether the result is expected to be a JSON object which should be sent by value.generate_preview (
Optional[bool]) – (Optional) Whether preview should be generated for the result.await_promise (
Optional[bool]) – (Optional) Whether execution should``await`for resulting value and return once awaited promise is resolved.
- Return type:
Generator[Dict[str,Any],Dict[str,Any],Tuple[RemoteObject,Optional[ExceptionDetails]]]- Returns:
A tuple with the following items:
result - Run result.
exceptionDetails - (Optional) Exception details.
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 BindingCalled(name, payload, execution_context_id)[source]#
EXPERIMENTAL
Notification is issued every time when binding is called.
-
execution_context_id:
ExecutionContextId# Identifier of the context where the call was made.
-
execution_context_id:
- class ConsoleAPICalled(type_, args, execution_context_id, timestamp, stack_trace, context)[source]#
Issued when console API was called.
-
args:
List[RemoteObject]# Call arguments.
-
execution_context_id:
ExecutionContextId# Identifier of the context where the call was made.
-
stack_trace:
Optional[StackTrace]# Stack trace captured when the call was made. The async stack chain is automatically reported for the following call types:
assert,error,trace,warning. For other types the async call chain can be retrieved usingDebugger.getStackTraceandstackTrace.parentIdfield.
-
args:
- class ExceptionThrown(timestamp, exception_details)[source]#
Issued when exception was thrown and unhandled.
-
exception_details:
ExceptionDetails#
-
exception_details:
- class ExecutionContextCreated(context)[source]#
Issued when new execution context is created.
-
context:
ExecutionContextDescription# A newly created execution context.
-
context:
- class ExecutionContextDestroyed(execution_context_id, execution_context_unique_id)[source]#
Issued when execution context is destroyed.
-
execution_context_id:
ExecutionContextId# Id of the destroyed context
-
execution_context_id:
- class InspectRequested(object_, hints, execution_context_id)[source]#
Issued when object should be inspected (for example, as a result of inspect() command line API call).
-
object_:
RemoteObject#
-
execution_context_id:
Optional[ExecutionContextId]# Identifier of the context where the call was made.
-
object_: