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

Pass an absolute filename to Playwright’s path option. In JavaScript or TypeScript, build it with path.resolve(); in Python, resolve a pathlib.Path and convert it to a string. Create the parent directory first when it may not exist, then use fullPage: true (or full_page=True) when you need the entire scrollable document instead of only the current viewport.

The shortest working solution

page.screenshot() writes to the file named by its path option. A relative path is resolved from the process’s current working directory, which can change depending on how you start your script, IDE, test runner, or CI job. Resolve the destination once and pass the resulting absolute path.

JavaScript or TypeScript

import path from 'node:path';

const outputPath = path.resolve(process.cwd(), 'artifacts', 'page.png');
await page.screenshot({ path: outputPath, fullPage: true });

The filename extension tells Playwright which image format to write. Use .png, .jpg (or .jpeg), or .webp as appropriate for your workflow.

Python

from pathlib import Path

output_path = (Path.cwd() / 'artifacts' / 'page.png').resolve()
await page.screenshot(path=str(output_path), full_page=True)

Python’s API uses full_page=True with an underscore, while the JavaScript and TypeScript API uses fullPage: true.

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

Build a reliable absolute path

Resolve from a deliberate base directory

process.cwd() and Path.cwd() represent the directory from which the process was launched. That is useful for project-relative artifacts, but it is not necessarily the directory containing your source file. If your application has a known project root, resolve from that root instead of assuming the caller’s working directory.

import path from 'node:path';

const projectRoot = process.cwd();
const outputPath = path.resolve(projectRoot, 'artifacts', 'screenshots', 'home.webp');

Once outputPath is created, changing directories later does not change where the screenshot is saved. Log the resolved value when diagnosing a path problem:

console.log(`Writing screenshot to: ${outputPath}`);
await page.screenshot({ path: outputPath });

Create missing parent directories

Playwright can write the file, but your code should create a missing directory tree. The recursive option makes the operation safe when some or all folders are absent.

import fs from 'node:fs/promises';
import path from 'node:path';

const outputPath = path.resolve(process.cwd(), 'artifacts', 'screenshots', 'home.png');
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await page.screenshot({ path: outputPath, fullPage: true });

Python equivalent:

from pathlib import Path

output_path = (Path.cwd() / 'artifacts' / 'screenshots' / 'home.png').resolve()
output_path.parent.mkdir(parents=True, exist_ok=True)
await page.screenshot(path=str(output_path), full_page=True)

Use platform-safe path construction

Do not concatenate path fragments with / or yourself. Node’s path.resolve() and Python’s pathlib select the correct separator for Windows, macOS, and Linux. An absolute Windows path such as C:buildartifactshome.png is valid when passed as a string; constructing it with path.resolve() avoids escaping and separator mistakes in source code.

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
  • 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

Choose viewport, full-page, or element capture

Goal JavaScript/TypeScript Python
Current viewport only await page.screenshot({ path: outputPath }); await page.screenshot(path=str(output_path))
Entire scrollable page await page.screenshot({ path: outputPath, fullPage: true }); await page.screenshot(path=str(output_path), full_page=True)
One element await page.locator('header').screenshot({ path: outputPath }); await page.locator('.header').screenshot(path=str(output_path))

fullPage/full_page captures the complete scrollable document. Omit it when a viewport-sized image is required. For a component, use the locator screenshot method so the file contains only that element rather than the whole page.

Complete browser scripts

TypeScript example

import { chromium } from 'playwright';
import fs from 'node:fs/promises';
import path from 'node:path';

const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
await page.goto('https://example.com', { waitUntil: 'networkidle' });

const outputPath = path.resolve(process.cwd(), 'artifacts', 'example', 'home.png');
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await page.screenshot({ path: outputPath, fullPage: true });
console.log(outputPath);

await browser.close();

For a production capture, replace networkidle with a readiness condition that matches the site, such as waiting for a known heading or chart. A page can be technically idle before client-side content has rendered.

Python async example

import asyncio
from pathlib import Path
from playwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page(viewport={"width": 1440, "height": 900})
        await page.goto('https://example.com', wait_until='networkidle')

        output_path = (Path.cwd() / 'artifacts' / 'example' / 'home.png').resolve()
        output_path.parent.mkdir(parents=True, exist_ok=True)
        await page.screenshot(path=str(output_path), full_page=True)
        print(output_path)

        await browser.close()

asyncio.run(main())

Saving screenshots in Playwright Test

When the code runs under Playwright Test, prefer the test-scoped output helper for files that belong to a test result. It places the artifact in the runner’s configured output area and keeps files from workers and retries separated.

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

test('capture homepage', async ({ page }, testInfo) => {
  await page.goto('https://example.com');
  await page.screenshot({
    path: testInfo.outputPath('homepage.png'),
    fullPage: true
  });
});

Use a normal resolved path when an application or a build step needs a stable, project-controlled location. Use testInfo.outputPath() when the file is an artifact of one test invocation and should follow Playwright Test’s reporting, retry, and worker conventions.

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.
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.

