Iframes as tiles: sizing, focus, prerender and limits
An <iframe> can be a child of a drawable canvas, and the canvas draws the whole embedded document. I had four questions about that:
can a tile take its height from the document inside it, can the embedder stop a tile from taking focus, is a cross-origin tile loaded while the page is prerendered, and what does the canvas get from a cross-origin tile.
Tiles A and B come from this origin. Tile C comes from another origin. Each tile's height is the height of its document: press Add a line, here or inside a tile, and the board moves the others. Tile C is drawn as an outline with a note, because a canvas receives no pixels from a cross-origin iframe. It still takes clicks and typing where it is drawn.
Show the code tiles that size themselves
- The tiles are iframes inside the canvas.
- CSS asks for content sizing. Chromium 157 parses this and does nothing with it, so step 4 does the same job by message.
- The embedded document opts in.
- Fallback: the tile reports its height and the board applies it.
- Lay the tiles out and draw them.
- What a tile does to take focus, and the attribute that is meant to stop it.
- The prerendered page.
Measurements
These run on separate fixtures in a corner of the window, not on the board. One of them moves keyboard focus into a fixture and back, so they wait for this button.
| Result | Experiment | Detail |
|---|
Prerender
When a page is prerendered, its same-origin iframes load with it and its cross-origin iframes wait until the page is shown. From Chrome 159 a page sent with
Supports-Loading-Mode: prerender-cross-origin-frames has its cross-origin iframes loaded during prerender too. Two copies of a small board are compared, one sent with the header and one without.
Press the button, wait a few seconds, then open each link. Each page reports what had already happened when it was shown.
Findings
frame-sizing: content-heightdoesn't size an iframe in Chromium 157 or 153. The property parses andwindow.requestResize()exists, but the call throwsNotAllowedError("allowed only from HTML documents withresponsive-embedded-sizingmeta tags") in a document that has the tag, and the iframe stays 150 px tall. The board sizes tiles by message. The first two measurements pass on a browser where the CSS works.- A same-origin iframe is drawn like any element. A change inside it raises the canvas's
paintevent with norequestPaint(). - A cross-origin or sandboxed iframe is drawn as nothing.
drawElementImage()doesn't throw; every pixel is transparent.texElementSubImage2D()gives a WebGL shader the same empty texture. The iframe is still hit tested where it was drawn, so a click reaches a document the person can't see. A board has to draw something of its own in that place. - To put a shader on another origin's content, that origin has to draw itself. The embeddable cards page does this: the provider draws its own DOM into a canvas the host lent it.
allow="focus-without-user-activation 'none'"is enforced in Chromium 153 with experimental features on, and not in the 157 test build. Where it is enforced,focus()on load inside the tile leaves focus with the page. Without it, a tile takes focus as soon as it loads, same-origin or not.- The prerender comparison hasn't been measured. A browser driven by automation refuses to prerender (
PrerenderingDisabledByDevTools), so both linked pages report that they weren't prerendered. It needs a person: press the button, wait a few seconds, then open each link. Each page lists which tiles had loaded before it was shown. - Removing an iframe during a
paintevent crashes the tab in Chromium 157. This includes a microtask of the handler. Losing a WebGL context there, while the canvas holds an iframe, crashed it too. The measurements on this page leave the event with a timer before they remove a fixture.