Emulation
此域为页面模拟不同的环境。
EN
✅️️ Methods
🔨Emulation.clearDeviceMetricsOverride
清除被覆盖的设备指标。
EN
🔨Emulation.clearGeolocationOverride
清除被覆盖的地理位置定位和错误信息。
EN
🔨Emulation.clearIdleOverride
清除空闲状态覆盖。
EN
🔨Emulation.setCPUThrottlingRate
启用CPU节流以模拟慢速CPU。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| rate | ✔️ | number | 节流速率作为减速因子(1表示无节流,2表示2倍减速,依此类推)。 | ENThrottling rate as a slowdown factor (1 is no throttle, 2 is 2x slowdown, etc). |
🔨Emulation.setDefaultBackgroundColorOverride
设置或清除框架默认背景颜色的覆盖。如果内容未指定背景颜色,则使用此覆盖。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| color | DOM.RGBA | 默认背景色的 RGBA 值。若未指定,将清除任何现有的覆盖设置。 | ENRGBA of the default background color. If not specified, any existing override will be cleared. |
🔨Emulation.setDeviceMetricsOverride
覆盖设备屏幕尺寸的值(window.screen.width、window.screen.height、window.innerWidth、window.innerHeight,以及与"device-width"/"device-height"相关的CSS媒体查询结果)。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| width | ✔️ | integer | 覆盖宽度值(以像素为单位,最小值为0,最大值为10000000)。0表示禁用覆盖。 | ENOverriding width value in pixels (minimum 0, maximum 10000000). 0 disables the override. | |
| height | ✔️ | integer | 覆盖高度值(以像素为单位,最小值为0,最大值为10000000)。0表示禁用覆盖。 | ENOverriding height value in pixels (minimum 0, maximum 10000000). 0 disables the override. | |
| deviceScaleFactor | ✔️ | number | 覆盖设备缩放因 子值。0表示禁用覆盖。 | ENOverriding device scale factor value. 0 disables the override. | |
| mobile | ✔️ | boolean | 是否模拟移动设备。这包括 viewport meta 标签、覆盖滚动条、文本自动调整大小等。 | ENWhether to emulate mobile device. This includes viewport meta tag, overlay scrollbars, text autosizing and more. | |
| scale | 🧪 | number | 应用于结果视图图像的缩放比例。 | ENScale to apply to resulting view image. | |
| screenWidth | 🧪 | integer | 覆盖屏幕宽度值(以像素为单位,最小值为0,最大值为10000000)。 | ENOverriding screen width value in pixels (minimum 0, maximum 10000000). | |
| screenHeight | 🧪 | integer | 覆盖屏幕高度值,单位为像素(最小值为0,最大值为10000000)。 | ENOverriding screen height value in pixels (minimum 0, maximum 10000000). | |
| positionX | 🧪 | integer | 覆盖屏幕上视图X轴位置,单位为像素(最小值为0,最大值为10000000)。 | ENOverriding view X position on screen in pixels (minimum 0, maximum 10000000). | |
| positionY | 🧪 | integer | 覆盖屏幕上视图的Y轴位置(以像素为单位,最小值为0,最大值为10000000)。 | ENOverriding view Y position on screen in pixels (minimum 0, maximum 10000000). | |
| dontSetVisibleSize | 🧪 | boolean | 不要设置可见视图大小,依赖显式的setVisibleSize调用。 | ENDo not set visible view size, rely upon explicit setVisibleSize call. | |
| screenOrientation | ScreenOrientation | 屏幕方向覆盖。 | ENScreen orientation override. | ||
| viewport | 🧪 | Page.Viewport | 如果设置,页面的可见区域将被覆盖为此视口。此视口更改不会被页面观察到,例如,视口相对元素不会改变位置。 | ENIf set, the visible area of the page will be overridden to this viewport. This viewport change is not observed by the page, e.g. viewport-relative elements do not change positions. | |
| displayFeature | 🧪 | DisplayFeature | 如果设置,则启用多段屏幕的显示功能。如果未设置,则关闭多 段支持。已弃用,请使用 Emulation.setDisplayFeaturesOverride。 | ENIf set, the display feature of a multi-segment screen. If not set, multi-segment support is turned-off. Deprecated, use Emulation.setDisplayFeaturesOverride. | |
| devicePosture | 🧪 | DevicePosture | 如果设置,表示可折叠设备的姿态。如果未设置,姿态将默认为连续。已弃用,请使用 Emulation.setDevicePostureOverride。 | ENIf set, the posture of a foldable device. If not set the posture is set to continuous. Deprecated, use Emulation.setDevicePostureOverride. | |
| scrollbarType | 🧪 | string | 滚动条类型。默认值:default。允许的值: overlay、default | ENScrollbar type. Default:default.Allowed Values: overlay, default | |
| screenOrientationLockEmulation | 🧪 | boolean | 如果设置为true,将启用屏幕方向锁定模拟功能,该功能会拦截页面中的screen.orientation.lock()调用,并通过screenOrientationLockChanged事件报告方向变化。这在响应式设计模式下模拟移动设备方向锁定行为时非常有用。 | ENIf set to true, enables screen orientation lock emulation, which intercepts screen.orientation.lock() calls from the page and reports orientation changes via screenOrientationLockChanged events. This is useful for emulating mobile device orientation lock behavior in responsive design mode. |
🔨Emulation.setEmulatedMedia
模拟给定的CSS媒体查询的媒体类型或媒体特性。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| media | string | 模拟的媒体类型。空字符串会禁用覆盖。 | ENMedia type to emulate. Empty string disables the override. | ||
| features | array[MediaFeature] | 要模拟的媒体特性。 | ENMedia features to emulate. |
🔨Emulation.setEmulatedOSTextScale
模拟给定的操作系统文本缩放比例。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| scale | number |
🔨Emulation.setEmulatedVisionDeficiency
模拟给定的视觉缺陷。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| type | ✔️ | string | 要模拟的视觉缺陷。顺序:优先采用尽力模拟方式,其次针对医学认可的色彩视觉缺陷提供生理学精确模拟。 允许值: none、blurredVision、reducedContrast、achromatopsia、deuteranopia、protanopia、tritanopia | ENVision deficiency to emulate. Order: best-effort emulations come first, followed by any physiologically accurate emulations for medically recognized color vision deficiencies.Allowed Values: none, blurredVision, reducedContrast, achromatopsia, deuteranopia, protanopia, tritanopia |
🔨Emulation.setGeolocationOverride
覆盖地理位置定位或错误。省略纬度、经度或精确度将模拟位置不可用。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| latitude | number | 模拟纬度 | ENMock latitude | ||
| longitude | number | 模拟经度 | ENMock longitude | ||
| accuracy | number | 模拟准确度 | ENMock accuracy | ||
| altitude | number | 模拟海拔高度 | ENMock altitude | ||
| altitudeAccuracy | number | 模拟海拔精度 | ENMock altitudeAccuracy | ||
| heading | number | 模拟标题 | ENMock heading | ||
| speed | number | 模拟速度 | ENMock speed |
🔨Emulation.setIdleOverride
覆盖空闲状态。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| isUserActive | ✔️ | boolean | Mock isUserActive | ENMock isUserActive | |
| isScreenUnlocked | ✔️ | boolean | Mock isScreenUnlocked | ENMock isScreenUnlocked |
🔨Emulation.setScriptExecutionDisabled
在页面中切换脚本执行。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| value | ✔️ | boolean | 是否应在页面中禁用脚本执行。 | ENWhether script execution should be disabled in the page. |
🔨Emulation.setTimezoneOverride
使用指定的时区覆盖默认主机系统时区。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| timezoneId | ✔️ | string | 时区标识符。支持的时区列表:https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt 若为空,则禁用覆盖并恢复默认主机系统时区。 | ENThe timezone identifier. List of supported timezones: https://source.chromium.org/chromium/chromium/deps/icu.git/+/faee8bc70570192d82d2978a71e2a615788597d1:source/data/misc/metaZones.txt If empty, disables the override and restores default host system timezone. |
🔨Emulation.setTouchEmulationEnabled
在不支持触摸功能的平台上启用触摸操作。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | ✔️ | boolean | 是否应启用触摸事件模拟。 | ENWhether the touch event emulation should be enabled. | |
| maxTouchPoints | integer | 支持的最大触摸点数。默认为一个。 | ENMaximum touch points supported. Defaults to one. |
🔨Emulation.setUserAgentOverride
允许使用给定字符串覆盖用户代理。必须设置 userAgentMetadata 才能发送 Client Hint 标头。
EN
userAgentMetadata must be set for Client Hint headers to be sent.| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| userAgent | ✔️ | string | 要使用的用户代理。 | ENUser agent to use. | |
| acceptLanguage | string | 要模拟的浏览器语言。 | ENBrowser language to emulate. | ||
| platform | string | 平台 navigator.platform 应当返回。 | ENThe platform navigator.platform should return. | ||
| userAgentMetadata | 🧪 | UserAgentMetadata | 在Sec-CH-UA-*头部中发送,并在navigator.userAgentData中返回 | ENTo be sent in Sec-CH-UA-* headers and returned in navigator.userAgentData |
🔨Emulation.canEmulate❌️
判断是否支持模拟功能。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| result | boolean | 如果支持模拟,则为True。 | ENTrue if emulation is supported. |
🔨Emulation.addScreen🧪
向设备添加一个新屏幕。仅在无头模式下受支持。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| left | ✔️ | integer | 屏幕左边缘的偏移量,以像素为单位。 | ENOffset of the left edge of the screen in pixels. | |
| top | ✔️ | integer | 屏幕顶边的偏移量(以像素为单位)。 | ENOffset of the top edge of the screen in pixels. | |
| width | ✔️ | integer | 屏幕的宽度,单位为像素。 | ENThe width of the screen in pixels. | |
| height | ✔️ | integer | 屏幕的高度,单位为像素。 | ENThe height of the screen in pixels. | |
| workAreaInsets | WorkAreaInsets | 指定屏幕的工作区域。默认值为整个屏幕。 | ENSpecifies the screen's work area. Default is entire screen. | ||
| devicePixelRatio | number | 指定屏幕的设备像素比。默认值为1。 | ENSpecifies the screen's device pixel ratio. Default is 1. | ||
| rotation | integer | 指定屏幕的旋转角度。可用值为0、90、180和270。默认值为0。 | ENSpecifies the screen's rotation angle. Available values are 0, 90, 180 and 270. Default is 0. | ||
| colorDepth | integer | 指定屏幕的颜色深度,单位为比特。默认值为24。 | ENSpecifies the screen's color depth in bits. Default is 24. | ||
| label | string | 指定屏幕的描述性标签。默认值为无。 | ENSpecifies the descriptive label for the screen. Default is none. | ||
| isInternal | boolean | 指示屏幕是否为设备内置或外接于设备。默认值为 false。 | ENIndicates whether the screen is internal to the device or external, attached to the device. Default is false. |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| screenInfo | ScreenInfo |
🔨Emulation.clearDevicePostureOverride🧪
清除通过 setDeviceMetricsOverride() 或 setDevicePostureOverride() 设置的设备姿态覆盖,并重新开始使用来自平台的姿态信息。如果未设置任何覆盖,则不执行任何操作。
EN
🔨Emulation.clearDisplayFeaturesOverride🧪
清除通过 setDeviceMetricsOverride() 或 setDisplayFeaturesOverride() 设置的显示特性覆盖,并重新开始使用平台的显示特性。如果未设置覆盖,则不执行任何操作。
EN
🔨Emulation.getOverriddenSensorInformation🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| type | ✔️ | SensorType |
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| requestedSamplingFrequency | number |
🔨Emulation.getScreenInfos🧪
返回设备的屏幕配置。在''headful''模式下,返回物理屏幕配置;而在''headless''模式下,则提供虚拟的无头屏幕配置。
EN
| 返回对象 | 类型 | 描述 | 原文 |
|---|---|---|---|
| screenInfos | array[ScreenInfo] |
🔨Emulation.removeScreen🧪
从设备移除屏幕。仅在无头模式下支持。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| screenId | ✔️ | ScreenId |
🔨Emulation.resetPageScaleFactor🧪
请求将页面缩放比例重置为初 始值。
EN
🔨Emulation.setAutoDarkModeOverride🧪
自动使用深色主题渲染所有网页内容。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | boolean | 是否启用或禁用自动深色模式。如果未指定,将清除任何现有的覆盖设置。 | ENWhether to enable or disable automatic dark mode. If not specified, any existing override will be cleared. |
🔨Emulation.setAutomationOverride🧪
允许覆盖自动化标志。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | ✔️ | boolean | 覆盖是否应启用。 | ENWhether the override should be enabled. |
🔨Emulation.setDataSaverOverride🧪
覆盖 navigator.connection.saveData 的值
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| dataSaverEnabled | boolean | 覆盖值。省略参数将禁用覆盖。 | ENOverride value. Omitting the parameter disables the override. |
🔨Emulation.setDevicePostureOverride🧪
开始向设备姿态API报告给定的姿态值。此覆盖设置也可以在setDeviceMetricsOverride()中完成。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| posture | ✔️ | DevicePosture |
🔨Emulation.setDisabledImageTypes🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| imageTypes | ✔️ | array[DisabledImageType] | 要禁用的图像类型。 | ENImage types to disable. |
🔨Emulation.setDisplayFeaturesOverride🧪
开始使用给定的显示特性来填充视口分段API。此覆盖也可以在setDeviceMetricsOverride()中设置。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| features | ✔️ | array[DisplayFeature] |
🔨Emulation.setDocumentCookieDisabled🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| disabled | ✔️ | boolean | 是否应禁用 document.coookie API。 | ENWhether document.coookie API should be disabled. |
🔨Emulation.setEmitTouchEventsForMouse🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | ✔️ | boolean | 是否应启用基于鼠标输入的触摸模拟。 | ENWhether touch emulation based on mouse input should be enabled. | |
| configuration | string | 触摸/手势事件配置。默认值:当前平台。 允许的值: mobile、desktop | ENTouch/gesture events configuration. Default: current platform.Allowed Values: mobile, desktop |
🔨Emulation.setFocusEmulationEnabled🧪
启用或禁用模拟页面处于聚焦和活动状态。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| enabled | ✔️ | boolean | 是否启用或禁用焦点模拟。 | ENWhether to enable to disable focus emulation. |
🔨Emulation.setHardwareConcurrencyOverride🧪
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| hardwareConcurrency | ✔️ | integer | 报告硬件并发数 | ENHardware concurrency to report |
🔨Emulation.setLocaleOverride🧪
使用指定的区域设置覆盖默认主机系统区域设置。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| locale | string | ICU 风格的 C 语言区域设置(例如 "en_US")。如果未指定或为空,则禁用覆盖并恢复默认主机系统区域设置。 | ENICU style C locale (e.g. "en_US"). If not specified or empty, disables the override and restores default host system locale. |
🔨Emulation.setPageScaleFactor🧪
设置指定的页面缩放比例。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| pageScaleFactor | ✔️ | number | 页面缩放比例。 | ENPage scale factor. |
🔨Emulation.setPressureDataOverride🧪
提供一个给定的压力数据集,该数据集将被处理并最终传递给PressureObserver用户。|source|必须事先通过setPressureSourceOverrideEnabled进行覆盖。
EN
| 参数 | 必填 | 标记 | 类型 | 描述 | 原文 |
|---|---|---|---|---|---|
| source | ✔️ | PressureSource | |||
| state | ✔️ | PressureState | |||
| ownContributionEstimate | number |