跳到主要内容

Browser

浏览器域定义了用于浏览器管理的方法和事件。

EN
The Browser domain defines methods and events for browser managing.

✅️️ Methods

🔨Browser.addPrivacySandboxCoordinatorKeyConfig

配置用于与可信协调器通信的特定隐私沙箱API的加密密钥。由于此功能仅用于测试自动化,coordinatorOrigin必须是一个.test域名。该来源不得存在任何现有的协调器配置。

EN
Configures encryption keys used with a given privacy sandbox API to talk to a trusted coordinator. Since this is intended for test automation only, coordinatorOrigin must be a .test domain. No existing coordinator configuration for the origin may exist.
参数必填标记类型描述原文
api✔️PrivacySandboxAPI
coordinatorOrigin✔️string
keyConfig✔️string
browserContextIdBrowserContextID执行操作的浏览器上下文。省略时,将使用默认浏览器上下文。
ENBrowserContext to perform the action in. When omitted, default browser context is used.

🔨Browser.addPrivacySandboxEnrollmentOverride

允许站点使用需要注册的隐私沙箱功能,而无需站点实际完成注册。仅支持页面目标。

EN
Allows a site to use privacy sandbox features that require enrollment without the site actually being enrolled. Only supported on page targets.
参数必填标记类型描述原文
url✔️string

🔨Browser.close

优雅地关闭浏览器。

EN
Close browser gracefully.

🔨Browser.getVersion

返回版本信息。

EN
Returns version information.
返回对象类型描述原文
protocolVersionstring协议版本。
ENProtocol version.
productstring产品名称。
ENProduct name.
revisionstring产品修订版。
ENProduct revision.
userAgentstringUser-Agent.
ENUser-Agent.
jsVersionstringV8 ''version``。
ENV8 version.

🔨Browser.resetPermissions

重置所有来源的所有权限管理。

EN
Reset all permission management for all origins.
参数必填标记类型描述原文
browserContextIdBrowserContextID重置权限的浏览器上下文。如果省略,则使用默认浏览器上下文。
ENBrowserContext to reset permissions. When omitted, default browser context is used.

🔨Browser.cancelDownload🧪

如果正在进行中,则取消下载

EN
Cancel a download if in progress
参数必填标记类型描述原文
guid✔️string下载的全局唯一标识符。
ENGlobal unique identifier of the download.
browserContextIdBrowserContextID执行操作的浏览器上下文。如果省略,则使用默认浏览器上下文。
ENBrowserContext to perform the action in. When omitted, default browser context is used.

🔨Browser.crash🧪

在主线程上导致浏览器崩溃。

EN
Crashes browser on the main thread.

🔨Browser.crashGpuProcess🧪

崩溃 GPU 进程。

EN
Crashes GPU process.

🔨Browser.executeBrowserCommand🧪

调用由遥测使用的自定义浏览器命令。

EN
Invoke custom browser commands used by telemetry.
参数必填标记类型描述原文
commandId✔️BrowserCommandId

🔨Browser.getBrowserCommandLine🧪

返回浏览器进程的命令行开关,当且仅当命令行中包含 --enable-automation 时。

EN
Returns the command line switches for the browser process if, and only if --enable-automation is on the commandline.
返回对象类型描述原文
argumentsarray[string]命令行参数
ENCommandline parameters

🔨Browser.getHistogram🧪

通过名称获取Chrome直方图。

EN
Get a Chrome histogram by name.
参数必填标记类型描述原文
name✔️string请求的直方图名称。
ENRequested histogram name.
deltaboolean如果为真,则获取自上次增量调用以来的增量。
ENIf true, retrieve delta since last delta call.
返回对象类型描述原文
histogramHistogram直方图。
ENHistogram.

🔨Browser.getHistograms🧪

获取Chrome直方图。

EN
Get Chrome histograms.
参数必填标记类型描述原文
querystring请求名称中的子字符串。仅提取名称中包含查询作为子字符串的直方图。空查询或未提供查询将返回所有直方图。
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.
deltaboolean如果为真,则获取自上次增量调用以来的增量。
ENIf true, retrieve delta since last delta call.
返回对象类型描述原文
histogramsarray[Histogram]Histograms.
ENHistograms.

🔨Browser.getWindowBounds🧪

获取浏览器窗口的位置和尺寸。

