Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallSome links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use page.evaluate() to cross an open Shadow DOM boundary: select the custom-element host, read its shadowRoot, then query the desired node and return its textContent or markup. A normal document-level querySelector() does not search inside a shadow root, and a closed root is not accessible through the host’s shadowRoot property.
Why a normal selector misses shadow-root content
A web component can attach its own DOM tree to a host element. That tree is separate from the document’s ordinary child tree, so document.querySelector('.description') searches the document tree but does not cross into a component’s shadow root. The selector can therefore return null even when the matching element is visibly rendered.
With an open root, traverse explicitly: find the host, access host.shadowRoot, then call querySelector() on that root. Pyppeteer runs the JavaScript in the page through page.evaluate(), and the function’s return value is passed back to Python. This works for content that exists in the page’s DOM; it is not a way to read a closed root or content that has not yet been rendered.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Read text from an open shadow root
This complete example launches Chromium, opens a page, waits for the component host, and returns the target’s raw descendant text. Replace the example URL and selectors with the ones for your page.
#1 Best Overall
- 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
import asyncio
from pyppeteer import launch
async def main():
browser = await launch(headless=True)
try:
page = await browser.newPage()
await page.goto("https://example.test", {"waitUntil": "domcontentloaded"})
await page.waitForSelector("my-widget", {"timeout": 10000})
content = await page.evaluate("""() => {
const host = document.querySelector('my-widget');
const root = host && host.shadowRoot;
const node = root && root.querySelector('.description');
return node ? node.textContent : null;
}""")
print(content)
finally:
await browser.close()
asyncio.run(main())
The null checks make the result predictable: the script prints the text when the host, open root, and target exist, otherwise it prints None in Python. To distinguish those cases while debugging, return separate status fields, as in the troubleshooting section.
Use a host ElementHandle when it is convenient
Pyppeteer’s page.querySelector() returns an ElementHandle. You can pass that handle to a function evaluated in the page, which avoids repeating the host selector inside JavaScript:
host = await page.querySelector('my-widget')
if host is None:
raise RuntimeError('my-widget was not found')
text = await page.evaluate("""host => {
const node = host.shadowRoot?.querySelector('.description');
return node?.textContent ?? null;
}""", host)
print(text)
This is still a single-root lookup: the handle points to the host, and JavaScript continues the traversal in the page. If you need several fields from one component, return an object from the same evaluate() call rather than making a separate round trip for each field.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsRank #2
- 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 text or markup deliberately
The property you return changes what your result means. Choose the one that matches the downstream task rather than treating these values as interchangeable.
| Return value | What it gives you | When to use it |
|---|---|---|
node.textContent |
Concatenated text from the node’s descendants, including text that may not be visibly rendered. | Raw text extraction, indexing, or comparison. |
node.innerText |
Rendered-text behavior that can reflect layout and visibility. | When the visible, layout-sensitive text is what matters. |
node.innerHTML |
Markup for the target node’s descendants, not the target element itself. | When you need the target’s child markup. |
node.outerHTML |
Markup serialization of the target element and its descendants. | When you need the target element’s opening element and contents as markup. |
For example, to obtain descendant markup inside the target, use:
html = await page.evaluate("""() => {
const host = document.querySelector('my-widget');
const node = host?.shadowRoot?.querySelector('.description');
return node?.innerHTML ?? null;
}""")
If the target itself is the desired markup, change node.innerHTML to node.outerHTML. A shadow root also has an innerHTML property for serializing the root’s descendants, but querying the target first is usually more precise.
Rank #3
- 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.
Extracted HTML is data, not automatically safe content. Reading innerHTML does not execute the returned string, but inserting untrusted strings into a page with an HTML-parsing sink can create an injection risk. Prefer text when markup is unnecessary, and sanitize HTML before reinserting it.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Traverse nested shadow roots
Each nested component introduces another boundary. Query the outer host, find the inner host inside its open root, then enter the inner host’s root. Guard every step so missing hosts, closed roots, and missing targets do not trigger property-access errors.
text = await page.evaluate("""() => {
const outer = document.querySelector('outer-widget');
const innerHost = outer?.shadowRoot?.querySelector('inner-widget');
const target = innerHost?.shadowRoot?.querySelector('[data-value]');
return target?.textContent ?? null;
}""")
print(text)
A null result here does not identify which boundary failed. For diagnosis, report each stage:
Rank #4
- 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
result = await page.evaluate("""() => {
const outer = document.querySelector('outer-widget');
if (!outer) return { stage: 'outer host missing' };
if (!outer.shadowRoot) return { stage: 'outer root unavailable' };
const inner = outer.shadowRoot.querySelector('inner-widget');
if (!inner) return { stage: 'inner host missing' };
if (!inner.shadowRoot) return { stage: 'inner root unavailable' };
const target = inner.shadowRoot.querySelector('[data-value]');
if (!target) return { stage: 'target missing' };
return { stage: 'found', text: target.textContent };
}""")
print(result)
Wait for components that render asynchronously
Waiting for the host element alone is not enough if the page attaches its shadow root later or populates the target after an API response. In that case, wait for the actual condition you need, with a timeout, before reading it. The predicate is specific to your component’s selectors:
await page.waitForSelector('my-widget', {"timeout": 10000})
await page.waitForFunction("""() => {
const host = document.querySelector('my-widget');
return !!host?.shadowRoot?.querySelector('.description');
}""", {"timeout": 10000})
text = await page.evaluate("""() => {
const host = document.querySelector('my-widget');
return host?.shadowRoot?.querySelector('.description')?.textContent ?? null;
}""")
Use a wait predicate that represents readiness, not merely visibility of the host. If the component’s content updates repeatedly, define what “ready” means for your use case—for example, the presence of a particular attribute or non-empty text. Avoid an unbounded wait: a finite timeout lets the script fail clearly when the component never reaches that state.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Selector shortcuts and compatibility
Puppeteer documents deep selectors such as >>> and pierce/ for searching descendants in open shadow roots. Availability and support can differ between Puppeteer and Pyppeteer versions, so do not assume that a shortcut shown in Puppeteer documentation is exposed by the Pyppeteer version installed in your project. If a deep selector is rejected or returns no match, use the explicit evaluate() traversal above; it makes each boundary visible and is easier to debug.
Best Value
- 【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.
Explicit traversal also makes the limitations clear: each root must be open, and nested roots require an additional host-to-root step. For a single simple lookup, a supported deep selector may be concise; for nested components, asynchronous rendering, or diagnostics, explicit JavaScript is generally easier to control.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What closed shadow roots allow
When a component attaches its root with mode: 'closed', the host’s shadowRoot property returns null. Ordinary page JavaScript—and therefore an external Pyppeteer evaluation—cannot recover the internal root reference later through that property. This differs from an open root, for which the host exposes the root through shadowRoot.
A component’s own code may still hold the reference returned by attachShadow(); that does not make the reference available to your automation script. If you control the component or can use its documented interface, prefer a public method, attribute, or event that exposes the needed value. Otherwise, you may be able to observe the rendered page visually, but a screenshot is not a substitute for retrieving the hidden DOM text.
Common errors and fixes
querySelector()returnsnullalthough the element is visible: The selector is being run againstdocument, outside the component boundary. Select the host first and query its openshadowRoot.Cannot read properties of null: A host, root, or target is missing. Guard every lookup with checks or optional chaining; then wait for the specific element if rendering may still be in progress.- The host exists but
host.shadowRootisnull: The root may be closed, or it may not have been attached yet. Wait for attachment when timing is the issue; if the root is closed, use a component-provided public interface. - The script times out while waiting: Check the host and target selectors in the actual page, confirm navigation reached the expected page state, and make the predicate match the component’s real readiness condition. A timeout does not prove that the root is closed.
- The returned string is empty or differs from what you see:
textContentincludes raw descendant text and may include hidden text;innerTextis rendered-text oriented. Check whether the target selector is correct and whether the component has finished updating. - A deep selector works in Puppeteer examples but fails in Pyppeteer: The selector syntax may not be available in your installed Pyppeteer release. Switch to explicit root traversal rather than assuming API parity.
- Markup appears as text, or reinserting it causes a security concern: Use
textContentfor text output. Treat serialized HTML as untrusted and sanitize before inserting it into an HTML-parsing context.
Reliability and efficiency notes
Use one page.evaluate() call to collect multiple related values from the same component. This reduces browser-to-Python round trips and keeps related reads together. Keep selectors scoped to the host’s root instead of searching the entire page repeatedly. For nested components, make each boundary explicit and return a diagnostic object during development; once selectors are stable, return only the data your application needs.
Reliability mostly depends on page state and the component’s public accessibility. Navigation completion does not guarantee that a client-rendered component is populated, so wait for a meaningful target condition. Use bounded waits and close the browser in a finally block, as in the runnable example, so a selector failure does not leave Chromium running. No benchmark or success-rate figure is established here; actual runtime depends on navigation, the site, and when its component renders.
Or skip the browser setup
If your goal is to save a visual screenshot rather than extract text from a shadow root, ScreenshotNeo offers a one-request screenshot API; it does not return DOM text or markup. It accepts consent banners as a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before capture, with each step switchable off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. It also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.
For example, save a screenshot of a page as WebP:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.test -o shot.webp
See the ScreenshotNeo API documentation for the request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. ScreenshotNeo also supports element screenshots, PDFs, full-page captures, and an MCP server. Sign up for 1,000 free screenshots a month with no card.
Quick Recap
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.

