Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober 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 PC×
Skip to content
World desk4 min

How to Screenshot an Element Outside the Viewport with Playwright

Playwright’s locator screenshot scrolls an offscreen target into view before capturing it. Learn the runnable pattern, how it differs from a full-page screenshot, and how to handle nested scrollers and detached elements.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a locator’s screenshot() method. Playwright scrolls the matched element into view before capturing it, so you usually do not need to call scrollIntoViewIfNeeded() first:

const heading = page.getByRole('heading', { name: 'Results' });
await heading.screenshot({ path: 'results-heading.png' });

This captures the matched element, not the whole page. The locator API is the recommended approach; Playwright’s ElementHandle.screenshot() API is marked discouraged in favor of locator screenshots.

As an Amazon Associate I earn from qualifying purchases.

Capture an offscreen element with a locator

After navigating to the page, create a locator for the target and call screenshot() on it. The locator screenshot waits for actionability checks, scrolls the element into view, and captures the page clipped to the element’s size and position. Pass path to save the image; the method also returns the screenshot buffer.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const resultHeading = page.getByRole('heading', { name: 'Results' });
const image = await resultHeading.screenshot({ path: 'results-heading.png' });

Choose a locator that expresses the target clearly. Playwright’s built-in locator options include getByRole() for accessible roles and names, getByText() for text, getByLabel() for labeled controls, and getByTestId() for an explicit test identifier. Prefer these user-facing attributes or project testing contracts where they fit. CSS and XPath are supported, but selectors tied to long or fragile DOM structure can break when the page changes.

#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

Runnable example

This example uses Playwright’s library from Node.js. Install it in your project with npm install playwright; install the browser binaries with npx playwright install chromium. Save the following as capture-element.js and run it with node capture-element.js.

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

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

  try {
    await page.goto('https://example.com', { waitUntil: 'load' });

    const target = page.getByRole('heading', { name: 'Example Domain' });
    await target.screenshot({ path: 'element.png' });
  } finally {
    await browser.close();
  }
})();

Replace the example URL and locator with the page and target you need. The locator screenshot call performs the scroll-into-view behavior. If your target is inside a nested scrollable container and you need a particular interior portion, first scroll that container to the desired content; capturing a scrollable element does not stitch together its entire interior.

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 the screenshot scope that matches the result you need

Goal Use What the image contains
Isolate one element, including one initially outside the viewport locator.screenshot() The page clipped to the matched element’s size and position; the locator is scrolled into view before capture.
Capture the document’s full scrollable extent page.screenshot({ fullPage: true }) A full-page image, as if the page fit on a very tall screen.
Capture a scrollable element’s interior Screenshot the element after scrolling its container Only the container’s currently scrolled content, not all of its inner content stitched together.

These scopes are not interchangeable: use a locator screenshot for a single target and fullPage: true for the whole document.

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.

Common problems and fixes

The screenshot shows a covering element

Scrolling the target into view does not uncover it. If another element covers the target, the screenshot reflects that visible rendering. Change the page state or remove the covering content before capturing if your use case permits.

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.

The target is detached

The screenshot call throws if its element is detached from the DOM. Keep a locator rather than retaining an old element handle when the page may re-render; a locator resolves the current matching element when used.

The screenshot misses content inside a nested scroller

A screenshot of a scrollable element shows only the content at its current scroll position. Scroll the inner container to the section you want before capturing it. Automatic scroll-into-view for the matched element does not mean Playwright captures or stitches the entire interior of that container.

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

The image contains the entire page or the wrong region

Check which API you called. page.screenshot({ fullPage: true }) captures the full scrollable document; locator.screenshot() captures the selected element. Use the latter when the output should isolate one 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.

The locator stops matching after a page change

Prefer a role and accessible name, visible text, label, or test ID when it accurately identifies the target. CSS and XPath can work, but a selector coupled to incidental DOM structure is more likely to become brittle as the page changes.

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

Or skip the browser setup

If you need a screenshot from a service rather than running Playwright in your own browser, ScreenshotNeo is a website screenshot API and MCP server. It takes a URL and returns an image or PDF; it is a page-capture service, not a replacement for a Playwright locator when you need to target one particular DOM element.

For example, this cURL request captures a page:

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 request options. ScreenshotNeo removes supported cookie banners, newsletter popups, and chat widgets before capture; those cleaning steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers say the page verdict and whether the request was billed. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for 1,000 free screenshots a month with no card.

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.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
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.