EN
Get position and size of the browser window.
参数必填标记类型描述原文
windowId✔️WindowID浏览器窗口标识符。
ENBrowser window id.
返回对象类型描述原文
boundsBounds窗口的边界信息。当窗口状态为'minimized'时,返回的是窗口恢复后的位置和大小。
ENBounds information of the window. When window state is 'minimized', the restored window position and size are returned.

🔨Browser.getWindowForTarget🧪

获取包含开发者工具目标的浏览器窗口。

EN
Get the browser window that contains the devtools target.
参数必填标记类型描述原文
targetIdTarget.TargetIDDevtools 代理主机 ID。若作为会话的一部分调用,将使用关联的 targetId。
ENDevtools agent host id. If called as a part of the session, associated targetId is used.
返回对象类型描述原文
windowIdWindowID浏览器窗口标识符。
ENBrowser window id.
boundsBounds窗口的边界信息。当窗口状态为'minimized'时,返回的是窗口恢复后的位置和尺寸。
ENBounds information of the window. When window state is 'minimized', the restored window position and size are returned.

🔨Browser.setContentsSize🧪

设置浏览器内容的大小,必要时调整浏览器窗口大小。

EN
Set size of the browser contents resizing browser window as necessary.
参数必填标记类型描述原文
windowId✔️WindowID浏览器窗口ID。
ENBrowser window id.
widthinteger窗口内容宽度(以DIP为单位)。若省略则采用当前宽度。若省略'height'参数则必须指定本参数。
ENThe window contents width in DIP. Assumes current width if omitted. Must be specified if 'height' is omitted.
heightinteger窗口内容的高度,以设备独立像素(DIP)为单位。若省略则采用当前高度。若省略'width'则必须指定此参数。
ENThe window contents height in DIP. Assumes current height if omitted. Must be specified if 'width' is omitted.

🔨Browser.setDockTile🧪

设置停靠栏磁贴详细信息,平台特定。

EN
Set dock tile details, platform-specific.
参数必填标记类型描述原文
badgeLabelstring
imagestringPng编码图像。(通过JSON传递时编码为base64字符串)
ENPng encoded image. (Encoded as a base64 string when passed over JSON)

🔨Browser.setDownloadBehavior🧪

设置下载文件时的行为。

EN
Set the behavior when downloading a file.
参数必填标记类型描述原文
behavior✔️string是否允许所有或拒绝所有下载请求,或者在有条件时使用Chrome的默认行为(否则拒绝)。|allowAndName| 允许下载并根据下载GUID命名文件。
允许取值:denyallowallowAndNamedefault
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
browserContextIdBrowserContextID设置下载行为的浏览器上下文。省略时,将使用默认的浏览器上下文。
ENBrowserContext to set download behavior. When omitted, default browser context is used.
downloadPathstring保存下载文件的默认路径。如果行为设置为'allow'或'allowAndName',则必须设置此路径。
ENThe default path to save downloaded files to. This is required if behavior is set to 'allow' or 'allowAndName'.
eventsEnabledboolean是否发出下载事件(默认为 false)。
ENWhether to emit download events (defaults to false).

🔨Browser.setPermission🧪

为给定的嵌入源和被嵌入源设置权限设置。

EN
Set permission settings for given embedding and embedded origins.
参数必填标记类型描述原文
permission✔️PermissionDescriptor覆盖权限的描述符。
ENDescriptor of permission to override.
setting✔️PermissionSetting权限的设置。
ENSetting of the permission.
originstring嵌入来源权限适用的来源,如果未指定则为所有来源。
ENEmbedding origin the permission applies to, all origins if not specified.
embeddedOriginstring该权限所适用的嵌入来源。除非嵌入来源存在且有效,否则此字段将被忽略。如果提供了嵌入来源但未提供被嵌入来源,则嵌入来源将被用作被嵌入来源。
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.
browserContextIdBrowserContextID要覆盖的上下文。当省略时,将使用默认的浏览器上下文。
ENContext to override. When omitted, default browser context is used.

🔨Browser.setWindowBounds🧪

设置浏览器窗口的位置和/或大小。

EN
Set position and/or size of the browser window.
参数必填标记类型描述原文
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
Grant specific permissions to the given origin and reject all others. Deprecated. Use setPermission instead.
参数必填标记类型描述原文
permissions✔️array[PermissionType]
originstring权限适用的来源,如果未指定则为所有来源。
ENOrigin the permission applies to, all origins if not specified.
browserContextIdBrowserContextID用于覆盖权限的浏览器上下文。当省略时,将使用默认浏览器上下文。
ENBrowserContext to override permissions. When omitted, default browser context is used.

