Runtime
Runtime 领域通过远程评估和镜像对象的方式暴露 JavaScript 运行时环境。评估结果以镜像对象的形式返回,这些镜像对象会公开对象的类型、字符串表示形式以及可用于进一步对象引用的唯一标识符。原始对象会保留在内存中,除非它们被显式释放,或者与其对象组中的其他对象一同被释放。
EN
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.
✅️️ Methods
🔨Runtime.addBinding
如果executionContextId为空,则会在所有被检查上下文的全局对象上添加具有给定名称的绑定,包括后续创建的上下文,且绑定在页面重新加载后依然有效。绑定函数仅接受一个参数,该参数应为字符串类型,若输入其他类型,函数将抛出异常。每次调用绑定函数都会产生Runtime.bindingCalled通知。
EN
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.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string | |||
| executionContextId | 🧪 | ExecutionContextId | 如果 指定,绑定将仅对指定的执行上下文暴露。如果省略且未设置 executionContextName,则绑定将对目标的所有执行上下文暴露。此参数与 executionContextName 互斥。由于使用场景不明确及实现中存在缺陷(crbug.com/1169639),现已被 executionContextName 取代。executionContextId 将在未来被移除。 | ENIf specified, the binding would only be exposed to the specified execution context. If omitted andexecutionContextName 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 | string | 如果指定,该绑定将暴露给具有匹配名称的执行上下文,即使是在绑定添加后创建的上下文。另请参阅 ExecutionContext.name 和 Page.addScriptToEvaluateOnNewDocument 的 worldName 参数。此参数与 executionContextId 互斥。 | ENIf specified, the binding is exposed to the executionContext with matching name, even for contexts created after the binding is added. See alsoExecutionContext.name and worldName parameter to Page.addScriptToEvaluateOnNewDocument. This parameter is mutually exclusive with executionContextId. |
🔨Runtime.awaitPromise
为具有给定Promise对象ID的Promise添加处理程序。
EN
Add handler to promise with given promise object id.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| promiseObjectId | ✔️ | RemoteObjectId | promise的标识符。 | ENIdentifier of the promise. | |
| returnByValue | boolean | 结果是否预期为一个应通过值发送的JSON对象。 | ENWhether the result is expected to be a JSON object that should be sent by value. | ||
| generatePreview | boolean | 是否应为结果生成预览。 | ENWhether preview should be generated for the result. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | RemoteObject | Promise result. 如果 promise 被拒绝,将包含被拒绝的值。 | ENPromise result. Will contain rejected value if promise was rejected. |
| exceptionDetails | ExceptionDetails | 如果堆栈跟踪可用,则提供异常详细信息。 | ENException details if stack strace is available. |
🔨Runtime.callFunctionOn
在给定对象上调用具有指定声明的函数。结果的所属对象组继承自目标对象。
EN
Calls function with given declaration on the given object. Object group of the result is inherited from the target object.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| functionDeclaration | ✔️ | string | 声明要调用的函数。 | ENDeclaration of the function to call. | |
| objectId | RemoteObjectId | 调用函数的对象标识符。必须指定 objectId 或 executionContextId 中的一个。 | ENIdentifier of the object to call function on. Either objectId or executionContextId should be specified. | ||
| arguments | array[CallArgument] | 调用参数。所有调用参数必须与目标对象属于同一个JavaScript世界。 | ENCall arguments. All call arguments must belong to the same JavaScript world as the target object. | ||
| silent | boolean | 在静默模式下,评估期间抛出的异常不会被报告,也不会暂停执行。这会覆盖 setPauseOnException 的状态。 | ENIn silent mode exceptions thrown during evaluation are not reported and do not pause execution. OverridessetPauseOnException state. | ||
| returnByValue | boolean | 结果是否预期为一个应通过值传递的JSON对象。可通过serializationOptions覆盖此设置。 | ENWhether the result is expected to be a JSON object which should be sent by value. Can be overriden byserializationOptions. | ||
| generatePreview | 🧪 | boolean | 是否应为结果生成预览。 | ENWhether preview should be generated for the result. | |
| userGesture | boolean | 是否应将执行视为由用户在界面中发起。 | ENWhether execution should be treated as initiated by user in the UI. | ||
| awaitPromise | boolean | 执行是否应该await结果值,并在等待的Promise解析后返回。 | ENWhether execution shouldawait for resulting value and return once awaited promise is resolved. | ||
| executionContextId | ExecutionContextId | 指定执行上下文,其全局对象将用于调用函数。必须指定 executionContextId 或 objectId 之一。 | ENSpecifies execution context which global object will be used to call function on. Either executionContextId or objectId should be specified. | ||
| objectGroup | string | 可用于释放多个对象的符号化组名。如果未指定objectGroup但指定了objectId,则objectGroup将从对象继承。 | ENSymbolic 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 | 🧪 | boolean | 是否在评估过程中无法排除副作用时抛出异常。 | ENWhether to throw an exception if side effect cannot be ruled out during evaluation. | |
| uniqueContextId | 🧪 | string | 一种指定执行上下文以调用函数的替代方式。与可能在进程间重复使用的contextId相比,这种方式保证系统唯一性,因此可用于防止在非预期上下文中意外调用函数(例如因跨进程导航导致的情况)。此方式与executionContextId互斥。 | ENAn 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 withexecutionContextId. | |
| serializationOptions | 🧪 | SerializationOptions | 指定结果序列化方式。如果提供,将覆盖 generatePreview 和 returnByValue。 | ENSpecifies the result serialization. If provided, overridesgeneratePreview and returnByValue. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | RemoteObject | 调用结果。 | ENCall result. |
| exceptionDetails | ExceptionDetails | 异常详情。 | ENException details. |
🔨Runtime.compileScript
编译表达式。
EN
Compiles expression.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| expression | ✔️ | string | 要编译的表达式。 | ENExpression to compile. | |
| sourceURL | ✔️ | string | 脚本的源URL将被设置。 | ENSource url to be set for the script. | |
| persistScript | ✔️ | boolean | 指定是否应持久化已编译的脚本。 | ENSpecifies whether the compiled script should be persisted. | |
| executionContextId | ExecutionContextId | 指定在哪个执行上下文中运行脚本。如果省略该参数,则将在被检查页面的上下文中执行评估。 | ENSpecifies 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. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| scriptId | ScriptId | 脚本的ID。 | ENId of the script. |
| exceptionDetails | ExceptionDetails | 异常详情。 | ENException details. |
🔨Runtime.disable
禁用执行上下文创建的报告。
EN
Disables reporting of execution contexts creation.
🔨Runtime.discardConsoleEntries
丢弃已收集的异常和''console API''调用。
EN
Discards collected exceptions and console API calls.
🔨Runtime.enable
启用通过executionContextCreated事件报告执行上下文创建的功能。当启用报告时,该事件将立即为每个现有的执行上下文发送。
EN
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.🔨Runtime.evaluate
在全局对象上评估表达式。
EN
Evaluates expression on global object.
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| expression | ✔️ | string | 要评估的表达式。 | ENExpression to evaluate. | |
| objectGroup | string | 可用于释放多个对象的符号组名称。 | ENSymbolic group name that can be used to release multiple objects. | ||
| includeCommandLineAPI | boolean | 确定在评估期间是否应提供命令行API。 | ENDetermines whether Command Line API should be available during the evaluation. | ||
| silent | boolean | 在静默模式下,评估期间抛出的异常不会被报告,也不会暂停执行。这会覆盖 setPauseOnException 的状态。 | ENIn silent mode exceptions thrown during evaluation are not reported and do not pause execution. OverridessetPauseOnException state. | ||
| contextId | ExecutionContextId | 指定在哪个执行上下文中进行评估。如果省略该参数,则评估将在被检查页面的上下文中执行。这与uniqueContextId互斥,后者提供了一种在多进程环境中更可靠的识别执行上下文的方法。 | ENSpecifies 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 withuniqueContextId, which offers an alternative way to identify the execution context that is more reliable in a multi-process environment. | ||
| returnByValue | boolean | 结果是否预期为一个应通过值传递的JSON对象。 | ENWhether the result is expected to be a JSON object that should be sent by value. | ||
| generatePreview | 🧪 | boolean | 是否应为结果生成预览。 | ENWhether preview should be generated for the result. | |
| userGesture | boolean | 是否应将执行视为由用户在UI中发起。 | ENWhether execution should be treated as initiated by user in the UI. | ||
| awaitPromise | boolean | 执行是否应该await结果值,并在等待的承诺解析后返回。 | ENWhether execution shouldawait for resulting value and return once awaited promise is resolved. | ||
| throwOnSideEffect | 🧪 | boolean | 是否在评估期间无法排除副作用时抛出异常。这隐含了下面的 disableBreaks。 | ENWhether to throw an exception if side effect cannot be ruled out during evaluation. This impliesdisableBreaks below. | |
| timeout | 🧪 | TimeDelta | 在超时(毫秒数)后终止执行。 | ENTerminate execution after timing out (number of milliseconds). | |
| disableBreaks | 🧪 | boolean | 在执行期间禁用断点。 | ENDisable breakpoints during execution. | |
| replMode | 🧪 | boolean | 将此标志设为 true 可启用 let 重声明和顶层 await。请注意,仅当 let 变量本身源自 replMode 时才能进行重声明。 | ENSetting this flag to true enableslet re-declaration and top-level await. Note that let variables can only be re-declared if they originate from replMode themselves. | |
| allowUnsafeEvalBlockedByCSP | 🧪 | boolean | 目标的内容安全策略(CSP)可能会阻止'unsafe-eval',这包括使用不可调用参数调用时的eval()、Function()、setTimeout()和setInterval()。此标志会绕过CSP以进行此评估,并允许unsafe-eval。默认为true。 | ENThe 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 | 🧪 | string | 指定执行上下文的另一种方式。与可能在多个进程间重复使用的contextId相比,这种方式保证系统唯一性,因此可用于防止表达式在非预期上下文中意外执行(例如因跨进程导航导致的情况)。此方式与contextId |