Transport lab
Every route I could think of for getting DOM out of its canvas and into another context: another canvas, a worker, a cross-origin document. Each row is a test that runs in your browser. The small canvas shows what arrived at the far end, and a row passes only if the pixel read there matches the source element.
running…
Show the code what every route starts from
Every row below has its own Show the code link with the exact function that row ran. They all use these two helpers.
source(): a drawable canvas with one element in it.s.elis the element,s.cthe canvas,s.ctxits 2D context ands.snap()a freshElementImagefromcaptureElementImage().arrive(): draw whatever came out the other end and check one pixel.- The worker some routes send things to.
- The page on the other origin.
A · Moving the snapshot ElementImage and friends, DOM stays live
B · Getting around the one-canvas rule ways to keep it DOM
C · Moving pixels after drawElementImage
D · Streams and codecs continuous transport
E · GPU WebGL and WebGPU
Findings
- An ElementImage isn't an image. It isn't a
CanvasImageSource:drawImage,createImageBitmapandVideoFrameall reject it, and it only draws into its own canvas (2D or WebGL, main thread or worker). Every route out goes through that canvas first. - Fastest way out: a worker that owns the canvas. Snapshot → worker →
drawElementImage→transferToImageBitmap()gives a GPU-backed bitmap per frame with no main-thread rasterization, and from there it can go to any canvas, tab or origin. - Three ways keep the content as DOM: nest canvases (an inner drawable canvas is itself a drawable element of the outer one), put a same-origin iframe inside the canvas (a whole document reprojected live), or use one page-wide overlay canvas with
pointer-events: noneso any element can be drawn anywhere while the page stays clickable. - Across origins, send bitmaps or bytes.
VideoFrameand streams of them fail to deserialize in a cross-origin document (a silentmessageerror), andMediaStreamTrackdoesn't transfer.ImageBitmap, aReadableStreamof ImageBitmaps, Blobs, ArrayBuffers, encoded video chunks and WebRTC all get through. - Hit testing stops at the canvas edge.
updateElementGeometryaccepts a transform outside the canvas box, but the element isn't hit-testable there. Interactivity at a remote mirror means forwarding input (as in the cross-tab demo) or making the canvas bigger (the overlay). - Not testable in every environment: WebGPU needs a GPU adapter, and SharedArrayBuffer needs cross-origin isolation headers, which this site doesn't send yet.