DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Emulate Print and Screen Media with Puppeteer

Learn how to switch Puppeteer between print and screen CSS, verify the active media query, and generate PDFs with the intended styling.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use page.emulateMediaType('print') or page.emulateMediaType('screen') to make a Puppeteer page apply the corresponding CSS media rules. Pass null to clear the override. For PDFs, Puppeteer uses print media by default; select screen media first if the PDF should use screen styling.

Switch a page between print and screen CSS

Call Page.emulateMediaType() on the page and await it before checking page state or generating output. The accepted values are 'print', 'screen', and null. The Puppeteer API reference documents that passing null disables CSS media emulation: Page.emulateMediaType().

As an Amazon Associate I earn from qualifying purchases.

await page.emulateMediaType('print');
await page.emulateMediaType('screen');
await page.emulateMediaType(null);

These calls select which CSS media type the page reports and therefore which matching @media print or @media screen rules apply. They do not send a job to a physical printer.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Check which media type is active

Read the media query in the page context with matchMedia(). This is useful for confirming the emulation state before taking a screenshot or creating a PDF.

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

After choosing print, the print query should match; after choosing screen, the screen query should match. Passing null removes the emulated override and restores the browser’s default behavior.

Generate print-styled or screen-styled PDFs

page.pdf() uses print CSS media by default. Usually, you can call it directly to create a PDF intended to follow print styles. To create a PDF using the page’s screen styling, first choose screen media, then call page.pdf(). See Puppeteer’s PDF API reference and PDF generation guide.

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
// Print CSS is the default for PDF generation.
await page.pdf({ path: 'print.pdf' });

// Select screen CSS explicitly for the next PDF.
await page.emulateMediaType('screen');
await page.pdf({ path: 'screen-styled.pdf' });

Print-oriented PDF output may adjust colors for printing. Puppeteer’s PDF documentation points to the CSS property -webkit-print-color-adjust when exact colors should be forced. This does not guarantee identical colors across browser versions or output devices.

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

Complete example: check both modes and save PDFs

This example navigates to a page, checks the active media query, saves a print-mode PDF, then switches to screen mode for a second PDF. It also clears the media override before reusing the page.

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');
  const isScreen = await page.evaluate(() => matchMedia('screen').matches);
  console.log({ isScreen });
  await page.pdf({ path: 'screen.pdf' });

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

Install Puppeteer in the project before running this ES module example, and use the API documentation matching the Puppeteer version installed in that project. Puppeteer’s stable and Next documentation can differ as the API evolves.

Choose the right emulation API

Media type, media features, and device characteristics affect different parts of page rendering. Pick the control that matches the change you want.

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
Goal API What it changes
Apply print or screen CSS rules page.emulateMediaType('print') or page.emulateMediaType('screen') CSS media type
Clear the CSS media override page.emulateMediaType(null) Disables CSS media emulation
Change device viewport and user agent page.emulate(device) Device metrics and user agent; Puppeteer recommends applying device emulation before navigation because some sites do not expect viewport changes after load. See Page.emulate().
Set conditions such as dark mode or reduced motion page.emulateMediaFeatures([...]) CSS media feature values, not the media type. See Page.emulateMediaFeatures().
Create a PDF page.pdf() PDF output; print media is the default.

Troubleshoot media emulation

  • Print styles do not appear: await page.emulateMediaType('print') before checking the page or producing output. Confirm the page’s CSS contains matching @media print rules and verify with matchMedia('print').matches.
  • A PDF looks different from the page on screen: that is expected when print CSS is active, because page.pdf() uses print media by default. Select 'screen' before PDF generation if screen styling is the goal.
  • Dark mode or reduced-motion rules do not change: those are media features rather than media types. Use page.emulateMediaFeatures() for feature conditions.
  • The page layout changes after device emulation: device emulation changes viewport and user agent, unlike media-type selection. Apply page.emulate(device) before navigation where possible.
  • Subsequent work still behaves as print or screen: call await page.emulateMediaType(null) to clear the emulation override.
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 need an image screenshot or PDF without managing Puppeteer, ScreenshotNeo offers a one-request API and an MCP server. Its capture flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. AI agents can use its MCP tools, including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. See the ScreenshotNeo website and API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.