Target
支持额外目标发现,并允许附加到这些目标。
EN
✅️️ Methods
🔨Target.activateTarget
激活(聚焦)目标。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID |
🔨Target.attachToTarget
附加到具有给定ID的目标。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID | |||
| flatten | boolean | 通过在命令中指定sessionId属性,启用对会话的"扁平化"访问。我们计划将此设为默认方式,弃用非扁平化模式,并最终将其淘汰。详情参见crbug.com/991325。 | ENEnables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| sessionId | SessionID | 分配给会话的Id。 | ENId assigned to the session. |
🔨Target.closeTarget
关闭目标。如果目标是页面,该页面也会被关闭。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| success | boolean | 始终设置为true。如果发生错误,响应将指示协议错误。 | ENAlways set to true. If an error occurs, the response indicates protocol error. |
🔨Target.createBrowserContext
创建一个新的空浏览器上下文。类似于无痕浏览模式,但您可以创建多个。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| disposeOnDetach | 🧪 | boolean | 如果指定,则在调试会话断开时释放此上下文。 | ENIf specified, disposes this context when debugging session disconnects. | |
| proxyServer | 🧪 | string | 代理服务器,类似于传递给 --proxy-server 的参数 | ENProxy server, similar to the one passed to --proxy-server | |
| proxyBypassList | 🧪 | string | 代理绕过列表,类似于传递给 --proxy-bypass-list 的列表 | ENProxy bypass list, similar to the one passed to --proxy-bypass-list | |
| originsWithUniversalNetworkAccess | 🧪 | array[string] | 授予无限跨域访问权限的可选来源列表。URL中除构成来源部分外的其他部分将被忽略。 | ENAn optional list of origins to grant unlimited cross-origin access to. Parts of the URL other than those constituting origin are ignored. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| browserContextId | Browser.BrowserContextID | 所创建上下文的id。 | ENThe id of the context created. |
🔨Target.createTarget
创建一个新页面。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| url | ✔️ | string | 页面初始导航的URL。空字符串表示about:blank。 | ENThe initial URL the page will be navigated to. An empty string indicates about:blank. | |
| left | 🧪 | integer | Frame left origin in DIP (requires newWindow to be true or headless shell). | ENFrame left origin in DIP (requires newWindow to be true or headless shell). | |
| top | 🧪 | integer | Frame top origin in DIP (requires newWindow to be true or headless shell). | ENFrame top origin in DIP (requires newWindow to be true or headless shell). | |
| width | integer | 帧宽度,以DIP为单位(需要newWindow为true或使用headless shell)。 | ENFrame width in DIP (requires newWindow to be true or headless shell). | ||
| height | integer | 帧高度,单位为DIP(需要将newWindow设置为true或使用headless shell)。 | ENFrame height in DIP (requires newWindow to be true or headless shell). | ||
| windowState | WindowState | 框架窗口状态(要求 newWindow 为 true 或处于无头模式)。默认为 normal。 | ENFrame window state (requires newWindow to be true or headless shell). Default is normal. | ||
| browserContextId | 🧪 | Browser.BrowserContextID | 在指定的浏览器上下文中创建页面。 | ENThe browser context to create the page in. | |
| enableBeginFrameControl | 🧪 | boolean | 此目标是否将通过DevTools控制BeginFrames(仅限无头模式,MacOS暂不支持,默认值为false)。 | ENWhether BeginFrames for this target will be controlled via DevTools (headless shell only, not supported on MacOS yet, false by default). | |
| newWindow | boolean | 是否创建新窗口或标签页(默认为 false,无头 shell 不支持)。 | ENWhether to create a new Window or Tab (false by default, not supported by headless shell). | ||
| background | boolean | 是否在后台或前台创建目标(默认为false,无头shell不支持)。 | ENWhether to create the target in background or foreground (false by default, not supported by headless shell). | ||
| forTab | 🧪 | boolean | 是否创建类型为"tab"的目标。 | ENWhether to create the target of type "tab". | |
| hidden | 🧪 | boolean | 是否创建隐藏 目标。隐藏目标可通过协议观察到,但不会出现在标签页UI条中。不能与 forTab: true、newWindow: true 或 background: false 同时使用。标签页的生命周期仅限于会话的生命周期。 | ENWhether to create a hidden target. The hidden target is observable via protocol, but not present in the tab UI strip. Cannot be created withforTab: true, newWindow: true or background: false. The life-time of the tab is limited to the life-time of the session. | |
| focus | 🧪 | boolean | 如果指定,该选项用于决定是否聚焦新目标。默认情况下,聚焦行为取决于background字段的值。例如,background=false和focus=false将导致目标标签页被打开但浏览器窗口保持不变(如果窗口原本处于后台,则保持后台状态),而background=false与focus=undefined将导致窗口获得焦点。不支持同时使用background: true和focus: true,否则将引发错误。 | ENIf specified, the option is used to determine if the new target should be focused or not. By default, the focus behavior depends on the value of the background field. For example, background=false and focus=false will result in the target tab being opened but the browser window remain unchanged (if it was in the background, it will remain in the background) and background=false with focus=undefined will result in the window being focused. Using background: true and focus: true is not supported and will result in an error. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| targetId | TargetID | 打开的页面的id。 | ENThe id of the page opened. |
🔨Target.detachFromTarget
分离具有给定ID的会话。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| sessionId | SessionID | 要分离的会话。 | ENSession to detach. | ||
| targetId | ❌️ | TargetID | 已弃用。 | ENDeprecated. |
🔨Target.disposeBrowserContext
删除一个浏览器上下文。所有属于该上下文的页面将被关闭,且不会调用它们的 beforeunload 钩子 。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| browserContextId | ✔️ | Browser.BrowserContextID |
🔨Target.getBrowserContexts
返回所有使用Target.createBrowserContext方法创建的浏览器上下文。
EN
Target.createBrowserContext method.| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| browserContextIds | array[Browser.BrowserContextID] | 一组浏览器上下文ID。 | ENAn array of browser context ids. |
| defaultBrowserContextId | Browser.BrowserContextID | 如果可用,默认浏览器上下文的id。 | ENThe id of the default browser context if available. |
🔨Target.getTargets
获取可用目标列表。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| filter | 🧪 | TargetFilter | 仅匹配筛选器的目标会被报告。如果未指定筛选器且当前启用了目标发现,则会使用用于目标发现的一致性筛选器。 | ENOnly targets matching filter will be reported. If filter is not specified and target discovery is currently enabled, a filter used for target discovery is used for consistency. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| targetInfos | array[TargetInfo] | 目标列表。 | ENThe list of targets. |
🔨Target.setAutoAttach
控制是否自动附加到被认为与此目标直接相关的新目标(例如,iframe或worker)。开启时,也会附加到所有现有的相关目标。关闭时,会自动从所有当前附加的目标中分离。这还会从监视相关目标创建的列表中清除所有由autoAttachRelated添加的目标。你可能希望对自动附加的目标递归调用此方法,以附加到所有可用目标。
EN
autoAttachRelated from the list of targets to watch for creation of related targets. You might want to call this recursively for auto-attached targets to attach to all available targets.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| autoAttach | ✔️ | boolean | 是否自动附加到相关目标。 | ENWhether to auto-attach to related targets. | |
| waitForDebuggerOnStart | ✔️ | boolean | 是否在附加 到新目标时暂停它们。使用 Runtime.runIfWaitingForDebugger 来运行已暂停的目标。 | ENWhether to pause new targets when attaching to them. UseRuntime.runIfWaitingForDebugger to run paused targets. | |
| flatten | 🧪 | boolean | 通过在命令中指定sessionId属性,实现对会话的"扁平化"访问。我们计划将此设为默认模式,弃用非扁平化模式,并最终将其移除。详情参见crbug.com/991325。 | ENEnables "flat" access to the session via specifying sessionId attribute in the commands. We plan to make this the default, deprecate non-flattened mode, and eventually retire it. See crbug.com/991325. | |
| filter | 🧪 | TargetFilter | 只有符合筛选条件的目标才会被附加。 | ENOnly targets matching filter will be attached. |
🔨Target.setDiscoverTargets
控制是否发现可用目标并通过targetCreated/targetInfoChanged/targetDestroyed事件进行通知。
EN
targetCreated/targetInfoChanged/targetDestroyed events.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| discover | ✔️ | boolean | 是否发现可用目标。 | ENWhether to discover available targets. | |
| filter | 🧪 | TargetFilter | 只有符合筛选条件的目标才会被附加。如果 discover 为 false,则必须省略 filter 或将其置空。 | ENOnly targets matching filter will be attached. Ifdiscover is false, filter must be omitted or empty. |
🔨Target.sendMessageToTarget❌️
通过指定会话ID发送协议消息。建议改用扁平模式;请参阅命令attachToTarget、setAutoAttach以及crbug.com/991325。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| message | ✔️ | string | |||
| sessionId | SessionID | 会话的标识符。 | ENIdentifier of the session. | ||
| targetId | ❌️ | TargetID | 已弃用。 | ENDeprecated. |
🔨Target.attachToBrowserTarget🧪
附加到浏览器目标,仅使用扁平化会话ID模式。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| sessionId | SessionID | 分配给会话的ID。 | ENId assigned to the session. |
🔨Target.autoAttachRelated🧪
将指定的目标添加到监视列表中,该列表会监控任何相关目标的创建(例如子框架、子工作线程和服务工作线程的新版本),并通过 attachedToTarget 事件进行报告。指定的目标也会被自动附加。此操作会取消之前任何 setAutoAttach 的效果,并且也会被后续的 setAutoAttach 取消。仅适用于浏览器目标。
EN
attachedToTarget. The specified target is also auto-attached. This cancels the effect of any previous setAutoAttach and is also cancelled by subsequent setAutoAttach. Only available at the Browser target.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID | |||
| waitForDebuggerOnStart | ✔️ | boolean | 是否在附加到新目标时暂停它们。使用 Runtime.runIfWaitingForDebugger 来运行已暂停的目标。 | ENWhether to pause new targets when attaching to them. UseRuntime.runIfWaitingForDebugger to run paused targets. | |
| filter | 🧪 | TargetFilter | 仅匹配筛选器的目标会被附加。 | ENOnly targets matching filter will be attached. |
🔨Target.exposeDevToolsProtocol🧪
向目标主框架注入一个对象,该对象提供与浏览器目标的通信通道。
注入的对象将作为 window[bindingName] 提供。
该对象具有以下 API:
- binding.send(json) - 通过远程调试协议发送消息的方法
- binding.onmessage = json => handleMessage(json) - 用于处理协议通知和命令响应的回调函数。
EN
Injected object will be available as
window[bindingName].The object has the following API:
-
binding.send(json) - a method to send messages over the remote debugging protocol-
binding.onmessage = json => handleMessage(json) - a callback that will be called for the protocol notifications and command responses.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID | |||
| bindingName | string | 绑定名称,如果未指定,则为 'cdp'。 | ENBinding name, 'cdp' if not specified. | ||
| inheritPermissions | boolean | 如果为真,则继承当前根会话的权限(默认值:false)。 | ENIf true, inherits the current root session's permissions (default: false). |
🔨Target.getDevToolsTarget🧪
获取为指定目标(如果存在)打开的DevTools页面目标的targetId。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | ✔️ | TargetID | 页面或标签页目标ID。 | ENPage or tab target ID. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| targetId | TargetID | DevTools页面目标的targetId(如果存在)。 | ENThe targetId of DevTools page target if exists. |
🔨Target.getTargetInfo🧪
返回有关目标的信息。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | TargetID |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| targetInfo | TargetInfo |