Runtime
Runtime 领域通过远程评估和镜像对象的方式暴露 JavaScript 运行时环境。评估结果以镜像对象的形式返回,这些镜像对象会公开对象的 类型、字符串表示形式以及可用于进一步对象引用的唯一标识符。原始对象会保留在内存中,除非它们被显式释放,或者与其对象组中的其他对象一同被释放。
EN
✅️️ Methods
🔨Runtime.addBinding
如果executionContextId为空,则会在所有被检查上下文的全局对象上添加具有给定名称的绑定,包括后续创建的上下文,且绑定在页面重新加载后依然有效。绑定函数仅接受一个参数,该参数应为字符串类型,若输入其他类型,函数将抛出异常。每次调用绑定函数都会产生Runtime.bindingCalled通知。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| 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
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| 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
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| 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
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| 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
🔨Runtime.discardConsoleEntries
丢弃已收集的异常和''console API''调用。
EN
🔨Runtime.enable
启用通过executionContextCreated事件报告执行上下文创建的功能。当启用报告时,该事件将立即为每个现有的执行上下文发送。
EN
executionContextCreated event. When the reporting gets enabled the event will be sent immediately for each existing execution context.🔨Runtime.evaluate
在全局对象上评估表达式。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| 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互斥。 | ENAn 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 withcontextId. | |
| serializationOptions | 🧪 | SerializationOptions | 指定结果序列化方式。如果提供,将覆盖 generatePreview 和 returnByValue。 | ENSpecifies the result serialization. If provided, overridesgeneratePreview and returnByValue. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | RemoteObject | 评估结果。 | ENEvaluation result. |
| exceptionDetails | ExceptionDetails | 异常详情。 | ENException details. |
🔨Runtime.getProperties
返回给定对象的属性。结果的所属对象组继承自目标对象。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| objectId | ✔️ | RemoteObjectId | 返回属性的对象标识符。 | ENIdentifier of the object to return properties for. | |
| ownProperties | boolean | 如果为真,则仅返回元素自身的属性,不包括其原型链中的属性。 | ENIf true, returns properties belonging only to the element itself, not to its prototype chain. | ||
| accessorPropertiesOnly | 🧪 | boolean | 如果为真,则仅返回访问器属性(带有getter/setter);内部属性也不会被返回。 | ENIf true, returns accessor properties (with getter/setter) only; internal properties are not returned either. | |
| generatePreview | 🧪 | boolean | 是否应为结果生成预览。 | ENWhether preview should be generated for the results. | |
| nonIndexedPropertiesOnly | 🧪 | boolean | 如果为真,则仅返回非索引属性。 | ENIf true, returns non-indexed properties only. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | array[PropertyDescriptor] | 对象属性。 | ENObject properties. |
| internalProperties | array[InternalPropertyDescriptor] | 内部对象属性(仅限元素本身)。 | ENInternal object properties (only of the element itself). |
| privateProperties | array[PrivatePropertyDescriptor] | 对象私有属性。 | ENObject private properties. |
| exceptionDetails | ExceptionDetails | 异常详情。 | ENException details. |
🔨Runtime.globalLexicalScopeNames
返回全局作用域中所有的let、const和class变量。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| executionContextId | ExecutionContextId | 指定在哪个执行上下文中查找全局作用域变量。 | ENSpecifies in which execution context to lookup global scope variables. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| names | array[string] |
🔨Runtime.queryObjects
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| prototypeObjectId | ✔️ | RemoteObjectId | 返回对象的原型标识符。 | ENIdentifier of the prototype to return objects for. | |
| objectGroup | string | 可用于释放结果的符号组名称。 | ENSymbolic group name that can be used to release the results. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| objects | RemoteObject | 包含对象的数组。 | ENArray with objects. |
🔨Runtime.releaseObject
释放具有给定ID的远程对象。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| objectId | ✔️ | RemoteObjectId | 要释放的对象的标识符。 | ENIdentifier of the object to release. |
🔨Runtime.releaseObjectGroup
释放属于给定组的所有远程对象。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| objectGroup | ✔️ | string | 符号化对象组名称。 | ENSymbolic object group name. |
🔨Runtime.removeBinding
该方法不会从全局对象中移除绑定函数,而是取消当前运行时代理对Runtime.bindingCalled通知的订阅。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string |
🔨Runtime.runIfWaitingForDebugger
指示被检查的实例在等待调试器附加时运行。
EN
🔨Runtime.runScript
在给定的上下文中运行指定ID的脚本。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| scriptId | ✔️ | ScriptId | 要运行的脚本的Id。 | ENId of the script to run. | |
| 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. | ||
| objectGroup | string | 可用于释放多个对象的符号组名称。 | ENSymbolic group name that can be used to release multiple objects. | ||
| silent | boolean | 在静默模式下,评估期间抛出的异常不会被报告,也不会暂停执行。这会覆盖 setPauseOnException 状态。 | ENIn silent mode exceptions thrown during evaluation are not reported and do not pause execution. OverridessetPauseOnException state. | ||
| includeCommandLineAPI | boolean | 确定在评估期间是否应提供命令行API。 | ENDetermines whether Command Line API should be available during the evaluation. | ||
| returnByValue | boolean | 结果是否预期为一个JSON对象,该对象应通过值发送。 | ENWhether the result is expected to be a JSON object which should be sent by value. | ||
| generatePreview | boolean | 是否应为结果生成预览。 | ENWhether preview should be generated for the result. | ||
| awaitPromise | boolean | 执行是否应该 await 等待结果值,并在等待的 Promise 解析完成后返回。 | ENWhether execution shouldawait for resulting value and return once awaited promise is resolved. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | RemoteObject | 运行结果。 | ENRun result. |
| exceptionDetails | ExceptionDetails | 异常详情。 | ENException details. |
🔨Runtime.setAsyncCallStackDepth
启用或禁用异步调用堆栈跟踪。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| maxDepth | ✔️ | integer | 异步调用栈的最大深度。设置为 0 将有效禁用收集异步调用栈(默认)。 | ENMaximum depth of async call stacks. Setting to0 will effectively disable collecting async call stacks (default). |
🔨Runtime.getExceptionDetails🧪
此方法尝试查找并填充JavaScript Error对象的异常详情。请注意,只有当Error被抛出时Runtime域处于启用状态,生成的exceptionDetails中的stackTrace部分才会被填充。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| errorObjectId | ✔️ | RemoteObjectId | 解析异常详细信息的错误对象。 | ENThe error object for which to resolve the exception details. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| exceptionDetails | ExceptionDetails |
🔨Runtime.getHeapUsage🧪
返回JavaScript堆使用情况。这是对应隔离区的总使用量,不限定于特定的运行时。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| usedSize | number | 已使用的 JavaScript 堆大小(以字节为单位)。 | ENUsed JavaScript heap size in bytes. |
| totalSize | number | 已分配的 JavaScript 堆大小(以字节为单位)。 | ENAllocated JavaScript heap size in bytes. |
| embedderHeapUsedSize | number | 嵌入器垃圾回收堆中已使用的字节大小。 | ENUsed size in bytes in the embedder's garbage-collected heap. |
| backingStorageSize | number | 数组缓冲区和外部字符串后备存储的字节大小。 | ENSize in bytes of backing storage for array buffers and external strings. |
🔨Runtime.getIsolateId🧪
返回隔离ID。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| id | string | 隔离ID。 | ENThe isolate id. |
🔨Runtime.setCustomObjectFormatterEnabled🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | ✔️ | boolean |
🔨Runtime.setMaxCallStackSizeToCapture🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| size | ✔️ | integer |
🔨Runtime.terminateExecution🧪
终止当前或下一次JavaScript执行。当最外层的脚本执行结束时,将取消终止。
EN
✅️️ Events
👋Runtime.consoleAPICalled
当控制台API被调用时发出。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| type | ✔️ | string | 调用的类型。 允许的值: log、debug、info、error、warning、dir、dirxml、table、trace、clear、startGroup、startGroupCollapsed、endGroup、assert、profile、profileEnd、count、timeEnd | ENType of the call.Allowed Values: log, debug, info, error, warning, dir, dirxml, table, trace, clear, startGroup, startGroupCollapsed, endGroup, assert, profile, profileEnd, count, timeEnd | |
| args | ✔️ | array[RemoteObject] | 调用参数。 | ENCall arguments. | |
| executionContextId | ✔️ | ExecutionContextId | 调用发生所在的上下文标识符。 | ENIdentifier of the context where the call was made. | |
| timestamp | ✔️ | Timestamp | 调用时间戳。 | ENCall timestamp. | |
| stackTrace | StackTrace | 调用时捕获的堆栈跟踪。对于以下调用类型,异步堆栈链会自动报告:assert、error、trace、warning。对于其他类型,可以使用 Debugger.getStackTrace 和 stackTrace.parentId 字段来获取异步调用链。 | ENStack 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 using Debugger.getStackTrace and stackTrace.parentId field. | ||
| context | 🧪 | string | 非默认控制台上下文 (非 console.*)调用的控制台上下文描述符:对于未命名上下文的调用使用 'anonymous#unique-logger-id',对于命名上下文的调用使用 'name#unique-logger-id'。 | ENConsole context descriptor for calls on non-default console context (not console.*): 'anonymous#unique-logger-id' for call on unnamed context, 'name#unique-logger-id' for call on named context. |
👋Runtime.exceptionRevoked
当未处理的异常被撤销时发出。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| reason | ✔️ | string | 描述异常被撤销的原因。 | ENReason describing why exception was revoked. | |
| exceptionId | ✔️ | integer | 被撤销异常的ID,如 exceptionThrown 中报告。 | ENThe id of revoked exception, as reported inexceptionThrown. |
👋Runtime.exceptionThrown
当异常被抛出且未被处理时发出。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| timestamp | ✔️ | Timestamp | 异常的时间戳。 | ENTimestamp of the exception. | |
| exceptionDetails | ✔️ | ExceptionDetails |
👋Runtime.executionContextCreated
当新的执行上下文被创建时发出。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| context | ✔️ | ExecutionContextDescription | 一个新创建的''执行上下文''。 | ENA newly created execution context. |
👋Runtime.executionContextDestroyed
当执行上下文被销毁时发出。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| executionContextId | ✔️ | ❌️ | ExecutionContextId | 被销毁上下文的ID | ENId of the destroyed context |
| executionContextUniqueId | ✔️ | 🧪 | string | 被销毁上下文的唯一标识符 | ENUnique Id of the destroyed context |