Across origins

This page and the iframe below are on different origins ( and ). I tried it in both directions: showing the other origin's DOM here as pixels, and giving this page's DOM to the other origin to draw.

A · Their DOM, shown here

The iframe publishes its slot over a MessagePort that this page posted to it. The right-hand view is an <slot-mirror> in this document; click the heart or the input there and type.

cross-origin iframe (the DOM)

<slot-mirror name="widget"> in this page

Show the code their DOM, shown here
  1. This page: an iframe on the other origin and a <slot-mirror>.
  2. This page: post the iframe one end of a MessageChannel, attach the mirror to the other. REMOTE is the other origin.
  3. The other origin: its own DOM in its own canvas.
  4. The other origin: publish the slot on the port it was given. It sends pixels of the drawn element and replays the input that comes back. See Across tabs for what publish() does inside.

B · This page's DOM, drawn by them

The card below is this page's DOM. Its canvas was transferred to the iframe with transferControlToOffscreen(), and on every paint this page transfers an ElementImage of the card. The other origin does all the drawing (the wave is theirs) and never touches the DOM. The button works.

DOM from

Rendered by another origin.
Show the code this page's DOM, drawn by them
  1. This page: a drawable canvas with the card inside it.
  2. This page: give the other origin the canvas, then a snapshot on every paint. transferControlToOffscreen() and captureElementImage() both produce transferable objects, and postMessage carries them across origins. frame is the iframe and REMOTE its origin.
  3. The other origin: keep the canvas and the latest snapshot. This is inside its message listener; m is the message.
  4. The other origin: draw the snapshot however it likes. One plain drawElementImage() at the end, fully transparent, sets where clicks land back on this page.

What crosses an origin boundary (live)

ResultExperimentDetail

Findings