0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…
Gives an iframe an inline HTML document instead of a URL. Without sandbox the document runs with your page's origin, so untrusted HTML always needs sandbox.
Overview
The srcdocattribute gives an <iframe> its document as a string of HTML, with no separate URL. The frame loads it as about:srcdoc. If both srcdoc and src are present, srcdoc wins.
The most important fact about srcdoc: on its own it isolates nothing. An unsandboxed srcdoc document inherits your page's origin (and its Content Security Policy). Its scripts can read your cookies and storage and reach into your page through parent. Isolation comes only from adding sandbox without allow-same-origin.
The page saves a value in localStorage. The unsandboxed frame reports the page's own origin and reads the value; the sandboxed frame has origin null and cannot.
Values
Value
Result
An HTML string
Parsed as a complete document in the frame. A missing doctype is fine: srcdoc documents never enter quirks mode.
"" (empty)
An empty document. src is still ignored while the attribute is present.
Inside a double-quoted attribute you must escape " as " and & as &. Literal < and > are allowed in attribute values, so escaping them is optional. Single quotes inside the HTML avoid most of the escaping.
Static srcdoc
12345
<iframesandboxtitle="Order confirmation preview"class="bordered"srcdoc="<style>body { font-family: system-ui; }</style><h1>Thanks, Amara</h1><p>Order <strong>#4821</strong> ships Friday. Questions? Reply to this email & we'll help.</p><p><a href='https://shop.example.com/orders/4821'>Track your order</a></p>"></iframe>
Rendering an HTML email
An empty sandbox stops scripts, forms and popups in the message. It does not stop remote images, which are how emails track opens. To block them, put a CSP <meta> at the start of the string you build, or rewrite image URLs on the server.
VB treats srcdoc as a script sink. The sanitiser (src/lib/sanitize-html.js) drops srcdoc in every profile, and <card-list> refuses to write it from data through data-field-attr (src/web-components/card-list/logic.js, alongside style and is).
data-mock fills an empty iframe[data-mock] (no src, no srcdoc) with a placeholder srcdoc showing the frame's title (src/utils/mock-init.js).
Style the frame with iframe.bordered, iframe.rounded or data-ratio from src/native-elements/iframe/styles.css. VB's CSS does not reach inside the srcdoc document; link a stylesheet from the string if you need it.
Accessibility
Give the iframe a title that names its content.
The srcdoc document has its own accessibility tree: include a langattribute, headings and real structure in the string, as you would for any page.
Set a fixed height or use data-ratio; a frame that clips its content hides it from sighted keyboard users.
Security
Unsandboxed srcdoc is your origin. Treat its HTML exactly as if you inserted it into your page with innerHTML.
For untrusted HTML, use sandbox with no tokens, or with allow-scripts only. Never add allow-same-origin as well: the frame would get your origin back and could remove its own sandbox.
Escape when you build the attribute in a template. An unescaped " in user HTML ends the attribute and injects markup into your page. Setting the srcdoc property from script avoids this.
Sanitise as well as sandbox when the content can link out: a sandboxed frame can still show phishing links and load tracking images.
The srcdoc document inherits your page's CSP. A policy that blocks inline scripts or styles blocks them inside the frame too.
Gotchas
Relative URLs resolve against your page. The srcdoc document's base URL is the parent's, so href="next.html" points next to your page, not anywhere special.
No URL of its own. The content cannot be bookmarked, opened in a new tab or linked to from outside.
Size. Long strings bloat the page HTML and are parsed even if the frame is never seen; loading="lazy" defers rendering, not the bytes.
Related
sandbox — required for isolation; explains the allow-scripts allow-same-origin escape.