Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
FREEDOM251

Freedom251 › Blog › Next.js

How to Take a Screenshot of a Next.js Page with Playwright

By Freedom251 Team · · 5 min read

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

Use Playwright’s page.goto() to open your running Next.js route, then page.screenshot() to save the visible browser viewport. Add fullPage: true for the full scrollable page, or call screenshot() on a locator to capture one component.

Set up Playwright and make the Next.js app available

Playwright automates Chromium, Firefox and WebKit through one API, as the Next.js Playwright guide explains. For a new setup, Next.js points to pnpm create playwright for manual installation and to the create-next-app Playwright example as a quickstart. You can also add Playwright to an existing app using its setup flow.

As an Amazon Associate I earn from qualifying purchases.

The browser needs a reachable app URL. Start the Next.js development server separately and use an absolute URL such as http://localhost:3000/, or configure a baseURL so tests can navigate with relative paths. Playwright Test can also start the server and wait for it to become available through its webServer configuration. For behavior closer to production, the Next.js guide recommends building and starting the production app before running Playwright.

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

Capture a route from a Playwright test

This is a minimal TypeScript test using Playwright Test. It opens the home route and saves the current viewport as a PNG:

#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
import { test } from '@playwright/test';

test('save a page screenshot', async ({ page }) => {
  await page.goto('http://localhost:3000/');
  await page.screenshot({ path: 'screenshot.png' });
});

Save it in a test file and run it with your Playwright Test setup. The path is relative to the test process’s working directory, which must be writable. The default screenshot scope is the visible viewport.

For a route other than the home page, replace / with the route path, for example /products. If you configured baseURL, you can pass that relative path to page.goto().

Choose viewport, full-page or element capture

Visible viewport

Use page.screenshot({ path: 'page.png' }) when you want what is visible in the browser window. This is the default behavior documented in Playwright’s screenshot guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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

Full scrollable page

Add fullPage: true to capture the page’s full scrollable height:

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

One component

Use a locator’s screenshot() method to save a specific element. Playwright scrolls the element into view and performs actionability checks before capture:

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

If the locator targets a scrollable container, the screenshot shows only the content currently scrolled into view within that container; it does not automatically capture all of the container’s off-screen contents. The Locator API documentation describes the method and its options.

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.

Keep the image in memory

Omit path to receive the screenshot as a buffer, useful for image processing or pixel-diff tools:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const image = await page.screenshot();

Wait for the page state you intend to capture

Navigation completing does not necessarily mean that your application data, images or visual effects have settled. Wait for a meaningful condition that represents the state you want, such as a key heading being visible:

import { test, expect } from '@playwright/test';

test('capture the home page', async ({ page }) => {
  await page.goto('http://localhost:3000/');
  await expect(page.locator('h1')).toBeVisible();
  await page.screenshot({ path: 'artifacts/home.png', fullPage: true });
});

The selector should match your page; the heading is only an example. For a component capture, wait for that component or another reliable readiness signal before taking the screenshot.

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

For less volatile captures, locator screenshots support options such as animations: 'disabled'. The locator API also documents stylesheet options for stabilizing a capture. If you use visual comparisons, the Playwright visual comparisons guide describes using a stylesheet to remove changing content. Keep masking or hiding restricted to areas that are genuinely irrelevant to the behavior being reviewed.

Save screenshots automatically with Playwright Test

For screenshots managed by the test runner, configure the screenshot option in playwright.config.ts. Its documented modes are off, on, only-on-failure and on-first-failure; the default is off. For example, to save screenshots only when a test fails:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: {
    screenshot: 'only-on-failure',
  },
});

The TestOptions documentation covers the available screenshot settings, including full-page capture. For a test-specific file location or attachment, use testInfo.outputPath() and testInfo.attach(); those APIs are useful for organized test artifacts but are not needed for a one-off local screenshot.

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

Troubleshoot missing or unreliable captures

  • The browser cannot reach the route: confirm that the Next.js server is running and that the URL, port and route are correct. Alternatively, configure Playwright’s webServer to start the app and wait for it.
  • The image is shorter than expected: the default captures only the viewport. Set fullPage: true for the page’s full scrollable height.
  • The screenshot is blank or lacks expected content: wait for a page-specific condition, such as a visible heading or loaded component, before capture. Do not assume navigation alone means the application has finished rendering its intended state.
  • A component is clipped: check the selected locator and whether it is inside a scrollable container. Locator screenshots scroll the element into view, but a scrollable container’s capture is limited to the content currently visible within it.
  • The test cannot save the file: make sure the path’s parent directory exists where required by your setup and that the test process can write to it. Use a test output path when you want artifacts managed by Playwright Test.
  • Visual comparisons change between runs: rendering can vary with operating system, browser version, settings, hardware, power source and headless mode. Keep the execution environment consistent and manage genuinely dynamic content deliberately, as noted in the visual comparison documentation.

Or skip the browser setup

If you only need an image or PDF from a URL, ScreenshotNeo offers a website screenshot API and MCP server for developers. Its API takes a URL in one GET request. For example, this cURL command saves a WebP screenshot of the Next.js page; replace the example URL with your deployed route and use your API key:

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 API documentation for request options. Before capture, it accepts cookie/consent banners 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 and CAPTCHAs, blank pages, timeouts, failed loads and cache hits cost nothing, and response headers report the page verdict and whether the shot was billed. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up free for 1,000 screenshots a month, with no card required.

Keep visual baselines repeatable

For visual testing, capture the same route and application state in a stable browser and execution environment. Playwright’s visual comparison feature waits for consecutive matching captures and stores a baseline on the first run; later runs compare against it. Because rendering may differ across environments, do not treat a changed image as an application regression until you have accounted for environment and dynamic-content differences.

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.

Next.jsPlaywrightscreenshot testingWeb development

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.