Agent Ready HTML

Shadow DOM text reaches a fetch only if it is in the HTML

In short

Text a component builds with attachShadow() is not in the page markup, which carries only the host element. Put text an agent must read in light DOM children inside the host's tags, or in a template with shadowrootmode open or closed inside the host, which the HTML parser turns into a shadow root with no JavaScript.

Published 22 November 2026

In MDN's custom element example, the page carries only <filled-circle color="blue"></filled-circle>. The component builds everything inside it by calling attachShadow() in connectedCallback() (MDN's shadow DOM guide). web.dev describes the imperative attachShadow() API as working fine for client-side rendering, where the same modules that define the custom elements also create their shadow roots and set their content (web.dev on declarative shadow DOM).

Anthropic's web fetch tool retrieves the full text content from a URL but does not support websites dynamically rendered with JavaScript. For pages that need a real browser, Anthropic's documentation points to its browser use tool (Claude web fetch tool). Jina's Reader API lets the caller pick an engine with the X-Engine header: direct issues a plain HTTP fetch, and the default engine renders the page in a headless browser so client-side JavaScript executes before extraction. Its X-With-Shadow-Dom header is documented as "Extract content from Shadow DOM components", to be enabled for pages using web components (Jina Reader).

Related: How to see your site as a plain-fetch client

Light DOM children travel in the response

The DOM Standard calls the node tree of a shadow root's host the light tree, and a shadow tree contains zero or more slots (DOM Standard). A slot element represents its assigned nodes, if any, and its contents otherwise (WHATWG slot element).

Google's search documentation includes a web component that displays its light DOM content inside its shadow DOM (Google's JavaScript SEO basics). The two paragraphs inside <my-component> are written in the page markup, while the line "Hello World, this is shadow DOM content" is created in connectedCallback(), and a <slot> in that line projects the light DOM into the shadow tree. After rendering, Google can index both. A headless Chromium renders the page and executes the JavaScript, and when Google renders, the shadow DOM and light DOM content are flattened. Google can only see content that is visible in the rendered HTML, and content missing from it won't be indexed. To check, open the Rich Results Test or the URL Inspection Tool and look at the rendered output.

Declarative shadow DOM writes the shadow tree into the HTML

The template element's shadowrootmode attribute takes two keywords: open makes the template represent an open declarative shadow root, closed a closed one, and a missing or invalid value falls to the None state (WHATWG template element). Place the template inside the host element, as in web.dev's DSD example:

<host-element>
  <template shadowrootmode="open">
    <slot></slot>
  </template>
  <h2>Light content</h2>
</host-element>

The HTML parser creates a ShadowRoot for the parent element from the first template in it whose shadowrootmode has an allowed value (MDN). MDN describes shadowrootmode as a declarative version of the Element.attachShadow() method (MDN's template reference).

Related: Initial HTML

innerHTML does not create a declarative root

Fragment parsing APIs such as innerHTML and insertAdjacentHTML() cannot create declarative roots, and setHTMLUnsafe() and parseHTMLUnsafe() are the only ways to parse HTML with them applied (web.dev). A template element cannot be changed into a shadow root after parsing, for example by setting its shadowRootMode property (MDN).

Server-render Lit and Stencil components

Google says server-side or pre-rendering is still a great idea, because it makes a website faster for users and crawlers and not all bots can run JavaScript (Google's JavaScript SEO guide).

Lit SSR belongs to the Lit Labs family of experimental packages. It renders Lit components and templates to static HTML markup in non-browser JavaScript environments like Node. Lit defines server-side rendering as generating and serving the HTML of your components, including shadow DOM and styles, before their JavaScript has loaded and executed. Published integrations include the Lit Eleventy Plugin, the Astro integration for Lit and Rocket. For the Next.js pages router there is @lit-labs/nextjs, and for Nuxt 3 there is nuxt-ssr-lit. Under library status, the project lists notable limitations it hopes to resolve:

  • Async component work is not supported.
  • Only Lit components using shadow DOM are supported.
  • Declarative shadow DOM is not implemented in all major browsers yet, though a polyfill is available (Lit's client usage docs cover it).

Stencil prerenders components and routes at build time. With the --prerender CLI flag, the compiler generates a "hydrate" app, which prerendering uses internally (Stencil's static site generation). Each finished page is written to the configured www directory as an index.html file. Visitors of each prerendered page first receive the HTML with inline styles and no blocking JS or CSS, and as components hydrate they reuse the existing nodes in the DOM. Stencil lists among its benefits that it provides functionality for users with JavaScript disabled.

Related: Client-side rendering and agents

Serialize shadow roots when you save rendered HTML

Set the serializableShadowRoots option to true to include shadow roots marked serializable (the default is false), or pass ShadowRoot objects in the shadowRoots array, which are included whether or not they are serializable, open or closed. On a declarative root, the shadowrootserializable attribute sets serializable (WHATWG template attributes).

Check the sentence in the raw HTML

Fetch the page without running JavaScript and search the response for a sentence an agent needs to read. A template with shadowrootmode set to open or closed creates a shadow root for its parent element (MDN). Only the first such template in a node becomes a ShadowRoot: any other value, a missing attribute, or a second declarative root in the same parent produces an ordinary HTMLTemplateElement, and by default that element's content is not rendered (MDN template element).

Related: Plain Fetch viewer

Sources

  1. MDN: Using shadow DOM https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM, read 22 November 2026
  2. WHATWG: HTML Standard: Scripting (the template element) https://html.spec.whatwg.org/multipage/scripting.html, read 22 November 2026
  3. MDN: <template>: The Content Template element https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template, read 22 November 2026
  4. web.dev (Google): Declarative Shadow DOM https://web.dev/articles/declarative-shadow-dom, read 22 November 2026
  5. MDN: Element: getHTML() method https://developer.mozilla.org/en-US/docs/Web/API/Element/getHTML, read 22 November 2026
  6. WHATWG: DOM Standard https://dom.spec.whatwg.org/, read 22 November 2026
  7. Google Search Central: Understand JavaScript SEO basics https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics?hl=en, read 22 November 2026
  8. Anthropic: Web fetch tool https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool, read 22 November 2026
  9. Jina AI: Reader API https://jina.ai/reader/, read 22 November 2026
  10. Lit: Server-side rendering (SSR) https://lit.dev/docs/ssr/overview/, read 22 November 2026
  11. Stencil: Static Site Generation https://stenciljs.com/docs/static-site-generation, read 22 November 2026

Last reviewed 22 November 2026