Originally published on berkant.me.
gpucanvas is an open-source TypeScript library that puts thousands of live DOM nodes on an infinite canvas. The GPU draws them. An editor selects, moves and resizes them. WGSL shaders and transitions run on them. An AI agent can read them and point at them.
The nodes stay real DOM. React state, events, CSS and accessibility work as usual. Click a screen and type into it: the click and the keystrokes go to the real element.
The same session on both sides: 5,000 live React screens, the same camera path, a message typed and sent. Left, plain DOM under a CSS transform. Right, gpucanvas. Chrome on a MacBook Pro, frame rates measured live. Watch the video on berkant.me.
In the 30-second benchmark tour at 5,000 screens, gpucanvas runs at 113 to 115 fps and plain DOM at 18 to 20 fps. In a longer tour at 10,000 screens, it is 108 fps against 9.
npm install gpucanvas
import { GpuCanvas, CanvasNode } from "gpucanvas/react";
<GpuCanvas style={{ width: "100vw", height: "100vh" }}>
{cards.map((card) => (
<CanvasNode key={card.id} x={card.x} y={card.y} width={240} height={150}>
<Card {...card} />
</CanvasNode>
))}
</GpuCanvas>;
Why a DOM Infinite Canvas Slows Down
There are two usual ways to put real HTML on an infinite canvas, and each gives something up.
Plain DOM: camera moves → CSS transform on one container → the browser repaints every visible element.
Draw it yourself: camera moves → redraw everything in a canvas → fast, but no inputs, focus, CSS or React.
The first is fine for a hundred cards. With a few thousand full app screens, each a tree of real elements, the frame budget is gone. That is the left side of the video above. The second is fast, but you end up rebuilding a browser inside the browser.
gpucanvas takes both: the elements stay in the DOM, and the GPU draws their pixels.
HTML-in-Canvas
Chrome 157 implements HTML-in-Canvas, a WICG proposal that lets a <canvas> hold live DOM children and draw them. Two pieces matter here:
-
<canvas content="drawable">keeps its children as real, laid-out, interactive elements. -
GPUQueue.drawElementImageToTexture()rasterizes one of those elements straight into a WebGPU texture.
The DOM stays the source of truth, and WebGPU gets a texture of each element to draw however it wants.
It is on by default in Chrome 157 and later on a computer. On older Chrome, turn on chrome://flags/#canvas-draw-element and relaunch. Without it, gpucanvas falls back to a CSS-transformed container with the same API, and the demo runs 1,000 screens and says so.
Drawing 5,000 Screens in One Call
Calling drawElementImageToTexture once per element per frame would be far too slow. Each call allocates and fully rasterizes, and Chrome manages about 250 to 550 of them per second in total. Most of gpucanvas is about calling it as rarely as possible.
The pipeline: live DOM nodes → pages of 2048 px (one call per page) → texture-array atlas → cull to the view → one instanced draw call. A MutationObserver sends changed nodes back through a page; rasterized pages are parked with content-visibility: hidden.
- Pages. Nodes are packed side by side into pages of 2048 CSS pixels inside the canvas. Chrome records a page as one snapshot, so one call rasterizes dozens of nodes at once.
-
Rasterize, then park. A page with nodes waiting for pixels becomes
drawable. In the next paint event it is drawn into the atlas, whole, or one node at a time when only a few changed. Then it is parked withcontent-visibility: hidden, which keeps layout but skips paint. The browser spends nothing on it per frame. - Thumbnails first. Every node gets a 1/16 scale thumbnail in an atlas layer that is never evicted, so a zoomed-out view of thousands of screens is always filled in. Sharper snapshots go on top at power-of-two scales, so zooming reuses them.
- Tiles up close. Past 100% zoom on a 2x display, only the visible part of a node is rasterized, as sharp tiles, center first.
- One draw call. Each frame culls nodes against the view and draws every visible one with one instanced quad draw. Panning and zooming never touch the DOM. Raster work has a per-frame budget, so the camera stays smooth while pixels fill in.
-
Live updates. A
MutationObservermarks a node dirty when its content changes. Loading images, web fonts and CSS transitions trigger a redraw too.
Clicks Still Reach the Real Element
The pixels on screen come from the GPU, but input has to land on the DOM.
Input: pointer or tap → only the page under it is registered for hit testing → Chrome hit tests it where the GPU drew it → the real element gets the click, the typing, the hover.
Touch has no hover, so a tap makes the node under the finger live and hands the click to the element it landed on. A two-finger pinch zooms and pans the camera. A focused node keeps its page live.
What Chrome 157 Does Differently from the Explainer
Building this meant finding where Chrome's implementation differs from the WICG explainer. If you are building on HTML-in-Canvas, these will save you time:
-
Hit testing needs registration. A drawable is hit-tested only after
canvas.updateElementGeometry(el, options)registers it. -
Hit testing follows
canvasTransform. Chrome 157 hit tests atoptions.canvasTransform, a matrix in CSS pixels from the element's border box to the canvas. Chrome 156 ignored it and hit tested at the CSS box, positioned withel.style.transform = canvas.getElementTransform(el, drawMatrix). gpucanvas handles both. -
Newly drawable elements are not reported in
changedElements. Their snapshot is available from the next paint event. - Cropping still rasterizes everything. A source rectangle rasterizes the whole element at the requested scale before cropping. That is why a zoomed-in node moves to a page of its own.
-
Recording cost scales with drawables. It grows with the number of drawables on every
requestPaint. 10,000 always-drawable nodes run at 22 fps even when idle, which is why pages get parked.
An Editor, Shaders and an Agent View
Once every node is a texture on the GPU, a lot comes cheap.
Marks from an agent, a wipe and a dissolve, the glass lens and shockwaves, all on live components.
Editor. bindEditor turns the canvas into a design-tool editor. Click to select, double-click to go a layer deeper, down to any element or React component. Move and resize with snapping guides. The GPU draws the selection outlines, 2 CSS pixels wide at any zoom.
Shader effects. Run WGSL on live components: a glass lens, frost, shockwaves, glitch, VHS, or your own. An effect is a function over the node's pixels:
import { defineEffect } from "gpucanvas";
const scanlines = defineEffect({
name: "scanlines",
animated: true,
params: [3],
wgsl: /* wgsl */ `
fn effect(input: EffectInput) -> vec4f {
let color = source(input.uv);
let y = input.uv.y * input.size.y + input.time * 20.0;
return color * (0.85 + 0.15 * step(0.5, fract(y / input.params.x)));
}`,
});
canvas.setEffect(node, scanlines);
Effects draw from each node's snapshot in the same pass. With an effect on every one of the 5,000 screens, most cost nothing measurable. Glass, the heaviest, costs about 12%.
Snapshots. Every node is already on the GPU, so its pixels are one call away, with no headless browser: canvas.snapshot(node) returns ImageData, diffImages shows what changed between two versions, and recordFilmstrip keeps a history.
Agent view. An AI agent reads the canvas the way a person sees it.
Agent view: canvas → describe → a JSON tree with ids, roles, text and rects → the agent can capture an image of any element or region, and point with arrows, pins, notes and cursors.
A sign-in screen comes back as about 35 entries and 3.5 KB of JSON, read in 3 ms. The agent can capture any element or region as an image, and point at things with marks that follow the camera.
Transitions. Dissolve, wipe or fade one node out and another in on the GPU, while both stay live.
Benchmarks
Measured on an M-series Mac, Chrome 157, 1600 × 900 window, DPR 1. The tour is a 94-second session from the overview into clusters of app screens, close-ups up to 500% zoom, 20 clicks and typed messages, then back out.
| Screens | gpucanvas avg | gpucanvas p95 | DOM avg | DOM p95 |
|---|---|---|---|---|
| 5,000 | 117 fps | 9.2 ms | 23 fps | 50.2 ms |
| 10,000 | 108 fps | 16.7 ms | 9 fps | 133.8 ms |
DOM is the same screens in one CSS-transformed container, which is also gpucanvas's fallback. Press b in the demo to run the benchmark yourself.
Questions
Does gpucanvas work without WebGPU? Yes. Where WebGPU and HTML-in-Canvas are missing, it falls back to a CSS-transformed DOM container with the same API. Effects with a CSS look become CSS filters there.
Which browsers run the GPU path? Chrome 157 or later on a computer, where HTML-in-Canvas is on by default. Firefox, Safari, and iPhone and iPad browsers have no HTML-in-Canvas yet, so they run the DOM version. Since 0.5, snapshot works there too with a snapshotFallback.
Is it only for React? No. The core API takes plain DOM elements. gpucanvas/react adds <GpuCanvas>, <CanvasNode>, useEditor and a component picker.
Is it ready for production? It is early, version 0.5, and the API can still change. Two known gaps: Tab skips nodes on parked pages, so moving focus across pages needs a focus model, and compositing does not run in a worker yet.
What license? MIT.
Try It
- Demo: berkantay.github.io/gpucanvas. Thirty agent cursors build the first view, then the camera pulls out to all 5,000 screens. Switch the toolbar to Interact and every button works, like a clickable prototype. Try the glass or shockwave effect.
- Code: github.com/berkantay/gpucanvas. If it is useful to you, a star helps other people find it.
- Package: gpucanvas on npm.


Top comments (0)