Package io.webfolder.cdp.command
Interface RuntimeAsync
public interface RuntimeAsync
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.
-
Method Summary
Modifier and TypeMethodDescriptionaddBinding
(String name) 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.addBinding
(String name, Integer executionContextId, String executionContextName) 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.awaitPromise
(String promiseObjectId) Add handler to promise with given promise object id.awaitPromise
(String promiseObjectId, Boolean returnByValue, Boolean generatePreview) Add handler to promise with given promise object id.callFunctionOn
(String functionDeclaration) Calls function with given declaration on the given object.callFunctionOn
(String functionDeclaration, String objectId, List<CallArgument> arguments, Boolean silent, Boolean returnByValue, Boolean generatePreview, Boolean userGesture, Boolean awaitPromise, Integer executionContextId, String objectGroup, Boolean throwOnSideEffect, Boolean generateWebDriverValue) Calls function with given declaration on the given object.compileScript
(String expression, String sourceURL, Boolean persistScript) Compiles expression.compileScript
(String expression, String sourceURL, Boolean persistScript, Integer executionContextId) Compiles expression.disable()
Disables reporting of execution contexts creation.Discards collected exceptions and console API calls.enable()
Enables reporting of execution contexts creation by means of executionContextCreated event.Evaluates expression on global object.evaluate
(String expression, String objectGroup, Boolean includeCommandLineAPI, Boolean silent, Integer contextId, Boolean returnByValue, Boolean generatePreview, Boolean userGesture, Boolean awaitPromise, Boolean throwOnSideEffect, Double timeout, Boolean disableBreaks, Boolean replMode, Boolean allowUnsafeEvalBlockedByCSP, String uniqueContextId, Boolean generateWebDriverValue) Evaluates expression on global object.getExceptionDetails
(String errorObjectId) This method tries to lookup and populate exception details for a JavaScript Error object.Returns the JavaScript heap usage.Returns the isolate id.getProperties
(String objectId) Returns properties of a given object.getProperties
(String objectId, Boolean ownProperties, Boolean accessorPropertiesOnly, Boolean generatePreview, Boolean nonIndexedPropertiesOnly) Returns properties of a given object.Returns all let, const and class variables from global scope.globalLexicalScopeNames
(Integer executionContextId) Returns all let, const and class variables from global scope.queryObjects
(String prototypeObjectId) queryObjects
(String prototypeObjectId, String objectGroup) releaseObject
(String objectId) Releases remote object with given id.releaseObjectGroup
(String objectGroup) Releases all remote objects that belong to a given group.removeBinding
(String name) This method does not remove binding function from global object but unsubscribes current runtime agent from Runtime.bindingCalled notifications.Tells inspected instance to run if it was waiting for debugger to attach.Runs script with given id in a given context.runScript
(String scriptId, Integer executionContextId, String objectGroup, Boolean silent, Boolean includeCommandLineAPI, Boolean returnByValue, Boolean generatePreview, Boolean awaitPromise) Runs script with given id in a given context.setAsyncCallStackDepth
(Integer maxDepth) Enables or disables async call stacks tracking.setCustomObjectFormatterEnabled
(Boolean enabled) Terminate current or next JavaScript execution.
-
Method Details
-
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. 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. -
addBinding
CompletableFuture<Void> addBinding(String name, @Deprecated Integer executionContextId, String executionContextName) 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:
executionContextId
- 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.executionContextName
- 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.
-
awaitPromise
Add handler to promise with given promise object id.- Parameters:
promiseObjectId
- Identifier of the promise.- Returns:
- AwaitPromiseResult
-
awaitPromise
CompletableFuture<AwaitPromiseResult> awaitPromise(String promiseObjectId, Boolean returnByValue, Boolean generatePreview) Add handler to promise with given promise object id.- Parameters:
promiseObjectId
- Identifier of the promise.returnByValue
- Whether the result is expected to be a JSON object that should be sent by value.generatePreview
- Whether preview should be generated for the result.- Returns:
- AwaitPromiseResult
-
callFunctionOn
Calls function with given declaration on the given object. Object group of the result is inherited from the target object.- Parameters:
functionDeclaration
- Declaration of the function to call.- Returns:
- CallFunctionOnResult
-
callFunctionOn
CompletableFuture<CallFunctionOnResult> callFunctionOn(String functionDeclaration, String objectId, List<CallArgument> arguments, Boolean silent, Boolean returnByValue, Boolean generatePreview, Boolean userGesture, Boolean awaitPromise, Integer executionContextId, String objectGroup, Boolean throwOnSideEffect, Boolean generateWebDriverValue) Calls function with given declaration on the given object. Object group of the result is inherited from the target object.- Parameters:
functionDeclaration
- Declaration of the function to call.objectId
- Identifier of the object to call function on. Either objectId or executionContextId should be specified.arguments
- Call arguments. All call arguments must belong to the same JavaScript world as the target object.silent
- In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.returnByValue
- Whether the result is expected to be a JSON object which should be sent by value.generatePreview
- Whether preview should be generated for the result.userGesture
- Whether execution should be treated as initiated by user in the UI.awaitPromise
- Whether execution should await for resulting value and return once awaited promise is resolved.executionContextId
- Specifies execution context which global object will be used to call function on. Either executionContextId or objectId should be specified.objectGroup
- 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.throwOnSideEffect
- Whether to throw an exception if side effect cannot be ruled out during evaluation.generateWebDriverValue
- Whether the result should contain webDriverValue, serialized according to https://w3c.github.io/webdriver-bidi. This is mutually exclusive with returnByValue, but resulting objectId is still provided.- Returns:
- CallFunctionOnResult
-
compileScript
CompletableFuture<CompileScriptResult> compileScript(String expression, String sourceURL, Boolean persistScript) Compiles expression.- Parameters:
expression
- Expression to compile.sourceURL
- Source url to be set for the script.persistScript
- Specifies whether the compiled script should be persisted.- Returns:
- CompileScriptResult
-
compileScript
CompletableFuture<CompileScriptResult> compileScript(String expression, String sourceURL, Boolean persistScript, Integer executionContextId) Compiles expression.- Parameters:
expression
- Expression to compile.sourceURL
- Source url to be set for the script.persistScript
- Specifies whether the compiled script should be persisted.executionContextId
- 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.- Returns:
- CompileScriptResult
-
disable
CompletableFuture<Void> disable()Disables reporting of execution contexts creation. -
discardConsoleEntries
CompletableFuture<Void> discardConsoleEntries()Discards collected exceptions and console API calls. -
enable
CompletableFuture<Void> 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. -
evaluate
Evaluates expression on global object.- Parameters:
expression
- Expression to evaluate.- Returns:
- EvaluateResult
-
evaluate
CompletableFuture<EvaluateResult> evaluate(String expression, String objectGroup, Boolean includeCommandLineAPI, Boolean silent, Integer contextId, Boolean returnByValue, Boolean generatePreview, Boolean userGesture, Boolean awaitPromise, Boolean throwOnSideEffect, Double timeout, Boolean disableBreaks, Boolean replMode, Boolean allowUnsafeEvalBlockedByCSP, String uniqueContextId, Boolean generateWebDriverValue) Evaluates expression on global object.- Parameters:
expression
- Expression to evaluate.objectGroup
- Symbolic group name that can be used to release multiple objects.includeCommandLineAPI
- Determines whether Command Line API should be available during the evaluation.silent
- In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.contextId
- 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.returnByValue
- Whether the result is expected to be a JSON object that should be sent by value.generatePreview
- Whether preview should be generated for the result.userGesture
- Whether execution should be treated as initiated by user in the UI.awaitPromise
- Whether execution should await for resulting value and return once awaited promise is resolved.throwOnSideEffect
- Whether to throw an exception if side effect cannot be ruled out during evaluation. This implies disableBreaks below.timeout
- Terminate execution after timing out (number of milliseconds).disableBreaks
- Disable breakpoints during execution.replMode
- 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.allowUnsafeEvalBlockedByCSP
- 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.uniqueContextId
- 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.generateWebDriverValue
- Whether the result should be serialized according to https://w3c.github.io/webdriver-bidi.- Returns:
- EvaluateResult
-
getExceptionDetails
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.- Parameters:
errorObjectId
- The error object for which to resolve the exception details.
-
getHeapUsage
CompletableFuture<GetHeapUsageResult> getHeapUsage()Returns the JavaScript heap usage. It is the total usage of the corresponding isolate not scoped to a particular Runtime.- Returns:
- GetHeapUsageResult
-
getIsolateId
CompletableFuture<String> getIsolateId()Returns the isolate id.- Returns:
- The isolate id.
-
getProperties
Returns properties of a given object. Object group of the result is inherited from the target object.- Parameters:
objectId
- Identifier of the object to return properties for.- Returns:
- GetPropertiesResult
-
getProperties
CompletableFuture<GetPropertiesResult> getProperties(String objectId, Boolean ownProperties, Boolean accessorPropertiesOnly, Boolean generatePreview, Boolean nonIndexedPropertiesOnly) Returns properties of a given object. Object group of the result is inherited from the target object.- Parameters:
objectId
- Identifier of the object to return properties for.ownProperties
- If true, returns properties belonging only to the element itself, not to its prototype chain.accessorPropertiesOnly
- If true, returns accessor properties (with getter/setter) only; internal properties are not returned either.generatePreview
- Whether preview should be generated for the results.nonIndexedPropertiesOnly
- If true, returns non-indexed properties only.- Returns:
- GetPropertiesResult
-
globalLexicalScopeNames
CompletableFuture<List<String>> globalLexicalScopeNames()Returns all let, const and class variables from global scope. -
globalLexicalScopeNames
Returns all let, const and class variables from global scope.- Parameters:
executionContextId
- Specifies in which execution context to lookup global scope variables.
-
queryObjects
-
queryObjects
-
releaseObject
Releases remote object with given id.- Parameters:
objectId
- Identifier of the object to release.
-
releaseObjectGroup
Releases all remote objects that belong to a given group.- Parameters:
objectGroup
- Symbolic object group name.
-
removeBinding
This method does not remove binding function from global object but unsubscribes current runtime agent from Runtime.bindingCalled notifications. -
runIfWaitingForDebugger
CompletableFuture<Void> runIfWaitingForDebugger()Tells inspected instance to run if it was waiting for debugger to attach. -
runScript
Runs script with given id in a given context.- Parameters:
scriptId
- Id of the script to run.- Returns:
- RunScriptResult
-
runScript
CompletableFuture<RunScriptResult> runScript(String scriptId, Integer executionContextId, String objectGroup, Boolean silent, Boolean includeCommandLineAPI, Boolean returnByValue, Boolean generatePreview, Boolean awaitPromise) Runs script with given id in a given context.- Parameters:
scriptId
- Id of the script to run.executionContextId
- 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.objectGroup
- Symbolic group name that can be used to release multiple objects.silent
- In silent mode exceptions thrown during evaluation are not reported and do not pause execution. Overrides setPauseOnException state.includeCommandLineAPI
- Determines whether Command Line API should be available during the evaluation.returnByValue
- Whether the result is expected to be a JSON object which should be sent by value.generatePreview
- Whether preview should be generated for the result.awaitPromise
- Whether execution should await for resulting value and return once awaited promise is resolved.- Returns:
- RunScriptResult
-
setAsyncCallStackDepth
Enables or disables async call stacks tracking.- Parameters:
maxDepth
- Maximum depth of async call stacks. Setting to 0 will effectively disable collecting async call stacks (default).
-
setCustomObjectFormatterEnabled
-
setMaxCallStackSizeToCapture
-
terminateExecution
CompletableFuture<Void> terminateExecution()Terminate current or next JavaScript execution. Will cancel the termination when the outer-most script execution ends.
-