Summarise wrapped content via Chrome's Summarizer API, with provider-neutral inline endpoint and external deep-link fallbacks.
Overview
Wrap a block of content (typically an <article>) and ai-summary prepends a Summarize trigger that produces a streamed summary inline. The component is light DOM and progressively enhances — the wrapped article reads normally without JavaScript.
The provider is resolved once, when the component sets up (after an availability check), in this order: local Chrome Summarizer API → inline endpoint → external deep-link → unavailable. See AI page-tools v1 for the full contract. Changing endpoint or fallback-url afterwards does not re-resolve the provider.
Local Chrome Summarizer
In Chrome 138+ on a supported desktop, the component summarises on-device using Summarizer.summarizeStreaming(). The pass-through attributes type, length, and format map 1:1 to Summarizer.create() options. With format="plain-text" the result is shown as plain text (whitespace preserved) instead of going through <markdown-viewer>.
The on-device model accepts a limited amount of input. Where the browser exposes inputQuota and measureInputUsage(), content over the quota is trimmed to fit and a notice says how much was summarised; otherwise content over about 16,000 characters gets a warning that it may exceed the limit.
123456
<ai-summary type="key-points" length="medium" format="markdown"> <article> <h2>Headline</h2> <p>Body content…</p> </article></ai-summary>
Inline endpoint fallback
Configure endpoint="…" to POST to a server you control when on-device AI isn't available. The component sends { prompt, content, mode: "summarize" } as JSON; the server streams back text/plain chunks (or returns one-shot application/json). Stream output appears inline in the same UI.
123456
<ai-summary endpoint="/api/ai/summarize"> <article> <h2>Headline</h2> <p>Body content…</p> </article></ai-summary>
The wire format is documented in AI page-tools v1.1, §C. Implementations on the server side are unconstrained — wrap any AI provider that can produce text from a prompt.
External deep-link fallback
Configure fallback-url="…" with a URL template to send users to an external tool when neither on-device AI nor an inline endpoint is configured. Provider-neutral by design.
12345
<ai-summary fallback-url="https://claude.ai/new?q={prompt}" fallback-label="Read with Claude"> <article>…</article></ai-summary>
12345
<ai-summary fallback-url="https://chatgpt.com/?q={prompt}" fallback-label="Read with ChatGPT"> <article>…</article></ai-summary>
12345
<ai-summary fallback-url="mailto:?subject={title}&body={prompt}" fallback-label="Email this"> <article>…</article></ai-summary>
Template tokens (URL-encoded on substitution): {prompt}, {url}, {title} and {content}, the wrapped text capped at 1,500 characters so the URL stays within what browsers and providers accept. The trigger's accessible name ends in “(opens in new tab)” in deep-link mode. Override the default prompt with fallback-prompt="…":
123456
<ai-summary fallback-url="https://claude.ai/new?q={prompt}" fallback-prompt="Give me a one-paragraph summary of {url}" fallback-label="Read with Claude"> <article>…</article></ai-summary>
State and events
The host element reflects lifecycle on data-state: checking → ready → streaming → complete, plus downloading, error, unavailable, and deep-link. Theme via CSS attribute selectors.
While a summary streams, a Stop button appears next to the trigger. Click it, press Escape inside the element, or call stop() to end it; what streamed so far is kept, marked “(stopped)”, and data-state returns to ready.
123456
<script type="module">const summary = document.querySelector('ai-summary');summary.addEventListener('ai-summary:state', e => console.log(e.detail.state, e.detail.provider));summary.addEventListener('ai-summary:result', e => console.log(e.detail.text.length, 'chars'));summary.addEventListener('ai-summary:error', e => console.error(e.detail.error));</script>
Composing with other VB components
ai-summary drops into <page-tools> as just another child — the toolbar's responsive collapse and FAB-into-popover behaviour come for free. Streamed output renders through <markdown-viewer> on completion so VB themes and code highlighting apply automatically. Model and endpoint output is treated as untrusted: the viewer is always created with sanitize, so scripts, on* handlers and javascript: links in a response are stripped before rendering. The output region carries aria-busy="true" while a summary streams.