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

Use Playwright’s page.screenshot() with a clip object: x and y set the rectangle’s top-left corner, while width and height set its size. The coordinates are CSS pixels in the current viewport.

const image = await page.screenshot({
  path: 'region.png',
  clip: { x: 120, y: 80, width: 640, height: 360 },
});

This captures a 640×360 CSS-pixel rectangle beginning 120 pixels from the left and 80 pixels from the top of the viewport. The sections below show how to make the geometry repeatable, derive coordinates from elements, choose image scale, and diagnose common failures.

What the clip rectangle means

The clip option is an object with four required dimensions:

  • x: horizontal position of the top-left corner, measured from the viewport’s left edge.
  • y: vertical position of the top-left corner, measured from the viewport’s top edge.
  • width: rectangle width.
  • height: rectangle height.

These values describe CSS-pixel geometry. They are not automatically the number of pixels in the saved bitmap: device-scale screenshots can contain more raster pixels than the CSS dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Minimal runnable example

import { chromium } from 'playwright';

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

await page.screenshot({
  path: 'region.png',
  clip: { x: 120, y: 80, width: 640, height: 360 },
  scale: 'css',
});

await browser.close();

Save this as an ES module (for example, capture.mjs) and run it with a project that has Playwright installed. The explicit viewport and scale: 'css' make the output easier to compare across runs.

Set the viewport before navigation

Playwright documents a default browser-context viewport of 1280×720. Relying on defaults can hide layout changes in CI or between projects, so choose dimensions deliberately.

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

Set the viewport before loading the page whenever possible. Responsive breakpoints, font wrapping, sticky headers and lazy content all depend on viewport dimensions. Changing viewport-related settings after navigation can alter layout and invalidate previously measured coordinates. Disabling consistent viewport emulation makes screenshot geometry non-deterministic.

Choose the right capture method

Capture an arbitrary rectangle

Use page.screenshot({ clip }) when the rectangle is defined by coordinates rather than by a DOM element.

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.
await page.screenshot({
  path: 'header-region.png',
  clip: { x: 0, y: 0, width: 1280, height: 180 },
});

The clip is taken from the page’s current viewport. If the page has scrolled, the same y value refers to the new viewport position, not the document’s original top.

Capture the complete scrollable page

Set fullPage: true when you need the document’s full scrollable height rather than a fixed viewport rectangle.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
await page.screenshot({
  path: 'full-page.png',
  fullPage: true,
});

Do not combine a full-page requirement with a manually chosen clip unless you intentionally want a clipped portion of the page. Full-page capture is affected by content that appears only after scrolling, so wait for the relevant content before capturing.

Capture one identified element

For a known UI element, a locator screenshot is usually safer than converting a bounding box into a manual clip.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.getByRole('navigation').screenshot({
  path: 'navigation.png',
});

A locator screenshot waits for actionability and scrolls the target into view before capturing its bounds. Covered content may still be hidden by another layer, and a scrollable element shows only the portion currently visible inside it.

Return bytes instead of writing a file

Omit path to receive a buffer for upload, image processing or an assertion.

const imageBuffer = await page.screenshot({
  clip: { x: 40, y: 120, width: 800, height: 450 },
  type: 'png',
});
// imageBuffer is a Buffer in Node.js

Derive coordinates from a locator

When a region follows an element’s position, ask Playwright for its bounding box immediately before capture.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
const card = page.locator('.product-card').first();
await card.waitFor({ state: 'visible' });
const box = await card.boundingBox();
if (!box) throw new Error('The card has no visible bounding box');

await page.screenshot({
  path: 'card.png',
  clip: {
    x: box.x,
    y: box.y,
    width: box.width,
    height: box.height,
  },
  scale: 'css',
});

Bounding boxes are relative to the viewport and are expressed in CSS pixels. Scrolling, sticky elements, animations and responsive reflow can change them, so measure and capture in the same stable state. If the target is simply an element, prefer locator.screenshot(); it handles scrolling and actionability for you.

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

Add padding around an element

Expand the measured rectangle, then clamp it to the viewport to avoid negative coordinates or an area extending beyond the visible page.

const padding = 16;
const viewport = page.viewportSize();
if (!box || !viewport) throw new Error('Missing geometry');

const x = Math.max(0, box.x - padding);
const y = Math.max(0, box.y - padding);
const right = Math.min(viewport.width, box.x + box.width + padding);
const bottom = Math.min(viewport.height, box.y + box.height + padding);

await page.screenshot({
  path: 'card-with-padding.png',
  clip: { x, y, width: right - x, height: bottom - y },
});

