Skip to main content
Version: 24.38.0

Page.emulateMediaType() 方法

🌐 Page.emulateMediaType() method

语法

🌐 Signature

class Page {
abstract emulateMediaType(type?: string): Promise<void>;
}

参数

🌐 Parameters

范围

🌐 Parameter

类型

🌐 Type

描述

🌐 Description

type

string

(可选) 更改页面的 CSS 媒体类型。唯一允许的值是 screenprintnull。传递 null 将禁用 CSS 媒体模拟。

🌐 (Optional) Changes the CSS media type of the page. The only allowed values are screen, print and null. Passing null disables CSS media emulation.

返回:

Promise<void>

示例

🌐 Example

await page.evaluate(() => matchMedia('screen').matches);
// → true
await page.evaluate(() => matchMedia('print').matches);
// → false

await page.emulateMediaType('print');
await page.evaluate(() => matchMedia('screen').matches);
// → false
await page.evaluate(() => matchMedia('print').matches);
// → true

await page.emulateMediaType(null);
await page.evaluate(() => matchMedia('screen').matches);
// → true
await page.evaluate(() => matchMedia('print').matches);
// → false