Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › browser automation

How to Take a Playwright Screenshot of a PDF Viewer Page

By Freedom251 Team · · 4 min read

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

For a PDF already open in a browser viewer, use page.screenshot() after the visible page has rendered, then inspect the resulting image in the browser mode you plan to use. This captures the current browser page view; it is not a documented way to capture every page of the PDF. Playwright’s Page API specifically warns that “Headless mode doesn’t support navigation to a PDF document.”

Capture the visible PDF viewer page

If your page has already opened a PDF in a browser’s built-in viewer and you want an image of what is currently visible, take an ordinary page screenshot after navigation and rendering:

As an Amazon Associate I earn from qualifying purchases.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();

  await page.goto('https://example.com/document.pdf');
  // Confirm the PDF viewer has rendered in your target browser configuration.
  await page.screenshot({ path: 'pdf-viewer.png' });

  await browser.close();
})();

Replace the example URL with your PDF URL. This is a starting point, not a universal recipe: built-in PDF viewer behavior can differ by browser and launch mode, and Playwright’s generic screenshot documentation does not guarantee access to the viewer’s internal controls or rendered surface. Open the saved image and confirm it contains the expected page.

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

What each Playwright screenshot method captures

Method or option What it is for PDF viewer implication
page.screenshot() An image of the current browser page. Try it for the currently visible viewer area, then verify the output.
page.screenshot({ fullPage: true }) The full scrollable web page. It is not documented as capturing every sheet or page in a PDF document.
page.locator('selector').screenshot() An image of a particular DOM element. It works only if the target surface is exposed as a selectable element; the docs do not guarantee that native viewer surfaces are accessible this way.
page.pdf() Generates a PDF from a webpage, using print CSS by default. It does not create a PNG of a PDF viewer.

The Page API and Screenshots documentation describe generic page and element screenshots, but do not promise that fullPage enumerates the pages of a browser PDF viewer. If you need every document page, use a workflow with explicit control over PDF page rendering, such as an HTML PDF viewer or separate page images.

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Direct PDF navigation in headless mode

The current Playwright Page API documentation says: “Headless mode doesn’t support navigation to a PDF document.” That warning concerns navigating directly to a PDF in headless mode. It does not establish that every screenshot operation or every browser mode fails when a PDF viewer is involved. If your job relies on a built-in viewer, verify behavior in the exact browser configuration used by your project.

Capture an ordinary HTML page or element

For a regular HTML page, the standard capture call is:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
await page.screenshot({ path: 'screenshot.png' });

To capture the full scrollable HTML page:

await page.screenshot({ path: 'full-page.png', fullPage: true });

To capture a DOM element:

await page.locator('selector').screenshot({ path: 'element.png' });

Playwright supports PNG, JPEG, and WebP screenshots, along with screenshot scale options. These APIs apply to what the page exposes; they should not be treated as a guarantee about browser-native PDF viewer internals.

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.

When you need a PDF rather than an image

page.pdf() creates a PDF from a webpage; it is not a screenshot of a PDF that is open in the viewer. By default it uses print CSS. If you need the webpage’s screen styling in the generated PDF, emulate screen media first:

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.
await page.emulateMedia({ media: 'screen' });
await page.pdf({ path: 'webpage.pdf' });

Visual regression testing

For Playwright Test visual regression checks, expect(page).toHaveScreenshot() is an assertion that waits for two consecutive screenshots to match before comparing with the expected snapshot. It is distinct from saving a one-off screenshot with page.screenshot().

Troubleshooting

  • The direct PDF navigation fails in headless mode: this is consistent with the Page API’s documented limitation. Do not assume that changing screenshot options will make headless navigation to a PDF supported; use a workflow that explicitly renders the PDF pages or verify a suitable viewer setup.
  • The screenshot is blank or does not show a rendered PDF page: the viewer may not have rendered, or its surface may not be exposed to the screenshot API in that configuration. Inspect the image and verify the result in the same browser mode the project uses.
  • fullPage: true captures only part of the document: full-page mode refers to the web page’s scrollable content, not a documented enumeration of PDF pages. Use explicit PDF page rendering if you need the whole document.
  • A locator screenshot cannot find the viewer surface: locator screenshots target DOM elements. Check what the page exposes; native viewer controls or surfaces are not guaranteed to be selectable.
  • The output is a PDF instead of an image: use page.screenshot() for an image. page.pdf() generates a PDF from webpage content.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo accepts a URL in one GET request and returns a screenshot in PNG, JPEG, or WebP, or a PDF. It is intended for website captures, not a promise to render every page of a directly linked PDF through a browser’s built-in viewer. For website pages, cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo API documentation for request options. ScreenshotNeo is a website screenshot API and MCP server made by Yorker Media; visit ScreenshotNeo for service details. Sign up for 1,000 free screenshots a month with no card.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.
Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

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.

browser automationPDFPlaywrightscreenshots

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.

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.