Transport lab 2: newer routes
More routes for getting a drawn element to another thread, document or device, using APIs from Chrome 130 to 160:
WebRTC sender settings that keep text sharp, an RTCDataChannel moved to a worker, SharedArrayBuffer under
Document-Isolation-Policy, WebTransport datagrams and Element Capture. The first lab has the other fifty.
Each row is a test that runs in this browser. Nothing runs until you press the button, and each row removes its canvas before the next one starts.
Show the code the helpers the rows share
Every row has its own Show the code link with the function it ran. They use these.
source(): a drawable canvas with one element drawn into it.loopback(): twoRTCPeerConnections in this page, joined to each other. It stands in for two devices.- The worker that takes the data channel and reads the shared memory.
- The frame served with
Document-Isolation-Policy. - The freeze test.
- The timer that runs in a worker and in a SharedWorker.
freeze-log.js: record when the browser stopped the page.
A · WebRTC sender settings for a stream of text, not of camera video
B · Workers and shared memory
C · WebTransport
D · Element Capture needs a press and a permission prompt
Element Capture records the tab and crops the track to one element. It's the browser's own way to share one element, so it's compared here with canvas.captureStream() of a canvas that draws the element. The three targets below must be on screen to be captured.
E · When the browser freezes the source tab
A page that streams an element only produces frames while it runs. Chrome on Android freezes a hidden tab after about a minute; desktop Chrome does it under Energy Saver. This test measures what stops. Press the button, switch to another tab or app for at least 90 seconds, then come back.
| What | Longest stop | Detail |
|---|---|---|
| Timer on the page | not run | setInterval, 250 ms |
paint events of a drawable canvas | not run | requestPaint() on every timer tick |
| Timer in a dedicated worker | not run | where a worker-owned canvas would draw |
| Timer in a SharedWorker | not run | the broker of the cross-tab demo |
| WebSocket to this site's room server | not run | the signalling and relay route of the remote demo |
What freeze-log.js has recorded for this tab:
- Nothing recorded yet: this tab hasn't been hidden.
Findings
degradationPreference: 'maintain-framerate-and-resolution'keeps the element at its own size. With the default (balanced) and a low bitrate, WebRTC shrinks the picture, which blurs text first. With this value the encoder keeps the size and the page is responsible for sending fewer frames.scaleResolutionDownTosends a smaller stream without resizing the canvas. The source canvas stays at full size for the page; the phone gets a picture no larger than the size given.- An
RTCDataChanneltransfers to a worker, once, before anything is sent on it. Transfer it in thedatachannelevent. After that, input from the far device is parsed off the main thread. Document-Isolation-Policyisolates one frame. The frame getsSharedArrayBufferandAtomics.wait; the page around it stays as it was and keeps its cross-origin frames. This page isn't isolated, so the same code fails here, which the row before it shows.- WebTransport has no server on this site. The Cloudflare Workers documentation lists no way to accept a WebTransport session, so the datagram row fails with the browser's error. The row's code hasn't been run against a real server. Add
?wt=https://host/pathto point the row at an echo server of your own. - Element Capture can't be answered by a headless browser, so those rows have only been run by hand. See the detail text they print.
- Freezing hasn't been measured yet. Neither test browser can be made to freeze a tab (the DevTools lifecycle command changes nothing there, and no
freezeevent fires), so the freeze test above has only run with the tab visible. It needs a phone. The remote and cross-tab pages now report on their own page how long they were stopped. track.statsdoesn't exist on a canvas capture track. The frame counters are only on camera and screen capture tracks, so a canvas stream has to count its own frames.