Tear-off widgets
Three ordinary widgets. Pull one out of the page into a new window, an always-on-top window, another tab or another origin. It keeps working there, and what you do to it is sent back and applied to the element on this page. Drag a grip outside this window, onto the dock tab, or pick a route from the menu.
The routes
There are only two ways for a piece of a page to appear in another window, and this page does both.
- Move the element. A window you opened is a same-origin document you can reach, so
popup.document.body.append(element)adopts the node. Its listeners, timers and state come with it, because they belong to this page's script. In the other window it's DOM, so its text can be selected, it's in the accessibility tree and input is handled by the browser. It only works while a window reference exists, on the same origin. - Stream it and replay input. The element never leaves. HTML-in-canvas gives its pixels on every
paint; they travel asImageBitmaps, video or JPEGs and input comes back as small messages. This works over anything that carries a message, including routes with no window reference.
Show the code tearing a widget off
Each widget is ordinary markup inside a <live-region>. w.surface is that region's surface, w.content the widget's root element and win the window just opened.
- Load the pieces.
- Stream to a popup (same or another origin): post it a
MessagePortand serve the surface on the other end. - The window it opens. A
<live-view>and a few ways to get connected. It holds no DOM from this page. - Or move the real element.
append()into the other window's document adopts the node. No canvas involved. - Or float it as a video. The surface is a
MediaStream, so classic Picture-in-Picture works. - Or share it with a tab that has no link to this one, through a relay room and then WebRTC.
- 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.
What reaches another window (live)
These run in your browser now, using frames as stand-ins for the other window where a real popup would need a click.
| Result | Experiment | Detail |
|---|
One experiment isn't run automatically because it can take the tab down:
Findings
- Interaction does get back to the origin without any window link. A
noopenertab reaches the source overBroadcastChannel(ImageBitmaps clone across it), through aSharedWorkerthat hands both tabs one end of aMessageChannel, or through the Worker's relay room. EvenlocalStorageevents work as a transport. - Across origins with no link, you need a meeting point. The relay room works anywhere. A frame from the source's origin embedded in the other page can also bridge to
BroadcastChannel. Browsers that partition third-party storage are expected to cut that bridge when the two pages are different sites; headless Chromium 157 did not, so check the row above in your own browser. - A scripted
about:blankpopup needs no messaging. The opener calls into the popup's document directly and hands it ImageBitmaps by reference. - The source page has to be on screen for streaming.
paintstops when the tab is hidden, so a streamed widget freezes while you are in another tab. Moving the element into a Picture-in-Picture window doesn't have that problem, because the element is then painted by that window. - Video Picture-in-Picture is view only, but not button-less. Media Session actions show as buttons on the video window, and this page maps them to the widget's own buttons.