chrome-devtools-kotlin / org.hildan.chrome.devtools.domains.runtime / RuntimeDomain

RuntimeDomain

class RuntimeDomain

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.

Official doc

Functions

addBinding

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. If executionContextId is specified, adds binding only on global object of given execution context. 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.

suspend fun addBinding(input: AddBindingRequest): Unit

awaitPromise

Add handler to promise with given promise object id.

suspend fun awaitPromise(input: AwaitPromiseRequest): AwaitPromiseResponse

bindingCalled

Notification is issued every time when binding is called.

fun bindingCalled(): Flow<BindingCalledEvent>

callFunctionOn

Calls function with given declaration on the given object. Object group of the result is inherited from the target object.

suspend fun callFunctionOn(input: CallFunctionOnRequest): CallFunctionOnResponse

compileScript

Compiles expression.

suspend fun compileScript(input: CompileScriptRequest): CompileScriptResponse

consoleAPICalled

Issued when console API was called.

fun consoleAPICalled(): Flow<ConsoleAPICalledEvent>

disable

Disables reporting of execution contexts creation.

suspend fun disable(): Unit

discardConsoleEntries

Discards collected exceptions and console API calls.

suspend fun discardConsoleEntries(): Unit

enable

Enables reporting of execution contexts creation by means of executionContextCreated event. When the reporting gets enabled the event will be sent immediately for each existing execution context.

suspend fun enable(): Unit

evaluate

Evaluates expression on global object.

suspend fun evaluate(input: EvaluateRequest): EvaluateResponse

events

Subscribes to all events related to this domain.

fun events(): Flow<RuntimeEvent>

exceptionRevoked

Issued when unhandled exception was revoked.

fun exceptionRevoked(): Flow<ExceptionRevokedEvent>

exceptionThrown

Issued when exception was thrown and unhandled.

fun exceptionThrown(): Flow<ExceptionThrownEvent>

executionContextCreated

Issued when new execution context is created.

fun executionContextCreated(): Flow<ExecutionContextCreatedEvent>

executionContextDestroyed

Issued when execution context is destroyed.

fun executionContextDestroyed(): Flow<ExecutionContextDestroyedEvent>

executionContextsCleared

Issued when all executionContexts were cleared in browser

fun executionContextsCleared(): Flow<ExecutionContextsClearedEvent>

getHeapUsage

Returns the JavaScript heap usage. It is the total usage of the corresponding isolate not scoped to a particular Runtime.

suspend fun getHeapUsage(): GetHeapUsageResponse

getIsolateId

Returns the isolate id.

suspend fun getIsolateId(): GetIsolateIdResponse

getProperties

Returns properties of a given object. Object group of the result is inherited from the target object.

suspend fun getProperties(input: GetPropertiesRequest): GetPropertiesResponse

globalLexicalScopeNames

Returns all let, const and class variables from global scope.

suspend fun globalLexicalScopeNames(input: GlobalLexicalScopeNamesRequest): GlobalLexicalScopeNamesResponse

inspectRequested

Issued when object should be inspected (for example, as a result of inspect() command line API call).

fun inspectRequested(): Flow<InspectRequestedEvent>

queryObjects

Official doc

suspend fun queryObjects(input: QueryObjectsRequest): QueryObjectsResponse

releaseObject

Releases remote object with given id.

suspend fun releaseObject(input: ReleaseObjectRequest): Unit

releaseObjectGroup

Releases all remote objects that belong to a given group.

suspend fun releaseObjectGroup(input: ReleaseObjectGroupRequest): Unit

removeBinding

This method does not remove binding function from global object but unsubscribes current runtime agent from Runtime.bindingCalled notifications.

suspend fun removeBinding(input: RemoveBindingRequest): Unit

runIfWaitingForDebugger

Tells inspected instance to run if it was waiting for debugger to attach.

suspend fun runIfWaitingForDebugger(): Unit

runScript

Runs script with given id in a given context.

suspend fun runScript(input: RunScriptRequest): RunScriptResponse

setAsyncCallStackDepth

Enables or disables async call stacks tracking.

suspend fun setAsyncCallStackDepth(input: SetAsyncCallStackDepthRequest): Unit

setCustomObjectFormatterEnabled

Official doc

suspend fun setCustomObjectFormatterEnabled(input: SetCustomObjectFormatterEnabledRequest): Unit

setMaxCallStackSizeToCapture

Official doc

suspend fun setMaxCallStackSizeToCapture(input: SetMaxCallStackSizeToCaptureRequest): Unit

terminateExecution

Terminate current or next JavaScript execution. Will cancel the termination when the outer-most script execution ends.

suspend fun terminateExecution(): Unit

Extension Functions

evaluateJs

Evaluates the given js expression, and returns the result as a value of type T.

suspend fun <T> RuntimeDomain.evaluateJs(js: String): T?

Evaluates the given js expression, and returns the result as a value of type T using the provided deserializer.

suspend fun <T> RuntimeDomain.evaluateJs(js: String, deserializer: DeserializationStrategy<T>): T?