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

In Puppeteer, wait for the element, then call element.screenshot(). Puppeteer scrolls the element into view and captures its rendered bounds, so you do not need to take a full-page screenshot and crop it afterward. For a rectangle you calculate yourself, use page.screenshot({ clip }) instead.

Capture one element with Puppeteer

This complete Node.js example opens a page in headless Chrome, waits for a visible target, and saves just that element as a PNG:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com', { waitUntil: 'networkidle2' });

    const element = await page.waitForSelector('#target', { visible: true });
    if (!element) throw new Error('Target element was not found');

    await element.screenshot({ path: 'element.png' });
  } finally {
    await browser.close();
  }
})();

Replace https://example.com with the page to capture and #target with a selector for the desired element, such as .product-card or [data-testid="chart"]. The output file is written to the current working directory. The Puppeteer ElementHandle reference documents that the method scrolls the element into view if needed and then uses the page screenshot machinery.

Install and run

In a new project, install Puppeteer and save the example as a JavaScript file:

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.
npm install puppeteer
node capture-element.js

Puppeteer normally downloads a compatible Chrome for Testing browser during installation. If your environment uses a separately installed browser, configure the launch options for that installation; the browser executable and Puppeteer version must be compatible.

Wait for the page state you actually need

networkidle2 is a navigation wait condition, not a guarantee that every visual asset or application update is complete. A page may still load fonts, lazy images, or asynchronously render the target after navigation. Prefer an application-specific readiness condition when available. Puppeteer’s guide demonstrates waiting for fonts and image decoding before capture: Puppeteer screenshot guide.

await page.goto('https://example.com', { waitUntil: 'networkidle2' });
await page.waitForSelector('#target', { visible: true });
await page.evaluate(async () => {
  await document.fonts.ready;
  await Promise.all(
    Array.from(document.images, image => {
      if (image.complete) return Promise.resolve();
      return new Promise(resolve => {
        image.addEventListener('load', resolve, { once: true });
        image.addEventListener('error', resolve, { once: true });
      });
    })
  );
});

Use the asset wait only when those assets matter to the target. An image that has loaded can still be visually wrong for your use case, and a page’s own code may replace the target afterward. When the app exposes a stable ready flag or selector, wait for that rather than relying on a fixed sleep.

Choose element capture, a clip, or a full-page shot

Method Use it when Behavior and trade-off
ElementHandle.screenshot() You have a selector for one rendered element. Conveniently derives the element’s bounds and scrolls it into view as needed. If the node is detached, the call fails; reacquire it.
page.screenshot({ clip }) You need a specific rectangle, or want to calculate and reuse its coordinates. Captures the supplied rectangle. You must obtain sensible coordinates and dimensions yourself.
Chrome DevTools Protocol Page.captureScreenshot Your program already communicates with Chrome over CDP and needs protocol-level controls or base64 data. Accepts a clip rectangle and returns image data encoded as base64; requires working with the protocol directly.
page.screenshot({ fullPage: true }) You want the document rather than one element. Captures the full page, so it is not the focused method for a single-element screenshot.

The Puppeteer screenshot options are documented at ScreenshotOptions; the protocol method is documented at Chrome DevTools Protocol Page.captureScreenshot.

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

Capture an explicit rectangle with a clip

A clip is useful when you need to crop a known region, or when your coordinates come from another calculation. This example measures the element’s bounding rectangle in the page and passes it to Puppeteer:

const box = await page.$eval('#target', el => {
  const r = el.getBoundingClientRect();
  return { x: r.x, y: r.y, width: r.width, height: r.height };
});

await page.screenshot({
  path: 'element-clip.png',
  clip: box
});

getBoundingClientRect() returns coordinates relative to the viewport. Keep the measurement and screenshot in the same page state: scrolling, layout changes, or a responsive breakpoint change between those operations can make the rectangle point somewhere else. Ensure width and height are greater than zero. Do not combine a manual clip with fullPage: true for an element crop; they describe different capture scopes.

Puppeteer documents captureBeyondViewport as defaulting to false when there is no clip and true when a clip is provided. If a custom rectangle extends beyond the viewport, consider that option deliberately rather than assuming every requested area will be captured identically across configurations.

