Browser
浏览器域定义了用于浏览器管理的方法和事件。
EN
✅️️ Methods
🔨Browser.addPrivacySandboxCoordinatorKeyConfig
配置用于与可信协调器通信的特定隐私沙箱API的加密密钥。由于此功能仅用于测试自动化,coordinatorOrigin必须是一个.test域名。该来源不得存在任何现有的协调器配置。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| api | ✔️ | PrivacySandboxAPI | |||
| coordinatorOrigin | ✔️ | string | |||
| keyConfig | ✔️ | string | |||
| browserContextId | BrowserContextID | 执行操作的浏览器上下文。省略时,将使用默认浏览器上下文。 | ENBrowserContext to perform the action in. When omitted, default browser context is used. |
🔨Browser.addPrivacySandboxEnrollmentOverride
允许站点使用需要注册的隐私沙箱功能,而无需站点实际完成注册。仅支持页面目标。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| url | ✔️ | string |
🔨Browser.close
优雅地关闭浏览器。
EN
🔨Browser.getVersion
返回版本信息。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| protocolVersion | string | 协议版本。 | ENProtocol version. |
| product | string | 产品名称。 | ENProduct name. |
| revision | string | 产品修订版。 | ENProduct revision. |
| userAgent | string | User-Agent. | ENUser-Agent. |
| jsVersion | string | V8 ''version``。 | ENV8 version. |
🔨Browser.resetPermissions
重置所有来源的所有权限管理。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| browserContextId | BrowserContextID | 重置权限的浏览器上下文 。如果省略,则使用默认浏览器上下文。 | ENBrowserContext to reset permissions. When omitted, default browser context is used. |
🔨Browser.cancelDownload🧪
如果正在进行中,则取消下载
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| guid | ✔️ | string | 下载的全局唯一标识符。 | ENGlobal unique identifier of the download. | |
| browserContextId | BrowserContextID | 执行操作的浏览器上下文。如果省略,则使用默认浏览器上下文。 | ENBrowserContext to perform the action in. When omitted, default browser context is used. |
🔨Browser.crash🧪
在主线程上导致浏览器崩溃。
EN
🔨Browser.crashGpuProcess🧪
崩溃 GPU 进程。
EN
🔨Browser.executeBrowserCommand🧪
调用由遥测使用的自定义浏览器命令。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| commandId | ✔️ | BrowserCommandId |
🔨Browser.getBrowserCommandLine🧪
返回浏览器进程的命令行开关,当且仅当命令行中包含 --enable-automation 时。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| arguments | array[string] | 命令行参数 | ENCommandline parameters |
🔨Browser.getHistogram🧪
通过名称获取Chrome直方图。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string | 请求的直方图名称。 | ENRequested histogram name. | |
| delta | boolean | 如果为真,则获取自上次增量调用以来的增量。 | ENIf true, retrieve delta since last delta call. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| histogram | Histogram | 直方图。 | ENHistogram. |
🔨Browser.getHistograms🧪
获取Chrome直方图。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| query | string | 请求名称中的子字符串。仅提取名称中包含查询作为子字符串的直方图。空查询或未提供查询将返回所有直方图。 | ENRequested substring in name. Only histograms which have query as a substring in their name are extracted. An empty or absent query returns all histograms. | ||
| delta | boolean | 如果为真,则获取自上次增量调用以来的增量。 | ENIf true, retrieve delta since last delta call. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| histograms | array[Histogram] | Histograms. | ENHistograms. |
🔨Browser.getWindowBounds🧪
获取浏览器窗口的位置和尺寸。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| windowId | ✔️ | WindowID | 浏览器窗口标识符。 | ENBrowser window id. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| bounds | Bounds | 窗口的边界信息。当窗口状态为'minimized'时,返回的是窗口恢复后的位置和大小。 | ENBounds information of the window. When window state is 'minimized', the restored window position and size are returned. |
🔨Browser.getWindowForTarget🧪
获取包含开发者工具目标的浏览器窗口。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| targetId | Target.TargetID | Devtools 代理主机 ID。若作为会话的一部分调用,将使用关联的 targetId。 | ENDevtools agent host id. If called as a part of the session, associated targetId is used. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| windowId | WindowID | 浏览器窗口标识符。 | ENBrowser window id. |
| bounds | Bounds | 窗口的边界信息。当窗口状态为'minimized'时,返回的是窗口恢复后的位置和尺寸。 | ENBounds information of the window. When window state is 'minimized', the restored window position and size are returned. |
🔨Browser.setContentsSize🧪
设置浏览器内容的大小,必要时调整浏览器窗口大小。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| windowId | ✔️ | WindowID | 浏览器窗口ID。 | ENBrowser window id. | |
| width | integer | 窗口内容宽度(以DIP为单位)。若省略则采用当前宽度。若省略'height'参数则必须指定本参数。 | ENThe window contents width in DIP. Assumes current width if omitted. Must be specified if 'height' is omitted. | ||
| height | integer | 窗口内容的高度,以设备独立像素(DIP)为单位。若省略则采用当前高度。若省略'width'则必须指定此参数。 | ENThe window contents height in DIP. Assumes current height if omitted. Must be specified if 'width' is omitted. |
🔨Browser.setDockTile🧪
设置停靠栏磁贴详细信息,平台特定。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| badgeLabel | string | ||||
| image | string | Png编码图像。(通过JSON传递时编码为base64字符串) | ENPng encoded image. (Encoded as a base64 string when passed over JSON) |
🔨Browser.setDownloadBehavior🧪
设置下载文件时的行为。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| behavior | ✔️ | string | 是否允许所有或拒绝所有下载请求,或者在有条件时使用Chrome的默认行为(否则拒绝)。|allowAndName| 允许下载并根据下载GUID命名文件。 允许取值: deny、allow、allowAndName、default | ENWhether to allow all or deny all download requests, or use default Chrome behavior if available (otherwise deny). |allowAndName| allows download and names files according to their download guids.Allowed Values: deny, allow, allowAndName, default | |
| browserContextId | BrowserContextID | 设置下载行为的浏览器上下文。省略时,将使用默认的浏览器上下文。 | ENBrowserContext to set download behavior. When omitted, default browser context is used. | ||
| downloadPath | string | 保存下载文件的默认路径。如果行为设置为'allow'或'allowAndName',则必须设置此路径。 | ENThe default path to save downloaded files to. This is required if behavior is set to 'allow' or 'allowAndName'. | ||
| eventsEnabled | boolean | 是否发出下载事件(默认为 false)。 | ENWhether to emit download events (defaults to false). |
🔨Browser.setPermission🧪
为给定的嵌入源和被嵌入源设置权限设置。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| permission | ✔️ | PermissionDescriptor | 覆盖权限的描述符。 | ENDescriptor of permission to override. | |
| setting | ✔️ | PermissionSetting | 权限的设置。 | ENSetting of the permission. | |
| origin | string | 嵌入来源权限适用的来源,如果未指定则为所有来源。 | ENEmbedding origin the permission applies to, all origins if not specified. | ||
| embeddedOrigin | string | 该权限所适用的嵌入来源。除非嵌入来源存在且有效,否则此字段将被忽略。如果提供了嵌入来源但未提供被嵌入来源,则嵌入来源将被用作被嵌入来源。 | ENEmbedded origin the permission applies to. It is ignored unless the embedding origin is present and valid. If the embedding origin is provided but the embedded origin isn't, the embedding origin is used as the embedded origin. | ||
| browserContextId | BrowserContextID | 要覆盖的上下文。当省略时,将使用默认的浏览器上下文。 | ENContext to override. When omitted, default browser context is used. |
🔨Browser.setWindowBounds🧪
设置浏览器窗口的位置和/或大小。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| windowId | ✔️ | WindowID | 浏览器窗口ID。 | ENBrowser window id. | |
| bounds | ✔️ | Bounds | 新窗口边界。'minimized'、'maximized'和'fullscreen'状态不能与'left'、'top'、'width'或'height'组合使用。未指定的字段保持不变。 | ENNew window bounds. The 'minimized', 'maximized' and 'fullscreen' states cannot be combined with 'left', 'top', 'width' or 'height'. Leaves unspecified fields unchanged. |
🔨Browser.grantPermissions🧪❌️
授予指定来源特定权限并拒绝所有其他权限。已弃用。请改用 setPermission。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| permissions | ✔️ | array[PermissionType] | |||
| origin | string | 权限适用的来源,如果未指定则为所有来源。 | ENOrigin the permission applies to, all origins if not specified. | ||
| browserContextId | BrowserContextID | 用于覆盖权限的浏览器上下文。当省略时,将使用默认浏览器上下文。 | ENBrowserContext to override permissions. When omitted, default browser context is used. |
✅️️ Events
👋Browser.downloadProgress🧪
当下载进度更新时触发。最后一次调用时,|done| 参数为 true。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| guid | ✔️ | string | 下载的全局唯一标识符。 | ENGlobal unique identifier of the download. | |
| totalBytes | ✔️ | number | 预计下载的总字节数。 | ENTotal expected bytes to download. | |
| receivedBytes | ✔️ | number | 接收到的总字节数。 | ENTotal bytes received. | |
| state | ✔️ | string | 下载状态。 允许的值: inProgress、completed、canceled | ENDownload status.Allowed Values: inProgress, completed, canceled | |
| filePath | 🧪 | string | 如果下载状态为"completed",则提供下载文件的路径。根据平台的不同,无法保证该路径一定会被设置,也无法保证文件一定存在。 | ENIf download is "completed", provides the path of the downloaded file. Depending on the platform, it is not guaranteed to be set, nor the file is guaranteed to exist. |
👋Browser.downloadWillBegin🧪
当页面即将开始下载时触发。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| frameId | ✔️ | Page.FrameId | 导致下载开始的框架的Id。 | ENId of the frame that caused the download to begin. | |
| guid | ✔️ | string | 下载的全局唯一标识符。 | ENGlobal unique identifier of the download. | |
| url | ✔️ | string | 正在下载的资源的URL。 | ENURL of the resource being downloaded. | |
| suggestedFilename | ✔️ | string | 建议的资源文件名(实际保存在磁盘上的文件名可能不同)。 | ENSuggested file name of the resource (the actual name of the file saved on disk may differ). |
✅️️ Types
📌Browser.Bounds🧪
浏览器窗口边界信息
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| left | integer | 从屏幕左边缘到窗口的偏移量,以像素为单位。 | ENThe offset from the left edge of the screen to the window in pixels. | ||
| top | integer | 从屏幕顶部边缘到窗口的偏移量,单位为像素。 | ENThe offset from the top edge of the screen to the window in pixels. | ||
| width | integer | 窗口宽度,单位为像素。 | ENThe window width in pixels. | ||
| height | integer | 窗口高度,单位为像素。 | ENThe window height in pixels. | ||
| windowState | WindowState | 窗口状态。默认值为 normal。 | ENThe window state. Default to normal. |
📌Browser.BrowserCommandId🧪
浏览器命令ID,用于executeBrowserCommand。
允许的值:openTabSearch、closeTabSearch、openGlic
EN
Allowed Values:
openTabSearch, closeTabSearch, openGlic返回类型:string
📌Browser.BrowserContextID🧪
返回类型:string
📌Browser.Bucket🧪
Chrome直方图桶。
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| low | ✔️ | integer | 最小值(包含)。 | ENMinimum value (inclusive). | |
| high | ✔️ | integer | 最大值(不包含)。 | ENMaximum value (exclusive). | |
| count | ✔️ | integer | 样本数量。 | ENNumber of samples. |
📌Browser.Histogram🧪
Chrome直方图。
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string | 名称。 | ENName. | |
| sum | ✔️ | integer | 样本值的总和。 | ENSum of sample values. | |
| count | ✔️ | integer | 样本总数。 | ENTotal number of samples. | |
| buckets | ✔️ | array[Bucket] | Buckets。 | ENBuckets. |
📌Browser.PermissionDescriptor🧪
Permissions API 中定义的 PermissionDescriptor 的定义:https://w3c.github.io/permissions/#dom-permissiondescriptor。
EN
返回类型:object
| 属性 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| name | ✔️ | string | 权限名称。有关有效权限名称,请参阅 https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl。 | ENName of permission. See https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/permissions/permission_descriptor.idl for valid permission names. | |
| sysex | boolean | 对于"midi"权限,也可指定''sysex''控制。 | ENFor "midi" permission, may also specify sysex control. | ||
| userVisibleOnly | boolean | 对于"推送"权限,可以指定userVisibleOnly。请注意,userVisibleOnly = true是当前唯一支持的类型。 | ENFor "push" permission, may specify userVisibleOnly. Note that userVisibleOnly = true is the only currently supported type. | ||
| allowWithoutSanitization | boolean | 对于"clipboard"权限,可以指定allowWithoutSanitization。 | ENFor "clipboard" permission, may specify allowWithoutSanitization. | ||
| allowWithoutGesture | boolean | 对于"fullscreen"权限,必须指定allowWithoutGesture:true。 | ENFor "fullscreen" permission, must specify allowWithoutGesture:true. | ||
| panTiltZoom | boolean | 对于"camera"权限,可以指定panTiltZoom。 | ENFor "camera" permission, may specify panTiltZoom. |
📌Browser.PermissionSetting🧪
允许的值:granted、denied、prompt
EN
granted, denied, prompt返回类型:string
📌Browser.PermissionType🧪
允许的值:ar、audioCapture、automaticFullscreen、backgroundFetch、backgroundSync、cameraPanTiltZoom、capturedSurfaceControl、clipboardReadWrite、clipboardSanitizedWrite、displayCapture、durableStorage、geolocation、handTracking、idleDetection、keyboardLock、localFonts、localNetwork、localNetworkAccess、loopbackNetwork、midi、midiSysex、nfc、notifications、paymentHandler、periodicBackgroundSync、pointerLock、protectedMediaIdentifier、sensors、smartCard、speakerSelection、storageAccess、topLevelStorageAccess、videoCapture、vr、wakeLockScreen、wakeLockSystem、webAppInstallation、webPrinting、windowManagement
EN
ar, audioCapture, automaticFullscreen, backgroundFetch, backgroundSync, cameraPanTiltZoom, capturedSurfaceControl, clipboardReadWrite, clipboardSanitizedWrite, displayCapture, durableStorage, geolocation, handTracking, idleDetection, keyboardLock, localFonts, localNetwork, localNetworkAccess, loopbackNetwork, midi, midiSysex, nfc, notifications, paymentHandler, periodicBackgroundSync, pointerLock, protectedMediaIdentifier, sensors, smartCard, speakerSelection, storageAccess, topLevelStorageAccess, videoCapture, vr, wakeLockScreen, wakeLockSystem, webAppInstallation, webPrinting, windowManagement返回类型:string
📌Browser.PrivacySandboxAPI🧪
允许的值:BiddingAndAuctionServices、TrustedKeyValue
EN
BiddingAndAuctionServices, TrustedKeyValue返回类型:string
📌Browser.WindowID🧪
返回类型:integer
📌Browser.WindowState🧪
浏览器窗口的状态。
允许的值:normal、minimized、maximized、fullscreen
EN
Allowed Values:
normal, minimized, maximized, fullscreen返回类型:string