puppeteer/docs/api/puppeteer.page.emulatemediatype.md
jrandolf f07ad2c661
fix: update documentation on configuring puppeteer (#9150)
This PR updates the docs regarding configuring puppeteer. In addition,
some changes have been made to the documentation generator to show
default values on the documentation site.

Also fixes: https://github.com/puppeteer/puppeteer/pull/9144
2022-10-24 09:07:05 +02:00

1.4 KiB

sidebar_label
Page.emulateMediaType

Page.emulateMediaType() method

Signature:

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

Parameters

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

Returns:

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