October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Node.js

How to Capture a Screenshot of a URL with Playwright

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

In Node.js, use Playwright to launch a browser, open a page, navigate to the URL, and call page.screenshot(). By default, that saves the visible viewport if you provide a file path. Set fullPage: true for the full scrollable page, or capture a matched element with a locator.

Capture a URL with Playwright in Node.js

The basic sequence is navigation first, capture second, and browser cleanup after. This example saves a viewport screenshot as a PNG:

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

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

  try {
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await page.screenshot({ path: 'screenshot.png' });
  } finally {
    await browser.close();
  }
})();

Save the code in a file such as capture.js, make sure the Playwright package is available to the project, and run it with node capture.js. When navigation and capture complete, the image is written to screenshot.png in the process’s current working directory. The try/finally structure ensures the browser is closed even if navigation or screenshot capture throws an error.

The example uses Chromium. Playwright’s documented screenshot workflow also works with WebKit and Firefox; choose the engine that suits the purpose of the capture and the browser setup in your project. The method and options below refer to Playwright’s page and locator screenshot APIs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • 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

Choose what to capture

Pick the capture scope before building downstream processing around the image. A screenshot can represent the current viewport, the full scrollable page, one element, or an image held in memory.

Need Playwright call What it gives you
Visible viewport await page.screenshot({ path: 'view.png' }) The currently visible page area; this is the default screenshot scope.
Full scrollable page await page.screenshot({ path: 'full.png', fullPage: true }) A capture of the full page rather than just the current viewport.
One matched element await page.locator('.header').screenshot({ path: 'header.png' }) An image of the area occupied by the locator’s matched element.
Image bytes for further processing const image = await page.screenshot() Screenshot bytes returned as a buffer instead of being saved to a file.

Viewport screenshot

Use the default page.screenshot() behavior when the visible browser area is what you need—for example, when you want an image of the page as presented in a particular viewport. The call does not imply a full-page capture. If the content extends below the visible area, choose fullPage: true or capture a particular element instead.

Full-page screenshot

Add fullPage: true to request the full scrollable page. This is useful for a page record or a visual review of content beyond the first screen. It is a different scope from capturing the viewport: decide which one your consumer or comparison expects, and use that setting consistently.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • 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: 'full-page.png', fullPage: true });

Element screenshot

Use page.locator(selector).screenshot() when only a component or region matters. For instance, the following captures the matched header after first navigating to the target page:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.goto('https://example.com');
await page.locator('.header').screenshot({ path: 'header.png' });

A locator screenshot scrolls the element into view and waits for actionability checks. If the element becomes detached, Playwright reports an error; see the troubleshooting section before treating an element capture as a guaranteed output.

Save the image or keep it in memory

Pass path to save an image. A relative path is resolved from the current working directory, and Playwright infers the image type from the file extension. The documented types include PNG, JPEG, and WebP. For example, changing the path to page.jpg or page.webp selects the corresponding type.

Rank #3
Sale
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.screenshot({ path: 'page.webp' });

Omit path if the next step in your program needs the image bytes rather than a file:

const image = await page.screenshot();
// Pass image to the next step in your application.

That call returns a buffer; it does not save a file by itself. Choose file output when a human or another process needs a named artifact on disk. Choose a buffer when you intend to pass the bytes on without making a separate file.

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

Useful options for shaping a capture

Region and output scale

The screenshot API includes clip for a specified rectangular region and scale to select CSS-pixel or device-pixel output. Use a clip when a rectangular portion of the page is the intended artifact. Choose the scale deliberately when the output’s pixel dimensions matter to a later consumer; do not compare captures made at different scales as though they were identical outputs.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • 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

Animation and changing content

For a capture where CSS or Web Animations would make the frame inconsistent, the API provides animations: 'disabled'. Visual tests can also use screenshot masking and a stylesheet to suppress or standardize dynamic content. These are ways to control known sources of variation; they do not make different machines render every page identically.

Wait for the page state your work needs

page.goto(url) is the navigation step and should happen before the screenshot call. A successful call to the screenshot API only means the screenshot operation produced bytes or a file; it does not establish that every application-specific element has finished updating or that the page is in the state your downstream use expects.

There is no single readiness condition that is right for every site. A page used for a quick manual review may need a different state from a page used as a repeatable visual-test baseline. Identify what must be present or settled for your particular capture, then choose a readiness strategy appropriate to the page before taking the screenshot. Do not assume that a screenshot taken immediately after navigation always represents the final state of a dynamic page.

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.
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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use screenshots for visual regression tests

For repeatable comparisons, Playwright Test provides expect(page).toHaveScreenshot(). Its first run creates a reference image; later runs compare against that baseline. This is a testing workflow rather than simply saving a one-off screenshot to a path.

Keep the baseline and comparison environment consistent. Playwright warns that rendered output can vary with the host operating system, browser version, settings, hardware, power source, headless mode, and other factors. If those conditions change between the baseline and a later run, differences in the image may reflect the environment as well as changes to the page. Masking or a stylesheet can help standardize dynamic page content, but the browser and host setup still matter.

Troubleshooting common capture problems

  • No screenshot file appears: Check that the screenshot call includes a path. Without one, Playwright returns image bytes instead of saving to disk. Also check the path relative to the process’s current working directory.
  • The image only shows the first screen: The default scope is the visible viewport. Use fullPage: true when the full scrollable page is required.
  • The element capture errors because the element detached: The locator’s target was detached during the operation. Check whether the page replaces that element as it updates, and make sure the intended element is present when the locator screenshot runs.
  • The screenshot is blank or shows the wrong page state: Confirm that the script navigates to the intended URL before capturing. If the site updates after navigation, identify the page-specific state that needs to be ready before the screenshot.
  • A visual comparison changes unexpectedly: Compare the baseline and test on a consistent operating system, browser version, settings, hardware, power source, and headless configuration. Consider standardizing dynamic content with screenshot masking or a stylesheet.
  • Navigation or capture throws an error: Treat navigation and screenshot failures as failures rather than silently using an image from an earlier run. Preserve browser cleanup with a finally block, then investigate whether navigation to that URL succeeded and whether the requested page or element was available.

Or skip the browser setup

If you want an image or PDF from a URL without running your own Playwright browser, ScreenshotNeo is a website screenshot API and MCP server. One GET request returns a clean PNG, JPEG, WebP, or PDF. For example, this cURL request saves a WebP screenshot of Stripe:

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

See the ScreenshotNeo documentation for request details. Before capture, it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

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

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots; yearly billing gives two months free, and every feature is on every plan. Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I use a different browser engine from Chromium?

Yes. The documented screenshot workflow shows WebKit and notes Chromium and Firefox as options. Use the engine that matches your project setup and the purpose of the capture.

Does the basic Playwright example produce a PDF?

No. It writes an image file. The example is for screenshot capture; the output formats described here are PNG, JPEG, and WebP.

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.

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

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.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.