✅️️ Events

👋Browser.downloadProgress🧪

当下载进度更新时触发。最后一次调用时,|done| 参数为 true。

EN
Fired when download makes progress. Last call has |done| == true.
参数必填标记类型描述原文
guid✔️string下载的全局唯一标识符。
ENGlobal unique identifier of the download.
totalBytes✔️number预计下载的总字节数。
ENTotal expected bytes to download.
receivedBytes✔️number接收到的总字节数。
ENTotal bytes received.
state✔️string下载状态。
允许的值:inProgresscompletedcanceled
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
Fired when page is about to start a download.
参数必填标记类型描述原文
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
Browser window bounds information

返回类型:object

属性必填标记类型描述原文
leftinteger从屏幕左边缘到窗口的偏移量,以像素为单位。
ENThe offset from the left edge of the screen to the window in pixels.
topinteger从屏幕顶部边缘到窗口的偏移量,单位为像素。
ENThe offset from the top edge of the screen to the window in pixels.
widthinteger窗口宽度,单位为像素。
ENThe window width in pixels.
heightinteger窗口高度,单位为像素。
ENThe window height in pixels.
windowStateWindowState窗口状态。默认值为 normal。
ENThe window state. Default to normal.

📌Browser.BrowserCommandId🧪

浏览器命令ID,用于executeBrowserCommand。
允许的值:openTabSearchcloseTabSearchopenGlic

EN
Browser command ids used by executeBrowserCommand.
Allowed Values: openTabSearch, closeTabSearch, openGlic

返回类型:string


📌Browser.BrowserContextID🧪

返回类型:string


📌Browser.Bucket🧪

Chrome直方图桶。

EN
Chrome histogram bucket.

返回类型:object

属性必填标记类型描述原文
low✔️integer最小值(包含)。
ENMinimum value (inclusive).
high✔️integer最大值(不包含)。
ENMaximum value (exclusive).
count✔️integer样本数量。
ENNumber of samples.

📌Browser.Histogram🧪

Chrome直方图。

EN
Chrome histogram.

返回类型: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
Definition of PermissionDescriptor defined in the Permissions API: https://w3c.github.io/permissions/#dom-permissiondescriptor.

返回类型: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.
sysexboolean对于"midi"权限,也可指定''sysex''控制。
ENFor "midi" permission, may also specify sysex control.
userVisibleOnlyboolean对于"推送"权限,可以指定userVisibleOnly。请注意,userVisibleOnly = true是当前唯一支持的类型。
ENFor "push" permission, may specify userVisibleOnly. Note that userVisibleOnly = true is the only currently supported type.
allowWithoutSanitizationboolean对于"clipboard"权限,可以指定allowWithoutSanitization。
ENFor "clipboard" permission, may specify allowWithoutSanitization.
allowWithoutGestureboolean对于"fullscreen"权限,必须指定allowWithoutGesture:true
ENFor "fullscreen" permission, must specify allowWithoutGesture:true.
panTiltZoomboolean对于"camera"权限,可以指定panTiltZoom。
ENFor "camera" permission, may specify panTiltZoom.

📌Browser.PermissionSetting🧪

允许的值:granteddeniedprompt

EN
Allowed Values: granted, denied, prompt

返回类型:string


📌Browser.PermissionType🧪

允许的值:araudioCaptureautomaticFullscreenbackgroundFetchbackgroundSynccameraPanTiltZoomcapturedSurfaceControlclipboardReadWriteclipboardSanitizedWritedisplayCapturedurableStoragegeolocationhandTrackingidleDetectionkeyboardLocklocalFontslocalNetworklocalNetworkAccessloopbackNetworkmidimidiSysexnfcnotificationspaymentHandlerperiodicBackgroundSyncpointerLockprotectedMediaIdentifiersensorssmartCardspeakerSelectionstorageAccesstopLevelStorageAccessvideoCapturevrwakeLockScreenwakeLockSystemwebAppInstallationwebPrintingwindowManagement

EN
Allowed Values: 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🧪

允许的值:BiddingAndAuctionServicesTrustedKeyValue

EN
Allowed Values: BiddingAndAuctionServices, TrustedKeyValue

返回类型:string


📌Browser.WindowID🧪

返回类型:integer


📌Browser.WindowState🧪

浏览器窗口的状态。
允许的值:normalminimizedmaximizedfullscreen

EN
The state of the browser window.
Allowed Values: normal, minimized, maximized, fullscreen

返回类型:string