October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Capture Part of a Screen with a Screenshot API

Learn to capture a precise browser-page region with Playwright or Puppeteer, choose element screenshots, avoid coordinate failures, and use ScreenshotNeo when you do not want to run a browser.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture only part of a web page, pass a clipping rectangle—its top-left x and y coordinates plus width and height—to your browser automation library. If the target is a known page element, an element screenshot is usually clearer and less fragile. The examples below use Playwright and Puppeteer for browser pages; these APIs do not capture arbitrary desktop applications or the operating-system screen.

Choose a rectangle or an element

There are two reliable ways to define a partial capture:

  • Coordinate clip: use a rectangle when the region is defined by its position in the page viewport.
  • Element screenshot: use a CSS selector or element handle when the content already has a stable DOM identity.

Coordinates are library- and version-sensitive. Verify whether a library measures them in CSS pixels, how scrolling and device scale are handled, and whether the rectangle must remain inside the viewport. The official references below document the option names but do not establish one universal rule for every screenshot API.

Playwright: capture a rectangular region

Install Playwright, launch a browser, open the page, and pass clip to page.screenshot(). The rectangle’s x and y are its top-left origin; width and height are its dimensions.

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.
import { chromium } from 'playwright';

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

await page.screenshot({
  path: 'region.png',
  clip: { x: 40, y: 80, width: 320, height: 180 }
});

await browser.close();

The numbers are illustrative, not tested coordinates for a particular site. A changing banner, responsive layout, or different viewport can move the desired content. Use the current Playwright Page API reference to confirm valid bounds and coordinate behavior.

Return bytes instead of writing a file

Omit path and keep the returned buffer for storage, image processing, or an HTTP response:

const pngBytes = await page.screenshot({
  type: 'png',
  clip: { x: 40, y: 80, width: 320, height: 180 }
});
// For example: await fs.promises.writeFile('region.png', pngBytes);

Playwright also accepts image-format, quality, and other screenshot parameters. Quality applies to formats that support it; check the version-specific guide before relying on a default.

Playwright: capture a DOM element

If the target is a card, header, chart, or other identifiable element, let Playwright calculate its bounding box:

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.
import { chromium } from 'playwright';

const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');

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

await browser.close();

This avoids hard-coded coordinates and follows the element when responsive CSS changes its position. Use a stable selector and wait for the element to be visible before capturing. If the element is inside a scrollable container, confirm the resulting image includes the intended content and not only the currently visible portion.

Puppeteer: clip a page or element

Puppeteer exposes the same basic rectangle through Page.screenshot():

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setViewport({ width: 1280, height: 800 });
await page.goto('https://example.com', { waitUntil: 'networkidle0' });

await page.screenshot({
  path: 'region.png',
  clip: { x: 40, y: 80, width: 320, height: 180 }
});

await browser.close();

In Puppeteer’s documented 25.12.0 ScreenshotOptions, captureBeyondViewport is false when there is no clip and true when a clip is supplied unless you set it explicitly. Treat that as version-specific behavior and recheck the current reference when upgrading.

For an element, select it and call its screenshot method:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const fileElement = await page.$('.header');
if (!fileElement) throw new Error('Element not found');
await fileElement.screenshot({ path: 'header.png' });

Puppeteer documents that an element screenshot attempts to scroll a hidden element into view. That behavior belongs to Puppeteer, not every browser API.

Partial versus full-page screenshots

A clip is a defined region. A full-page screenshot is a different operation: Playwright describes it as the entire scrollable page, as if the page were displayed on a very tall screen, while Puppeteer provides a fullPage option.

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

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

Choose full-page output for a complete document, not as a substitute for a known region. Combining fullPage and clip can have library-specific restrictions; consult the relevant version’s API reference.

Making coordinates dependable

  1. Set the viewport deliberately. A fixed width and height make coordinates reproducible.
  2. Wait for layout. Use a selector wait, a documented load state, or an application-specific readiness signal before measuring or capturing.
  3. Scroll intentionally. A coordinate is relative to the page/view context defined by your library; scroll first when the target is below the fold.
  4. Prefer selectors for moving content. Element screenshots survive layout changes better than fixed rectangles.
  5. Account for overlays. Cookie dialogs, chat bubbles, sticky headers, and animations can cover the region. Dismiss or hide them before the shot.
  6. Validate bounds. Negative coordinates, zero dimensions, or a rectangle outside the available content can produce errors or an unexpected image.
  7. Check output format. Puppeteer infers type from the file extension when using path; PNG is its documented default, and quality does not apply to PNG.

