diff --git a/packages/engine/src/services/drawElementCanvasForm.browser.test.ts b/packages/engine/src/services/drawElementCanvasForm.browser.test.ts
new file mode 100644
index 0000000000..5492b21f11
--- /dev/null
+++ b/packages/engine/src/services/drawElementCanvasForm.browser.test.ts
@@ -0,0 +1,77 @@
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
+import puppeteer, { type Browser, type Page } from "puppeteer-core";
+import { resolveHeadlessShellPath } from "./browserManager.js";
+import { closeTestChrome } from "./__fixtures__/loopback.js";
+import { injectDrawElementCanvas } from "./drawElementService.js";
+
+const chromePath = process.env.HF_DRAWABLE_TEST_CHROME ?? resolveHeadlessShellPath();
+const COMPOSITION = '
';
+const ATTRIBUTE_ERROR = /requires the canvas to have|must have the 'drawable' attribute/;
+
+/** Makes drawElementImage check only the 157 marks, throwing as Chrome 157 does without them. */
+async function actLikeChrome157(page: Page): Promise {
+ await page.evaluate(() => {
+ delete (HTMLCanvasElement.prototype as unknown as Record).layoutSubtree;
+ (HTMLCanvasElement.prototype as unknown as Record).updateElementGeometry =
+ () => {};
+ CanvasRenderingContext2D.prototype.drawElementImage = function (el: Element) {
+ if (this.canvas.getAttribute("content") !== "drawable") {
+ throw new DOMException(
+ "DrawElementImage requires the canvas to have the content=drawable attribute",
+ "InvalidStateError",
+ );
+ }
+ if (!el.hasAttribute("drawable")) {
+ throw new DOMException(
+ "Descendants passed to DrawElementImage must have the 'drawable' attribute",
+ "InvalidStateError",
+ );
+ }
+ };
+ });
+}
+
+async function drawInjectedRoot(page: Page): Promise {
+ return page.evaluate(() => {
+ const canvas = document.getElementById("__hf_de_canvas") as HTMLCanvasElement;
+ const root = document.querySelector("[data-composition-id]") as Element;
+ try {
+ canvas.getContext("2d")!.drawElementImage(root, 0, 0);
+ return "";
+ } catch (err) {
+ return String(err);
+ }
+ });
+}
+
+describe.skipIf(!chromePath)("drawElement capture canvas form", () => {
+ let browser: Browser;
+ beforeAll(async () => {
+ browser = await puppeteer.launch({
+ executablePath: chromePath,
+ headless: true,
+ args: ["--no-sandbox", "--disable-dev-shm-usage", "--enable-features=CanvasDrawElement"],
+ });
+ });
+ afterAll(() => closeTestChrome(browser));
+
+ it.each([
+ ["this Chrome", false],
+ ["a Chrome that wants content=drawable (157+)", true],
+ ])("is accepted by drawElementImage on %s", async (_name, like157) => {
+ const page = await browser.newPage();
+ try {
+ await page.setContent(COMPOSITION);
+ // A Chrome without the API would "pass" on a TypeError, so the API must be there.
+ expect(
+ await page.evaluate(() => "drawElementImage" in CanvasRenderingContext2D.prototype),
+ ).toBe(true);
+ if (like157) await actLikeChrome157(page);
+ await injectDrawElementCanvas(page, 64, 32);
+ // "No cached paint record" is fine here: the marks were accepted, nothing has painted yet.
+ expect(await drawInjectedRoot(page)).not.toMatch(ATTRIBUTE_ERROR);
+ } finally {
+ await page.close();
+ }
+ });
+});
diff --git a/packages/engine/src/services/drawElementService.ts b/packages/engine/src/services/drawElementService.ts
index 25a948d52d..4d82564f03 100644
--- a/packages/engine/src/services/drawElementService.ts
+++ b/packages/engine/src/services/drawElementService.ts
@@ -15,6 +15,7 @@
*/
import type { Page } from "puppeteer-core";
+import { htmlInCanvasForm, type HtmlInCanvasForm } from "@hyperframes/core/html-in-canvas";
import { SOFTWARE_WEBGL_RENDERER_TOKENS } from "./browserManager.js";
import type { CaptureMode } from "./browserLeasePool.js";
@@ -269,7 +270,7 @@ export async function detectSwiftShader(page: Page): Promise {
}
/**
- * Inject a `