Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Puppeteer’s page.emulateMediaType() to switch a page’s CSS media rules between print and screen. Choose 'print' or 'screen'; pass null to clear the override. Puppeteer’s page.pdf() uses print styling by default, so select screen media first when you want a screen-styled PDF.

Switch a page between print and screen CSS

After opening a page, await page.emulateMediaType() before checking its state or generating output. The method selects CSS media type; it does not send a job to a physical printer.

await page.emulateMediaType('print');
await page.emulateMediaType('screen');
await page.emulateMediaType(null); // disable CSS media emulation

The accepted values documented by Puppeteer are 'print', 'screen', and null. To check which media query matches, evaluate matchMedia() in the page context:

const isPrint = await page.evaluate(() => matchMedia('print').matches);
const isScreen = await page.evaluate(() => matchMedia('screen').matches);
console.log({ isPrint, isScreen });

After selecting print, the print query matches and the screen query does not; selecting screen reverses those results. Passing null disables CSS media emulation, restoring the default behavior described in Puppeteer’s example. See the Page.emulateMediaType() API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Generate PDFs with the intended CSS

page.pdf() uses print CSS media by default. For a conventional print-styled PDF, call it directly or explicitly select print. To render screen styles instead, select screen before generating the PDF.

await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf' });

These settings choose the CSS media type used for rendering; they do not guarantee identical colors across browser versions or output devices. Puppeteer notes that PDF colors are adjusted for printing by default. Its PDF documentation points to -webkit-print-color-adjust when you need to force exact colors in CSS. See Page.pdf() documentation and PDF generation.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Complete example: check media and save both PDFs

This Node.js example opens a page, checks the active media query, writes a print-styled PDF, then writes a screen-styled PDF. It clears the media override before closing the browser.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();
  await page.goto('https://example.com');

  await page.emulateMediaType('print');
  const isPrint = await page.evaluate(() => matchMedia('print').matches);
  console.log({ isPrint });
  await page.pdf({ path: 'print.pdf' });

  await page.emulateMediaType('screen');
  await page.pdf({ path: 'screen.pdf' });

  await page.emulateMediaType(null);
} finally {
  await browser.close();
}

Install Puppeteer in the project before running the example, and use the API reference matching your installed version: the cited documentation includes current and Next pages, and APIs can change between versions. The example reflects documented behavior; it is not a claim of independent execution or testing.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the right Puppeteer control

Media type, device emulation, and media feature emulation affect different things:

Need API Effect
Apply @media print or @media screen rules page.emulateMediaType('print' | 'screen') Selects CSS media type.
Clear the CSS media override page.emulateMediaType(null) Disables CSS media emulation.
Change device viewport and user agent page.emulate(device) Sets device metrics and user agent. Puppeteer recommends doing this before navigation because some sites do not expect viewport changes after loading.
Set conditions such as dark mode or reduced motion page.emulateMediaFeatures([...]) Sets CSS media feature values rather than selecting print or screen media type.
Create a PDF page.pdf() Generates PDF output using print media by default.

Read the references for emulateMediaFeatures() and emulate() for their separate options and version-specific details.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Troubleshoot unexpected rendering

  • The PDF uses print styles when screen styles were expected: call and await page.emulateMediaType('screen') before page.pdf().
  • Your media query still appears to match the previous type: await the emulation call, then check the result inside page.evaluate(() => matchMedia('print').matches) or the corresponding screen query.
  • The page should return to normal media behavior: pass null to page.emulateMediaType().
  • A device viewport or user agent needs to change: use page.emulate(device), not media type emulation; configure it before navigation where possible.
  • Dark mode or reduced-motion rules need to change: use page.emulateMediaFeatures(), because those are media features, not media types.
  • PDF colors look different from the browser: printing can adjust PDF colors by default. Consult Puppeteer’s PDF guidance on -webkit-print-color-adjust; do not assume this guarantees identical output on every browser or device.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you only need a website screenshot or PDF rather than a Puppeteer script, ScreenshotNeo provides a one-request screenshot API. This cURL request saves a WebP capture; see the ScreenshotNeo documentation for API options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie banners and consent overlays, newsletter popups, and chat widgets are removed before capture; each of those steps can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers report the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.