Visual snapshot assertions

expect(page).toHaveScreenshot() is different from an ad hoc screenshot. It creates and compares reference images in the snapshots area. Keep snapshot files inside the snapshots directory for the test file, and configure the snapshot path template when a repository needs a deterministic layout. Do not treat a snapshot baseline as a general export directory: its location is part of the visual-comparison system.

Common path mistakes and fixes

The file appears in the wrong folder

A relative path follows the process current working directory, not necessarily the directory of the script. Print process.cwd() or Path.cwd(), then switch to path.resolve() or Path.resolve(). In a test suite, check whether the runner changes its working directory before invoking your test.

ENOENT or “directory not found”

The parent directory does not exist. Call fs.mkdir(path.dirname(outputPath), { recursive: true }) in Node or output_path.parent.mkdir(parents=True, exist_ok=True) in Python before taking the screenshot.

EACCES, EPERM, or a permission error

The destination is not writable by the account running the browser process. Choose a directory your process owns, fix its permissions, or write to the test runner’s output directory. On CI, also verify that the workspace is not mounted read-only.

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.
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

The screenshot is blank or missing dynamic content

A valid path does not guarantee a fully rendered page. Wait for a meaningful selector, a deliberate delay for animation, or an appropriate load state before capture. If content is below the fold, use fullPage: true/full_page=True. If lazy-loaded images appear only after scrolling, trigger the page’s normal scroll behavior before capture and verify the resulting image.

Windows paths contain unexpected escapes

Hard-coded backslashes in JavaScript strings can become escape sequences. Construct the path with path.resolve() or use a raw, correctly escaped Python path. Never mix a drive-letter path with a relative fragment without resolving it.

Parallel tests overwrite one file

Give each test a unique filename, or use testInfo.outputPath(), which is designed for test-scoped artifacts. Include a test identifier, project name, or timestamp only when reproducibility allows it; visual snapshots should remain deterministic.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Format, timing, and reliability considerations

Choose the extension intentionally

Playwright infers the image type from the filename extension. PNG is lossless and usually best for pixel comparisons or text-heavy pages. JPEG is smaller but lossy, so compression can create differences in visual tests. WebP is useful when your downstream system accepts it. Keep the extension aligned with what consumers expect.

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.

Make page state deterministic

  • Set a fixed viewport and, when relevant, a fixed device scale factor.
  • Wait for the application’s real ready state rather than relying only on elapsed time.
  • Disable or freeze animations for visual comparison runs.
  • Use stable test data and consistent fonts in CI.
  • Capture after cookie banners, dialogs, or other overlays have been handled if they are not part of the intended image.

Large full-page captures

A very tall document produces a larger image and can take longer to render and write. If the consumer needs only a section, capture a locator instead. If the consumer needs separate pages, split the task into deliberate regions rather than relying on an enormous single bitmap.

Or skip the browser setup:

ScreenshotNeo provides a website screenshot API and MCP server for developers. One GET request returns a PNG, JPEG, WebP, or PDF. The API can load lazy images for full-page captures, select one element by CSS selector, set a viewport or device preset, use retina scale, wait for a selector, delay, or network idle, and apply custom CSS or JavaScript. It also supports dark mode, hiding selectors, click-before-capture actions, request/resource blocking, headers, cookies, user agents, Authorization, timezone and geolocation, transparent backgrounds, resizing, cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, and a usage API.

Example cURL request (see the ScreenshotNeo documentation for all parameters):

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

Python

import requests

r = requests.get('https://api.screenshotneo.com/v1/shot', params={'access_key': 'YOUR_API_KEY', 'url': 'https://stripe.com'}, timeout=90)
r.raise_for_status()
open('shot.webp', 'wb').write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot failed: ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before the shot; those cleanup 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 X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to 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 shots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Sign up for the free ScreenshotNeo plan to make your first captures without configuring a browser.

A practical decision guide

  • Use page.screenshot({ path }): your application already owns a Playwright browser and you need a file at a path you control.
  • Use testInfo.outputPath(): the image belongs to a Playwright Test run and should follow its artifact and retry handling.
  • Use toHaveScreenshot(): the image is a visual assertion baseline, not merely an exported file.
  • Use a locator screenshot: only one component or region matters.
  • Use ScreenshotNeo: you want an HTTP or MCP workflow, pre-capture removal of common overlays, explicit billing verdicts, or capture without maintaining browser setup.

Final checklist

  1. Construct an absolute file path with path.resolve() or Path.resolve().
  2. Create the parent directory before calling the screenshot method.
  3. Choose viewport, full-page, or locator capture deliberately.
  4. Use the correct option spelling for your language.
  5. Wait for the page state your screenshot actually requires.
  6. Use a unique or test-scoped filename under parallel execution.
  7. Confirm the extension matches the required image format.
  8. Log the resolved path and verify write permissions when troubleshooting.

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.