Remote component
Scan the code and the panel below is on your phone. It's streamed over WebRTC, and your taps and typing on the phone are sent back and applied to the element on this page. The phone doesn't need HTML-in-canvas, and this one element is all it receives.
Living room
Not shared yet.
Show the code one element on another device
- Wrap the part of the page to share in
<live-region>. - Share its surface in a room.
roomis a short random code. The link in the QR code is the viewer page with that code after the#. - The phone's page: a
<live-view>. It needs no HTML-in-canvas. - The phone's page: join the same room.
- Inside
shareInRoom(): a WebRTC video track of the surface for each viewer, with a data channel for input, and relayed JPEGs when WebRTC can't connect. - Inside
<live-region>: a shadow root with a drawable canvas and a slot. Your markup is slotted into the canvas, so it can be drawn without being moved. - Inside: on every
paintevent, draw the element. - Inside: copy the pixels to a second canvas, and black out private fields. That second canvas is the only thing that ever leaves the page.
- Inside: hand the copy out as an
ImageBitmapor aMediaStream. - Inside: replay the input that comes back on the real elements.
- The whole library.
How it travels
- Capture. The panel sits in a
<live-region>, whose shadow root paints it through an HTML-in-canvas canvas. Everypaintcopies the result to a second canvas, andcaptureStream()turns that into a video track. There's no screen-capture prompt, and nothing outside the element is in the picture. - Introduce. Both ends open a WebSocket to a room on the Worker (a Durable Object), which relays the WebRTC offer, answer and ICE candidates.
- Stream. Video goes peer to peer. Input comes back on an
RTCDataChannelas normalised coordinates and keys, and is replayed on the element. - Fall back. If the peers can't connect, the phone asks for relayed frames instead: JPEGs sent through the same WebSocket at a few frames a second.
Live checks
| Result | Experiment | Detail |
|---|
Findings
- Only the source needs HTML-in-canvas. The viewer is a
<video>and a few event listeners, so it runs on any phone. - Controls that open native UI need help. A
<select>popup or an on-screen keyboard belongs to the device in your hand and can't be streamed from the source. The source sends the options and the viewer shows its own native picker; a map of the element's fields tells the viewer when to raise its keyboard. - Pixels carry no roles or names, so the source sends an element map. Alongside video the source sends roles, names and positions of the interactive elements, read from the DOM. That's enough to rebuild an accessible outline at the far end.
- The source tab must stay visible. A hidden tab stops painting, so the stream freezes. The viewer is told and says so.
- STUN is enough for most home networks. It isn't enough for phones on mobile data. STUN only tells each device its public address. Mobile carriers and many offices give every destination a different port (symmetric NAT), so the two addresses never match up and the connection fails after about 15 seconds. A TURN server relays the packets instead. This site asks
/api/x/icefor servers: STUN always, plus Cloudflare Realtime TURN with one-hour credentials when the Worker has a key. - Without TURN the page falls back to a relay. It sends JPEGs through the room's WebSocket, at one Durable Object message per frame. The viewer switches to it after 7 seconds and moves to video if WebRTC connects later.
- A phone needs its errors on the page. Both ends keep a connection log: the room, the servers offered, each kind of candidate found, the route chosen and every error, with a button to copy it.