Set output format, dimensions, and appearance

Format and image size

Puppeteer supports PNG, JPEG, and WebP screenshot types. PNG is the default and preserves sharp edges well; JPEG and WebP can produce smaller lossy files. The quality option applies to lossy formats where supported.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
await element.screenshot({
  path: 'element.webp',
  type: 'webp',
  quality: 80
});

Other useful screenshot options include encoding, omitBackground, fullPage, clip, captureBeyondViewport, and fromSurface. Check the API reference for the installed Puppeteer version when depending on a specific option or default.

Viewport and device scale

Screenshot dimensions depend on the element’s CSS layout and the browser’s device scale factor. Set these explicitly when predictable output dimensions matter:

await page.setViewport({
  width: 1280,
  height: 800,
  deviceScaleFactor: 1
});

Set the viewport before navigating or measuring the target, since viewport width can change responsive layout and therefore element bounds. A higher device scale factor produces more output pixels per CSS pixel; it also increases image dimensions and potentially file size. Browser, operating system, fonts, and rendering differences can affect the final pixels, so identical page code does not guarantee byte-identical screenshots across environments.

Make captures reliable

  • Wait for the selector. Use waitForSelector and check the returned handle before capturing.
  • Check visibility and geometry. A selector can match a hidden node or an element with zero width or height. Wait for the page’s intended visible state and inspect its bounds if needed.
  • Wait for visual assets. Navigation completing does not ensure fonts and images are ready. Wait for the assets that affect the target.
  • Capture after the final update. Animations, lazy loading, and client-side replacements can alter the image. Prefer a meaningful readiness signal over an arbitrary delay.
  • Set viewport and scale. Do so before measuring when output dimensions or responsive appearance matter.
  • Reacquire replaced nodes. If a framework rerenders the element, an earlier handle may be detached; query the selector again after the update.

Troubleshoot common failures

“Waiting for selector” times out

The selector may be wrong, the page may not have reached the relevant state, or the target may be inside an iframe. Verify the selector in the page, wait for the correct application state, and use the frame’s page context when the element belongs to a frame.

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

The element handle is detached

The page removed or replaced the matched node after Puppeteer found it. Wait for the update to finish, then run waitForSelector again and take the screenshot using the fresh handle.

The screenshot is blank or the element is missing

Check whether the target is hidden, has zero-size geometry, is covered by another state, or has not finished rendering. Confirm the selector matches the intended element and capture only after the relevant content is ready.

Images or fonts are absent or inconsistent

Navigation readiness does not necessarily include visual asset readiness. Wait for document.fonts.ready and for relevant images to load or decode, then capture. Also account for lazy-loaded images: scrolling the target into view can trigger loading, so an application-specific readiness check after scrolling may be necessary.

Clip captures the wrong area or is cut off

Recalculate the rectangle immediately before capture and confirm it uses the coordinate system expected by the screenshot call. Layout shifts and scrolling can invalidate old measurements. For an element selected from the DOM, ElementHandle.screenshot() avoids manually managing the rectangle in the usual case.

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

Output pixel dimensions differ from CSS dimensions

Check the viewport and deviceScaleFactor. CSS pixels are not necessarily output image pixels; explicitly set the scale when your downstream system expects fixed dimensions.

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 can capture a URL through one GET request; its capture options include selecting an element by CSS selector. Cookie banners, newsletter popups, and chat widgets from its supported set of more than 60 consent platforms and widget types are removed before capture, and each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. An MCP server provides screenshot 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. See the ScreenshotNeo API docs for parameters and options.

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

For the single-element capture, use the element-selection parameter documented by ScreenshotNeo rather than treating this basic URL request as an element-only capture. The service also accepts parameter names used by other screenshot APIs, which can ease migration. Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Can I screenshot an element that is below the fold?

Yes. Puppeteer’s ElementHandle screenshot method scrolls the element into view if needed before capturing it.

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

Does an element screenshot include the page background?

It captures the element’s rendered area; use screenshot options such as omitBackground when you specifically need to control background handling.

Can I get the screenshot as base64 instead of writing a file?

Puppeteer screenshot options support an encoding setting, and the lower-level Chrome DevTools Protocol capture method returns base64 image data.

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.