// Copyright © 2020 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
namespace CefSharp.DevTools.Runtime
{
using System.Linq;
///
/// 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.
///
public partial class Runtime : DevToolsDomainBase
{
private CefSharp.DevTools.IDevToolsClient _client;
public Runtime(CefSharp.DevTools.IDevToolsClient client)
{
_client = (client);
}
partial void ValidateAwaitPromise(string promiseObjectId, bool? returnByValue = null, bool? generatePreview = null);
///
/// Add handler to promise with given promise object id.
///
/// Identifier of the promise.
/// Whether the result is expected to be a JSON object that should be sent by value.
/// Whether preview should be generated for the result.
/// returns System.Threading.Tasks.Task<AwaitPromiseResponse>
public async System.Threading.Tasks.Task AwaitPromiseAsync(string promiseObjectId, bool? returnByValue = null, bool? generatePreview = null)
{
ValidateAwaitPromise(promiseObjectId, returnByValue, generatePreview);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("promiseObjectId", promiseObjectId);
if (returnByValue.HasValue)
{
dict.Add("returnByValue", returnByValue.Value);
}
if (generatePreview.HasValue)
{
dict.Add("generatePreview", generatePreview.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.awaitPromise", dict);
return methodResult.DeserializeJson();
}
partial void ValidateCallFunctionOn(string functionDeclaration, string objectId = null, System.Collections.Generic.IList arguments = null, bool? silent = null, bool? returnByValue = null, bool? generatePreview = null, bool? userGesture = null, bool? awaitPromise = null, int? executionContextId = null, string objectGroup = null);
///
/// Calls function with given declaration on the given object. Object group of the result is
/// inherited from the target object.
///
/// Declaration of the function to call.
/// Identifier of the object to call function on. Either objectId or executionContextId shouldbe specified.
/// Call arguments. All call arguments must belong to the same JavaScript world as the targetobject.
/// In silent mode exceptions thrown during evaluation are not reported and do not pauseexecution. Overrides `setPauseOnException` state.
/// Whether the result is expected to be a JSON object which should be sent by value.
/// Whether preview should be generated for the result.
/// Whether execution should be treated as initiated by user in the UI.
/// Whether execution should `await` for resulting value and return once awaited promise isresolved.
/// Specifies execution context which global object will be used to call function on. EitherexecutionContextId or objectId should be specified.
/// Symbolic group name that can be used to release multiple objects. If objectGroup is notspecified and objectId is, objectGroup will be inherited from object.
/// returns System.Threading.Tasks.Task<CallFunctionOnResponse>
public async System.Threading.Tasks.Task CallFunctionOnAsync(string functionDeclaration, string objectId = null, System.Collections.Generic.IList arguments = null, bool? silent = null, bool? returnByValue = null, bool? generatePreview = null, bool? userGesture = null, bool? awaitPromise = null, int? executionContextId = null, string objectGroup = null)
{
ValidateCallFunctionOn(functionDeclaration, objectId, arguments, silent, returnByValue, generatePreview, userGesture, awaitPromise, executionContextId, objectGroup);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("functionDeclaration", functionDeclaration);
if (!(string.IsNullOrEmpty(objectId)))
{
dict.Add("objectId", objectId);
}
if ((arguments) != (null))
{
dict.Add("arguments", arguments.Select(x => x.ToDictionary()));
}
if (silent.HasValue)
{
dict.Add("silent", silent.Value);
}
if (returnByValue.HasValue)
{
dict.Add("returnByValue", returnByValue.Value);
}
if (generatePreview.HasValue)
{
dict.Add("generatePreview", generatePreview.Value);
}
if (userGesture.HasValue)
{
dict.Add("userGesture", userGesture.Value);
}
if (awaitPromise.HasValue)
{
dict.Add("awaitPromise", awaitPromise.Value);
}
if (executionContextId.HasValue)
{
dict.Add("executionContextId", executionContextId.Value);
}
if (!(string.IsNullOrEmpty(objectGroup)))
{
dict.Add("objectGroup", objectGroup);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.callFunctionOn", dict);
return methodResult.DeserializeJson();
}
partial void ValidateCompileScript(string expression, string sourceURL, bool persistScript, int? executionContextId = null);
///
/// Compiles expression.
///
/// Expression to compile.
/// Source url to be set for the script.
/// Specifies whether the compiled script should be persisted.
/// Specifies in which execution context to perform script run. If the parameter is omitted theevaluation will be performed in the context of the inspected page.
/// returns System.Threading.Tasks.Task<CompileScriptResponse>
public async System.Threading.Tasks.Task CompileScriptAsync(string expression, string sourceURL, bool persistScript, int? executionContextId = null)
{
ValidateCompileScript(expression, sourceURL, persistScript, executionContextId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("expression", expression);
dict.Add("sourceURL", sourceURL);
dict.Add("persistScript", persistScript);
if (executionContextId.HasValue)
{
dict.Add("executionContextId", executionContextId.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.compileScript", dict);
return methodResult.DeserializeJson();
}
///
/// Disables reporting of execution contexts creation.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DisableAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.disable", dict);
return methodResult;
}
///
/// Discards collected exceptions and console API calls.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task DiscardConsoleEntriesAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.discardConsoleEntries", dict);
return methodResult;
}
///
/// 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.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task EnableAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.enable", dict);
return methodResult;
}
partial void ValidateEvaluate(string expression, string objectGroup = null, bool? includeCommandLineAPI = null, bool? silent = null, int? contextId = null, bool? returnByValue = null, bool? generatePreview = null, bool? userGesture = null, bool? awaitPromise = null, bool? throwOnSideEffect = null, long? timeout = null, bool? disableBreaks = null, bool? replMode = null, bool? allowUnsafeEvalBlockedByCSP = null);
///
/// Evaluates expression on global object.
///
/// Expression to evaluate.
/// Symbolic group name that can be used to release multiple objects.
/// Determines whether Command Line API should be available during the evaluation.
/// In silent mode exceptions thrown during evaluation are not reported and do not pauseexecution. Overrides `setPauseOnException` state.
/// Specifies in which execution context to perform evaluation. If the parameter is omitted theevaluation will be performed in the context of the inspected page.
/// Whether the result is expected to be a JSON object that should be sent by value.
/// Whether preview should be generated for the result.
/// Whether execution should be treated as initiated by user in the UI.
/// Whether execution should `await` for resulting value and return once awaited promise isresolved.
/// Whether to throw an exception if side effect cannot be ruled out during evaluation.This implies `disableBreaks` below.
/// Terminate execution after timing out (number of milliseconds).
/// Disable breakpoints during execution.
/// 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.
/// 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 thisevaluation and allows unsafe-eval. Defaults to true.
/// returns System.Threading.Tasks.Task<EvaluateResponse>
public async System.Threading.Tasks.Task EvaluateAsync(string expression, string objectGroup = null, bool? includeCommandLineAPI = null, bool? silent = null, int? contextId = null, bool? returnByValue = null, bool? generatePreview = null, bool? userGesture = null, bool? awaitPromise = null, bool? throwOnSideEffect = null, long? timeout = null, bool? disableBreaks = null, bool? replMode = null, bool? allowUnsafeEvalBlockedByCSP = null)
{
ValidateEvaluate(expression, objectGroup, includeCommandLineAPI, silent, contextId, returnByValue, generatePreview, userGesture, awaitPromise, throwOnSideEffect, timeout, disableBreaks, replMode, allowUnsafeEvalBlockedByCSP);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("expression", expression);
if (!(string.IsNullOrEmpty(objectGroup)))
{
dict.Add("objectGroup", objectGroup);
}
if (includeCommandLineAPI.HasValue)
{
dict.Add("includeCommandLineAPI", includeCommandLineAPI.Value);
}
if (silent.HasValue)
{
dict.Add("silent", silent.Value);
}
if (contextId.HasValue)
{
dict.Add("contextId", contextId.Value);
}
if (returnByValue.HasValue)
{
dict.Add("returnByValue", returnByValue.Value);
}
if (generatePreview.HasValue)
{
dict.Add("generatePreview", generatePreview.Value);
}
if (userGesture.HasValue)
{
dict.Add("userGesture", userGesture.Value);
}
if (awaitPromise.HasValue)
{
dict.Add("awaitPromise", awaitPromise.Value);
}
if (throwOnSideEffect.HasValue)
{
dict.Add("throwOnSideEffect", throwOnSideEffect.Value);
}
if (timeout.HasValue)
{
dict.Add("timeout", timeout.Value);
}
if (disableBreaks.HasValue)
{
dict.Add("disableBreaks", disableBreaks.Value);
}
if (replMode.HasValue)
{
dict.Add("replMode", replMode.Value);
}
if (allowUnsafeEvalBlockedByCSP.HasValue)
{
dict.Add("allowUnsafeEvalBlockedByCSP", allowUnsafeEvalBlockedByCSP.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.evaluate", dict);
return methodResult.DeserializeJson();
}
///
/// Returns the isolate id.
///
/// returns System.Threading.Tasks.Task<GetIsolateIdResponse>
public async System.Threading.Tasks.Task GetIsolateIdAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.getIsolateId", dict);
return methodResult.DeserializeJson();
}
///
/// Returns the JavaScript heap usage.
/// It is the total usage of the corresponding isolate not scoped to a particular Runtime.
///
/// returns System.Threading.Tasks.Task<GetHeapUsageResponse>
public async System.Threading.Tasks.Task GetHeapUsageAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.getHeapUsage", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGetProperties(string objectId, bool? ownProperties = null, bool? accessorPropertiesOnly = null, bool? generatePreview = null);
///
/// Returns properties of a given object. Object group of the result is inherited from the target
/// object.
///
/// Identifier of the object to return properties for.
/// If true, returns properties belonging only to the element itself, not to its prototypechain.
/// If true, returns accessor properties (with getter/setter) only; internal properties are notreturned either.
/// Whether preview should be generated for the results.
/// returns System.Threading.Tasks.Task<GetPropertiesResponse>
public async System.Threading.Tasks.Task GetPropertiesAsync(string objectId, bool? ownProperties = null, bool? accessorPropertiesOnly = null, bool? generatePreview = null)
{
ValidateGetProperties(objectId, ownProperties, accessorPropertiesOnly, generatePreview);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("objectId", objectId);
if (ownProperties.HasValue)
{
dict.Add("ownProperties", ownProperties.Value);
}
if (accessorPropertiesOnly.HasValue)
{
dict.Add("accessorPropertiesOnly", accessorPropertiesOnly.Value);
}
if (generatePreview.HasValue)
{
dict.Add("generatePreview", generatePreview.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.getProperties", dict);
return methodResult.DeserializeJson();
}
partial void ValidateGlobalLexicalScopeNames(int? executionContextId = null);
///
/// Returns all let, const and class variables from global scope.
///
/// Specifies in which execution context to lookup global scope variables.
/// returns System.Threading.Tasks.Task<GlobalLexicalScopeNamesResponse>
public async System.Threading.Tasks.Task GlobalLexicalScopeNamesAsync(int? executionContextId = null)
{
ValidateGlobalLexicalScopeNames(executionContextId);
var dict = new System.Collections.Generic.Dictionary();
if (executionContextId.HasValue)
{
dict.Add("executionContextId", executionContextId.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.globalLexicalScopeNames", dict);
return methodResult.DeserializeJson();
}
partial void ValidateQueryObjects(string prototypeObjectId, string objectGroup = null);
///
/// QueryObjects
///
/// Identifier of the prototype to return objects for.
/// Symbolic group name that can be used to release the results.
/// returns System.Threading.Tasks.Task<QueryObjectsResponse>
public async System.Threading.Tasks.Task QueryObjectsAsync(string prototypeObjectId, string objectGroup = null)
{
ValidateQueryObjects(prototypeObjectId, objectGroup);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("prototypeObjectId", prototypeObjectId);
if (!(string.IsNullOrEmpty(objectGroup)))
{
dict.Add("objectGroup", objectGroup);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.queryObjects", dict);
return methodResult.DeserializeJson();
}
partial void ValidateReleaseObject(string objectId);
///
/// Releases remote object with given id.
///
/// Identifier of the object to release.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ReleaseObjectAsync(string objectId)
{
ValidateReleaseObject(objectId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("objectId", objectId);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.releaseObject", dict);
return methodResult;
}
partial void ValidateReleaseObjectGroup(string objectGroup);
///
/// Releases all remote objects that belong to a given group.
///
/// Symbolic object group name.
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task ReleaseObjectGroupAsync(string objectGroup)
{
ValidateReleaseObjectGroup(objectGroup);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("objectGroup", objectGroup);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.releaseObjectGroup", dict);
return methodResult;
}
///
/// Tells inspected instance to run if it was waiting for debugger to attach.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task RunIfWaitingForDebuggerAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.runIfWaitingForDebugger", dict);
return methodResult;
}
partial void ValidateRunScript(string scriptId, int? executionContextId = null, string objectGroup = null, bool? silent = null, bool? includeCommandLineAPI = null, bool? returnByValue = null, bool? generatePreview = null, bool? awaitPromise = null);
///
/// Runs script with given id in a given context.
///
/// Id of the script to run.
/// Specifies in which execution context to perform script run. If the parameter is omitted theevaluation will be performed in the context of the inspected page.
/// Symbolic group name that can be used to release multiple objects.
/// In silent mode exceptions thrown during evaluation are not reported and do not pauseexecution. Overrides `setPauseOnException` state.
/// Determines whether Command Line API should be available during the evaluation.
/// Whether the result is expected to be a JSON object which should be sent by value.
/// Whether preview should be generated for the result.
/// Whether execution should `await` for resulting value and return once awaited promise isresolved.
/// returns System.Threading.Tasks.Task<RunScriptResponse>
public async System.Threading.Tasks.Task RunScriptAsync(string scriptId, int? executionContextId = null, string objectGroup = null, bool? silent = null, bool? includeCommandLineAPI = null, bool? returnByValue = null, bool? generatePreview = null, bool? awaitPromise = null)
{
ValidateRunScript(scriptId, executionContextId, objectGroup, silent, includeCommandLineAPI, returnByValue, generatePreview, awaitPromise);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("scriptId", scriptId);
if (executionContextId.HasValue)
{
dict.Add("executionContextId", executionContextId.Value);
}
if (!(string.IsNullOrEmpty(objectGroup)))
{
dict.Add("objectGroup", objectGroup);
}
if (silent.HasValue)
{
dict.Add("silent", silent.Value);
}
if (includeCommandLineAPI.HasValue)
{
dict.Add("includeCommandLineAPI", includeCommandLineAPI.Value);
}
if (returnByValue.HasValue)
{
dict.Add("returnByValue", returnByValue.Value);
}
if (generatePreview.HasValue)
{
dict.Add("generatePreview", generatePreview.Value);
}
if (awaitPromise.HasValue)
{
dict.Add("awaitPromise", awaitPromise.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.runScript", dict);
return methodResult.DeserializeJson();
}
partial void ValidateSetAsyncCallStackDepth(int maxDepth);
///
/// Enables or disables async call stacks tracking.
///
/// Maximum depth of async call stacks. Setting to `0` will effectively disable collecting asynccall stacks (default).
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetAsyncCallStackDepthAsync(int maxDepth)
{
ValidateSetAsyncCallStackDepth(maxDepth);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("maxDepth", maxDepth);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.setAsyncCallStackDepth", dict);
return methodResult;
}
partial void ValidateSetCustomObjectFormatterEnabled(bool enabled);
///
/// SetCustomObjectFormatterEnabled
///
/// enabled
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetCustomObjectFormatterEnabledAsync(bool enabled)
{
ValidateSetCustomObjectFormatterEnabled(enabled);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("enabled", enabled);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.setCustomObjectFormatterEnabled", dict);
return methodResult;
}
partial void ValidateSetMaxCallStackSizeToCapture(int size);
///
/// SetMaxCallStackSizeToCapture
///
/// size
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task SetMaxCallStackSizeToCaptureAsync(int size)
{
ValidateSetMaxCallStackSizeToCapture(size);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("size", size);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.setMaxCallStackSizeToCapture", dict);
return methodResult;
}
///
/// Terminate current or next JavaScript execution.
/// Will cancel the termination when the outer-most script execution ends.
///
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task TerminateExecutionAsync()
{
System.Collections.Generic.Dictionary dict = null;
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.terminateExecution", dict);
return methodResult;
}
partial void ValidateAddBinding(string name, int? executionContextId = null);
///
/// 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.
///
/// name
/// executionContextId
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task AddBindingAsync(string name, int? executionContextId = null)
{
ValidateAddBinding(name, executionContextId);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("name", name);
if (executionContextId.HasValue)
{
dict.Add("executionContextId", executionContextId.Value);
}
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.addBinding", dict);
return methodResult;
}
partial void ValidateRemoveBinding(string name);
///
/// This method does not remove binding function from global object but
/// unsubscribes current runtime agent from Runtime.bindingCalled notifications.
///
/// name
/// returns System.Threading.Tasks.Task<DevToolsMethodResponse>
public async System.Threading.Tasks.Task RemoveBindingAsync(string name)
{
ValidateRemoveBinding(name);
var dict = new System.Collections.Generic.Dictionary();
dict.Add("name", name);
var methodResult = await _client.ExecuteDevToolsMethodAsync("Runtime.removeBinding", dict);
return methodResult;
}
}
}