Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › JavaScript

How to Take a Puppeteer Screenshot of an Element Inside Shadow DOM

By Freedom251 Team · · 4 min read

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

To screenshot one element inside an open shadow root, use Puppeteer’s >>> deep selector to find it, then call ElementHandle.screenshot(). To capture the whole rendered page, use page.screenshot() instead; that does not require selecting anything inside the shadow tree.

Capture one element inside an open shadow root

Install Puppeteer in your project if it is not already available, then run this complete example. Replace the URL, host selector, and target selector with those for your page and component.

As an Amazon Associate I earn from qualifying purchases.

const puppeteer = require('puppeteer');

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

    const target = await page.waitForSelector('my-widget >>> .target');
    if (!target) {
      throw new Error('Target element not found');
    }
    await target.screenshot({ path: 'target.png' });
  } finally {
    await browser.close();
  }
})();

my-widget >>> .target searches beneath the my-widget host, traversing open shadow roots as needed to find a matching descendant. Puppeteer’s documentation explains that ordinary CSS selectors do not descend into Shadow DOM and provides these additional combinators for that purpose: Page interactions. Check the selector against the actual component markup; .target must match the element you want to save.

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

Use the direct-child combinator when appropriate

Use >>>> when the target is in the host’s immediate shadow root:

#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
const target = await page.waitForSelector('my-widget >>>> .target');
if (!target) {
  throw new Error('Target element not found');
}
await target.screenshot({ path: 'target.png' });

Both deep combinators are documented for open shadow roots. Do not assume they can traverse a closed root.

Wait for the component to render

The example waits for a selector, but that only helps if the component eventually exposes a matching element. Choose a navigation wait condition that fits the site: networkidle0 is used above as an example, not a guarantee that every application has finished rendering. If the component appears later, wait for the target selector after navigation. Handle a missing result explicitly instead of calling screenshot() on a null handle.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB | 1920×1080 LED Monitor, 4ms GtG, Adaptive Sync, HDMI 1.4, Tilt Adjust, Low Blue Light, 4yr Advance Replacement Warranty
  • 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

Capture the whole rendered page instead

If you need the full page rather than a crop of one element, shadow-root traversal is unnecessary:

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

Page.screenshot() captures the page, while ElementHandle.screenshot() captures the selected element. The fullPage option requests a full-page image. See Puppeteer’s screenshot guide and Page.screenshot() API.

Rank #3
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.

Find an internal element through page-context DOM access

If the target is awkward to express with a deep selector, use evaluateHandle() to query an open root in page context, then screenshot the returned handle:

const target = await page.evaluateHandle(() => {
  const host = document.querySelector('my-widget');
  return host?.shadowRoot?.querySelector('.target') ?? null;
});

if (!target) {
  throw new Error('Target element not found');
}
await target.screenshot({ path: 'target.png' });

This example queries one host and one shadow root. If the target sits through several nested hosts, query each host’s shadowRoot in sequence. The code uses optional chaining so a missing host or closed root returns null rather than throwing during the query. Puppeteer documents page-context evaluation in its Page.evaluate() API; element capture is documented in the ElementHandle.screenshot() API.

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

Choose the capture method by the output you need

Need Method Need a shadow selector? Important detail
Whole rendered page page.screenshot() No Use options such as fullPage when appropriate.
One element in an open root elementHandle.screenshot() Yes, to obtain the handle Find it with >>> or >>>>.
One element with inconvenient selector syntax evaluateHandle(), then handle screenshot Use page-context DOM access Check that the returned handle is non-null and the root is open.

What to check when the screenshot fails or looks wrong

The target handle is missing

  • Verify the host selector and the internal element selector against the live page.
  • Wait until the component has rendered, then query again.
  • Confirm the target is inside an open shadow root; the documented deep selectors are for open roots.

The screenshot operation fails or captures the wrong region

Make sure you called screenshot() on the handle for the intended element, not on the page when you wanted a crop. Puppeteer’s element screenshot method scrolls the target into view if needed. That scroll can affect page state or sticky and fixed elements, so inspect the resulting image in the target environment. See the ElementHandle.screenshot() API.

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

The page renders incompletely

A navigation wait condition may finish before a client-rendered component exposes its target. Wait for the target selector after navigation, and use the full-page page screenshot only if the desired result is the rendered page rather than an individual element. The full-page capture avoids needing access to the shadow-internal node.

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

Version and API guidance

The Puppeteer documentation consulted for these APIs identifies version 25.12.0. If your project uses another version, confirm the method signatures and selector behavior against the documentation for your installed version before relying on this example.

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.

Or skip the browser setup

For a screenshot from one API request, ScreenshotNeo accepts a URL and returns an image or PDF. For example, this cURL request saves a WebP image:

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 documentation for request options. ScreenshotNeo accepts cookie or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; those cleanup steps can be turned off. 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. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

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

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

Frequently Asked Questions

Can Puppeteer screenshot content inside a closed shadow root?

The documented deep selectors apply to open shadow roots; the guidance here does not establish a way to traverse closed roots.

Which Puppeteer selector combinator should I use for an immediate shadow-root child?

Use >>>> for a target in the host’s immediate shadow root; use >>> to search at any depth through open roots below the host.

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.

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.

JavaScriptPuppeteerscreenshotsShadow DOMWeb development

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.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver 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.