puppeteer/website/versioned_docs/version-10.0.0/puppeteer.page.emulatemediafeatures.md
TASNEEM KOUSHAR 34ff00e2fe
chore(docs): generate site for v10.0.0
* fix: added parts of website

* fix: removed unnecessary lines

* fix: updated contributing.md

* fix: added parts of sidebar

* fix: added all APIs

* fix: added version 10.0.0

Co-authored-by: Jack Franklin <jacktfranklin@chromium.org>
2021-08-09 09:57:14 +01:00

2.1 KiB

Home > puppeteer > Page > emulateMediaFeatures

Page.emulateMediaFeatures() method

Signature:

emulateMediaFeatures(features?: MediaFeature[]): Promise<void>;

Parameters

Parameter Type Description
features MediaFeature[] <?Array<Object>> Given an array of media feature objects, emulates CSS media features on the page. Each media feature object must have the following properties:

Returns:

Promise<void>

Example

await page.emulateMediaFeatures([
{ name: 'prefers-color-scheme', value: 'dark' },
]);
await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
// → true
await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
// → false

await page.emulateMediaFeatures([
{ name: 'prefers-reduced-motion', value: 'reduce' },
]);
await page.evaluate(
() => matchMedia('(prefers-reduced-motion: reduce)').matches
);
// → true
await page.evaluate(
() => matchMedia('(prefers-reduced-motion: no-preference)').matches
);
// → false

await page.emulateMediaFeatures([
{ name: 'prefers-color-scheme', value: 'dark' },
{ name: 'prefers-reduced-motion', value: 'reduce' },
]);
await page.evaluate(() => matchMedia('(prefers-color-scheme: dark)').matches);
// → true
await page.evaluate(() => matchMedia('(prefers-color-scheme: light)').matches);
// → false
await page.evaluate(
() => matchMedia('(prefers-reduced-motion: reduce)').matches
);
// → true
await page.evaluate(
() => matchMedia('(prefers-reduced-motion: no-preference)').matches
);
// → false

await page.emulateMediaFeatures([{ name: 'color-gamut', value: 'p3' }]);
await page.evaluate(() => matchMedia('(color-gamut: srgb)').matches);
// → true
await page.evaluate(() => matchMedia('(color-gamut: p3)').matches);
// → true
await page.evaluate(() => matchMedia('(color-gamut: rec2020)').matches);
// → false