Repository navigation
Conversation
brainkim
marked this pull request as draft
November 9, 2026 16:05
A sandbox without allow-same-origin gives a frame an opaque origin, as HTML's sandboxed origin browsing context flag does, and a frame inside a sandboxed one keeps the sandbox. A srcdoc or about:blank frame takes the origin of the document that made it. Windows of two origins hold each other through a cross-origin WindowProxy that lets through only HTML's CrossOriginProperties and throws a SecurityError for the rest, so a sandboxed frame's contentDocument is null and its parent cannot reach into it, or it into the parent. Each viewer gets one proxy per window, so contentWindow compares equal to itself. postMessage checks the target origin against these origins, gives the event the sender's serialized origin, and gives as its source the sender as the receiver holds it, so a frame's event.source === parent holds. A frame may set its parent's location across origins, which goes through the parent's navigate event, and a sandbox without allow-top-navigation stops it with a SecurityError. A srcdoc frame resolves URLs against its parent's base URL, as HTML's fallback base URL does. Where the runtime has no node:vm, as in isolated-vm, a frame got a bare object with no postMessage, location or parent. It gets a whole window built in the engine's realm, which is what DuckDuckGo's result click needs: a message to a hidden frame that sends the page to the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
The guides said nothing about iframes. A reader needs to know that a frame's src is not loaded, where a frame gets a realm of its own, what a sandbox does to its origin, what a window of another origin lets through, and how messages and a parent's navigation cross between frames. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
brainkim
force-pushed
the
feat/frame-origins
branch
from
November 10, 2026 00:33
01feea4 to
be4e87d
Compare
A frame's engine read the terminal's colors, cell and loader off the document its iframe is in. A frame drawn in another isolate has no such document, so createFrameEngine takes them as settings, and the iframe's factory fills them from its document. exportGrid and importGrid carry a painted grid to another heap with the text of the clusters it interns. importGrid takes the cells as hostile: it rebuilds each cell's text and width, and drops control characters, bad code points and image placeholders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
TermDOM never loaded an iframe's src, so an embedder that wanted pages in frames, with limits on what each could take, ran a TermDOM per page and showed it through a pty embed. Every frame then went out as escape codes and came back through an emulator, and the page could not treat the program as a frame. The isolatedFrames option takes a function that starts a document in an isolate. An iframe whose src is an http: or https: URL loads it under the page's policy, now including frame-src, and its fetch listeners, and starts it there. The page draws the cells the frame paints, checked as untrusted, and hands it keys, the mouse, pastes and focus as an embed's program takes them. The page holds its window as one of another origin, so the two reach each other through postMessage, and the frame's own loads come back through the page's listeners without forbidden headers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
The runtime a bare V8 isolate needs before TermDOM loads in it: timers, events, text encoding, Blob and FormData, fetch through the host, decompression, streams, crypto and console, each from a plain callback the host provides. The frame entry builds the document from its markup, paints it with createFrameEngine and posts the cells, and dispatches the input, messages and responses the host sends it. A blank window with the page's origin stands in for the frame's parent, so parent, top, postMessage's origin check and parent.location go through the engine's own cross-origin windows. What the frame posts to it, or navigates it to, goes to the host. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
createIsolatedVMFrames resolves to a FrameIsolator. Each frame gets an isolate with a memory limit, and every call into it a time limit. The backend drives the frame's timers, randomness and logs, and runs the scripts the frame reports in document order: classic scripts, modules through the page's import maps, and dynamic imports. Their sources, and everything else the frame fetches, are loaded by the page. Inside the isolate, the frame copies its window onto the global object for its scripts, and sets currentScript, readyState and the load events as the backend reports each script's start and end. The build bundles the runtime into dist/isolate-frame.js. A checkout bundles it from source on first use. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
The frame runtime and the isolated-vm backend speak the page's protocol: the frame learns its parent's origin, says whether it navigates itself or its parent, and says when its isolate stopped. "auto" loads the backend with the first frame, as an optional peer dependency, and a frame whose backend cannot load crashes and says why. A frame that sends its parent elsewhere is held to its sandbox through the parent's own navigation, and the page gives the frame the cell size in CSS pixels its layout divides by. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
The frame's stand-in exchange gets editing and the document its autofocus, as a TermDOM's own do, and the reduced motion the page has. A click arrives in the frame's cells from zero and goes to the engine from one, as a terminal reports it. A frame stopped for time, memory or a failed start posts crash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
TermDOM leaves <link rel=stylesheet> to whoever loads the document. The frame fetches each one through the page, puts its rules after the link with URLs made absolute, and holds its first paint up to five seconds for them. Links added later load as they come. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
A form posted from a frame navigates with its method, its fields in the encoding its enctype names, and their content type. pushState, replaceState and a fragment change send history with the new URL, and no longer pass for navigations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
FrameInit.limits overrides the backend's memory and time limits for one frame. stats() gives the frame's CPU time, its longest task and its heap, or null once it is gone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
Where the page sends kitty images, the frame holds its images in a table of its own and paints the placeholder cells that name them, as a page does. After each paint it posts the images placed since the last one, with their pixels, and the ids it no longer shows, and the page places them under its own ids. Frames in the page's own heap still paint images in cells, since their framebuffers have no table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
A frame in an isolate posts its images' pixels and paints placeholder cells that name them by its own ids. The page keeps each image it posts once its size checks out, and importGrid hands each placeholder to the frame, which turns them into the grid images a pty embed's program shows. So the page sends them in the kitty protocol where the terminal draws it, and in half blocks elsewhere, and a placeholder for an image the frame never posted draws nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
The engine names a request's destination as a property of its own, and the frame's fetch copied the request from its internal state instead, so an image went to the page with no destination. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
The page draws a frame's images in kitty or in cells as its terminal can, so the frame paints placeholders whenever the page asks for kitty, and not only in 24-bit color. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv648YAe52aBTWbgPfn
A page that shows web pages can keep an address bar and a tab title for its frame, and can keep the frame from going somewhere. A form the frame posts loads its next document with that POST. An embedder that wants other limits, or the frames' logs, takes createIsolatedVMFrames from @b9g/termdom/isolated-vm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
A page that bundles TermDOM for a platform other than Node failed on the isolate backend's imports of node:crypto and node:fs/promises, and would go on to isolated-vm and esbuild. They come through the process now, as node-pty does, and randomness comes from the web's crypto. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
An iframe whose src is of another origin loads in an isolate where isolated-vm is installed and loads, and shows about:blank elsewhere. Its page reaches it as the web has it: load, postMessage, sandbox and frame-src. The isolatedFrames option, the exported message types, the @b9g/termdom/isolated-vm entry and the iframe's titlechange, navigate and historychange events go. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5bxvWWH7aApVCbS3z
Nothing sets FrameInit.limits or calls stats() now that the page starts the isolated-vm backend itself, with no option an embedder reaches. Each frame is held to the backend's limits, as the guide says. Co-Authored-By: Claude <noreply@anthropic.com>
isolated-vm 7 asks for Node 24. On CI's Node 20.19 leg its install script tried to build a binary and failed the install, so no test ran. That leg now installs without scripts, the tests that need an isolate skip under Node 24, and the guide gives the version. The lockfile takes the optional peer it was missing. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
A URL's pathname on Windows is /D:/..., which no file has. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
brainkim
marked this pull request as ready for review
November 12, 2026 18:17
A checkout bundles the runtime with esbuild, which was handed a URL's pathname. On Windows that is /D:/..., which esbuild could not resolve, so no frame loaded in an isolate there. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
Under Bun on Windows the message had not arrived by then. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
The test held every call into a frame to 200 milliseconds so that the frame that loops forever was stopped quickly. The limit is on the clock and covers a frame's start as well, its first parse, layout and paint in a cold isolate, and on a busy machine the calm frame took longer than that and was stopped too, so the test never saw it draw. With every core busy the old limit failed 11 runs of 15, and limits of 500 milliseconds and up failed none. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GVbRv5n8btiCtaRBtLrLig
# Conflicts: # src/internal/frames.ts
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Frames get origins, cross-origin windows and
postMessage, and an<iframe src>of another origin loads in a V8 isolate of its own where isolated-vm is installed. The branch adds no options, exports, package entries or event types: a page reaches a frame as the web has it, throughload,postMessage,sandboxandframe-src.DuckDuckGo's result click is what started this: it posts to a hidden frame, which checks
event.source === parentand setsparent.location.href.Origins and isolation
<iframe sandbox>withoutallow-same-origingets an opaque origin of its own, so itsoriginis"null". A frame inside a sandboxed frame stays sandboxed.srcdocandabout:blankframes take their creator's origin. Before, everysrcdocframe reported"null".contentDocumentisnull, andcontentWindow,frames[i], named frame access, and a frame'sparentandtopgive a cross-origin window. It allows only HTML's cross-origin properties and child frames by index. Itslocationallows only settinghrefandreplace(). Anything else throwsSecurityError. In a cross-origin frame,frameElementisnull.Messages and navigation
postMessageworks both ways, with HTML's target-origin check, and is delivered as a task.originis the sender's, andsourceis the sender as the receiver sees it.node:vm(isolated-vm, for one), frames get a real window in the engine's realm. They're also drawn, which they weren't before.parent.locationgoes through the parent's navigate algorithm, so itsnavigateevent fires. A sandboxed frame can navigate its top only withallow-top-navigation, orallow-top-navigation-by-user-activationduring a user action.Frames in isolates
<iframe src>with anhttp:orhttps:URL of another origin than the page's loads its document in an isolate, where theisolated-vmpackage is installed and loads. That means Node 24 or later only, started with--no-node-snapshot. Elsewhere the frame shows an emptyabout:blank, as everysrcframe did before. There is no option: installingisolated-vmturns it on.csp(now includingframe-src, with thechild-srcfallback) and through itsfetchlisteners, without the headers Fetch forbids.contentDocumentisnull, and the two talk throughpostMessage. A link or form in the frame loads the next document in a new isolate.Behavior changes for embedders
allow-same-origincan't be read from its parent:contentDocumentisnull, andcontentWindow.getSelection()throws. Addingallow-same-originrestores both.srcdocandabout:blankframes resolve URLs against the parent's base URL, per HTML's fallback base URL.<iframe name=x>makeswindow.xthe frame's window, and the frame'swindow.namestarts as the attribute.isolated-vminstalled, a cross-origin<iframe src>that showed nothing now loads and runs.Packaging
isolated-vmis an optional peer dependency.buildalso bundles the frame runtime intodist/isolate-frame.js. A checkout bundles it from source on first use, with esbuild.Limit: without
node:vm, a message sent by callingpostMessagedirectly on a same-origin window is attributed to the top window, because TermDOM can't tell whose code is calling. Messages through a cross-origin window are attributed correctly.Tests and CI
tests/frame-origins.test.ts(one test runs the DuckDuckGo flow in a child process withnode:vmhidden),tests/isolated-frames.test.ts,tests/isolated-vm-frames.test.ts, and one test intests/iframe-realms.test.ts.isolated-vm7 asks for Node 24. On the Node 20.19 job its install script tried to build a binary and failed the install, so that job installs with--ignore-scriptsand the tests that need an isolate skip below Node 24. They run on the Node 26 job.The frames section in
docs/guides/06-images-and-canvas.mdis new.🤖 Generated with Claude Code