This example intentionally captures what is visible in the viewport. For an element below the fold, scroll it into view first or use its locator screenshot.

CSS pixels, device pixels and scale

Playwright’s screenshot scale controls the relationship between CSS geometry and output raster resolution:

  • scale: 'css' produces one output pixel per CSS pixel. A 640×360 clip therefore produces a 640×360 image (subject to format metadata).
  • scale: 'device' preserves device-pixel resolution. On a high-DPI context, the bitmap can be larger than the CSS dimensions.

Use css for deterministic image dimensions, visual-diff baselines and downstream systems that expect CSS-sized assets. Use device when retaining high-DPI detail matters. The default is device.

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.

Make the captured state deterministic

Wait for the content you actually need

await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await page.locator('.hero').waitFor({ state: 'visible' });
await page.waitForTimeout(300); // only when a known animation needs settling

A selector wait is generally more meaningful than an arbitrary delay. If images are lazy-loaded, scroll the relevant area into view and wait for the image’s completion state before measuring.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Freeze movement before measuring

Animations and transitions can move an element between boundingBox() and screenshot(). Disable them with a test-only stylesheet or wait until the animation finishes. Also account for cookie dialogs, chat launchers and sticky headers: they can cover the intended rectangle even when its coordinates are correct.

Scroll deliberately

await page.locator('#report').scrollIntoViewIfNeeded();
const reportBox = await page.locator('#report').boundingBox();

After scrolling, re-read the bounding box. Do not reuse coordinates measured before the scroll.

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

Common failures and fixes

“Clip is outside the viewport” or an invalid rectangle

Check that x, y, width and height are finite, non-negative numbers and that the intended region exists at capture time. Clamp an expanded rectangle to the viewport, as shown above. A negative width or height is a calculation error, not a Playwright feature.

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

The screenshot is the wrong part of the page

The coordinates are viewport-relative. Confirm the current scroll position, measure after scrolling, and ensure no responsive breakpoint changed the layout. Set the viewport before navigation.

The element is missing or partially visible

Wait for the locator, call scrollIntoViewIfNeeded(), and check whether an overlay covers it. For a scrollable container, locator capture includes only its currently visible content; scroll that container separately if you need another portion.

The file dimensions are larger than the clip

This is normally device scaling. Set scale: 'css' when one output pixel per CSS pixel is required.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

A full-page image omits late content

Wait for the application’s data and images before calling fullPage. Lazy-loaded content may not exist until its region has been scrolled or otherwise triggered.

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

Captures differ between local and CI

Use a fixed viewport, the same browser engine and browser version, stable test data, and a consistent scale. Remove or wait for animations and avoid measuring during layout changes. The documented API behavior does not by itself guarantee identical results across every browser engine or historical Playwright version.

Performance, format and repeatability choices

  • Use a clip instead of fullPage when only a small region is needed; less content generally means less image data and faster processing.
  • Choose PNG for lossless UI text and visual comparisons. JPEG or WebP can reduce file size when some compression is acceptable.
  • Keep a single browser and context alive for batches of captures, while creating pages as needed; launching a browser for every image adds avoidable overhead.
  • Capture after the final layout state, not immediately after navigation, to avoid retries caused by shifting geometry.
  • Record viewport, scale, browser engine and target URL alongside generated images so a later difference is explainable.

Or skip the browser setup

ScreenshotNeo provides a website screenshot API when you do not need to maintain Playwright, browser binaries or viewport orchestration. It accepts a URL and can return PNG, JPEG, WebP or PDF; its options include full-page capture, CSS-selector element capture, custom viewport and device presets, retina scale, waits, custom CSS and JavaScript, hidden selectors, request blocking, headers, cookies, user agents, timezone and geolocation.

Before the capture, ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server with take_screenshot, get_page_info and capture_pdf for Claude, Cursor and other MCP clients.

One-call cURL example

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 all parameters, including clipping and output controls.

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

Python

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://example.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://example.com'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

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. Create a free ScreenshotNeo account to make the first captures.

Frequently Asked Questions

Can I use negative x or y values to capture outside the viewport?

Treat clip coordinates as a visible viewport rectangle and keep them non-negative; use scrolling or a different capture method to reach content outside the current viewport.

Should I use a locator screenshot or a manual clip for a component?

Use a locator screenshot when the component is identified in the DOM. Use a manual clip when the required area is an arbitrary coordinate-based rectangle or combines several regions.

Why does a high-DPI screenshot have more pixels than the CSS width?

The default device scale preserves device-pixel resolution. Set scale: 'css' for one output pixel per CSS pixel.

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.