What happens when the DOM can go anywhere a pixel can?

Experiments with the HTML-in-canvas API: reprojecting real, interactive DOM through slots, workers, tabs and origins. Each page runs live tests in your browser and says what works and what doesn't.

The building block

canvas-slot.js is one dependency-free module. Children with a slot name are projected into a canvas; you get a render callback with a draw(name, x, y) helper. Add worker="…" to render off the main thread, or pair it with slot-share.js to publish slots to other tabs and origins.

<script type="module" src="https://html-in-canvas-demos.kinlan-test.workers.dev/lib/canvas-slot.js"></script>

<canvas-slot id="stage">
  <h2 slot="title">Real DOM</h2>
  <button slot="cta">Still clickable</button>
</canvas-slot>

<script type="module">
  const stage = document.getElementById('stage');   // the <canvas-slot> element

  // draw(slotName, x, y) is drawElementImage() for the element in that slot.
  stage.onrender = ({ ctx, draw, time }) => {
    ctx.rotate(Math.sin(time / 800) * 0.05);
    draw('title', 20, 20);
    draw('cta', 20, 90);
  };
</script>

Where this could go

Needs Chrome 148+ with chrome://flags/#canvas-draw-element (or the html-in-canvas origin trial). Everything else, including this page, is plain HTML. Source: github.com/PaulKinlan/html-in-canvas-demos.