When you need the whole element, not its visible viewport

An element may contain lazy-loaded images or overflow content. Wait for the images or application state you need, then capture the element. A page clip captures what the page exposes at the chosen coordinates; it does not automatically understand semantic boundaries. If the element’s dimensions change after fonts or images load, measure only after those resources settle.

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

Output, encoding, and post-processing

Both libraries can write an image to a path. Playwright can also return image bytes in memory. Puppeteer documents binary output as the default encoding and supports base64 when requested. Use files for simple pipelines; use buffers or binary responses when an API worker will upload the result directly. Keep format and quality choices next to the code that consumes them so downstream systems know whether they receive PNG, JPEG, or another supported type.

Troubleshooting

The image is shifted or the wrong area

Confirm the viewport, browser scale, scroll position, and whether a sticky header changed the page after navigation. Replace the rectangle with a locator or element screenshot if the target has a stable selector.

The screenshot is blank or incomplete

Wait for the page or target selector, and wait for lazy images and fonts. A page that requires interaction may need a click or a short, bounded delay before capture. Avoid indefinite sleeps; use a readiness condition where possible.

The clip is rejected

Check that width and height are positive numbers and that the values satisfy your installed library’s bounds rules. Re-read the current Playwright or Puppeteer reference after a version upgrade.

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

An overlay appears in the result

Close the consent dialog or chat widget through the page’s normal controls, or hide the responsible selector with your automation code. Make sure doing so complies with the site’s terms and your privacy requirements.

The element cannot be found

Use a stable test identifier or role instead of a generated class, wait for the component to render, and check whether it lives inside an iframe. Frame content must be addressed through the appropriate frame object.

Memory or timeout failures

Use a smaller viewport or clip, avoid unnecessary full-page captures, close browser contexts promptly, and set an explicit navigation timeout. Large images and many concurrent pages increase memory pressure; throttle concurrency and retry only transient navigation failures.

Performance, reliability, and cost considerations

The supplied library documentation describes API behavior, not a performance or reliability winner, so choose based on your language, selector model, and deployment environment. A coordinate clip usually produces less image data than a full-page shot, but navigation and rendering can still dominate runtime. Element screenshots reduce coordinate maintenance, while fixed rectangles are useful for deterministic visual tests when the layout is controlled.

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

Self-hosted Playwright and Puppeteer have no per-shot API charge, but you operate browsers, fonts, sandboxing, patches, queueing, storage, and retries. A managed service trades that infrastructure work for a request-based price; verify its limits, retention, and failure billing before moving production traffic.

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 provides a website screenshot API and MCP server. It can capture a full page or one element, and its cleaning step accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each 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.

For a hosted capture, send one GET request (adapt the URL to your target):

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 complete parameter list and output details in the ScreenshotNeo documentation. The same service supports custom CSS and JavaScript, selectors, dark mode, device presets, viewport and retina scale, PDF options, request blocking, headers, cookies, user agent, authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, usage reporting, and an OpenAPI specification. Common screenshot-API parameter names also work, easing migration.

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://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(`HTTP ${res.status}`);
const data = 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 on every plan, and yearly billing provides two months free. An MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients. Create a free ScreenshotNeo account to try the 1,000 monthly shots without a card.

FAQ

Can this capture my desktop or another application?

No. The documented Playwright and Puppeteer methods capture browser pages. Use an operating-system capture API for arbitrary desktop windows.

Should I use coordinates or a selector?

Use a selector when the target is a DOM element; use coordinates for a deliberately defined viewport region or a visual test with a controlled layout.

Can I process the image without saving it first?

Yes. Playwright returns screenshot bytes when you omit path; Puppeteer supports binary or base64 output according to its screenshot options.

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

Frequently Asked Questions

Does a clip automatically include content below the fold?

No. A clip defines a region in the page/view context. Use an element method or a full-page option when you need content beyond the current viewport.

Which format should I choose for text-heavy captures?

PNG is a lossless default in Puppeteer and is usually appropriate for sharp interface text; choose JPEG or WebP when smaller files matter and your pipeline accepts the format.

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.

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.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.