Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(cli): a scoped keepsMoving capture ignores the page background behind it (#5966)
Miguel Ángelba1fa8b12aef
diff --git a/packages/cli/src/commands/motion-signature.browser.js b/packages/cli/src/commands/motion-signature.browser.jsindex 24760de4b7..0bd54ddcab 100644--- a/packages/cli/src/commands/motion-signature.browser.js+++ b/packages/cli/src/commands/motion-signature.browser.js@@ -428,7 +428,8 @@return (Math.abs(a[i] - b[i]) > FRAME_CHANNEL_NOISE ||Math.abs(a[i + 1] - b[i + 1]) > FRAME_CHANNEL_NOISE ||- Math.abs(a[i + 2] - b[i + 2]) > FRAME_CHANNEL_NOISE+ Math.abs(a[i + 2] - b[i + 2]) > FRAME_CHANNEL_NOISE ||+ Math.abs(a[i + 3] - b[i + 3]) > FRAME_CHANNEL_NOISE);}diff --git a/packages/cli/src/utils/checkBrowser.ts b/packages/cli/src/utils/checkBrowser.tsindex 35b1deece5..ddbf9cd6be 100644--- a/packages/cli/src/utils/checkBrowser.ts+++ b/packages/cli/src/utils/checkBrowser.ts@@ -1013,14 +1013,19 @@ async function captureFrame(page: Page, scope?: string): Promise<string> {try {const box = await page.evaluate(isolateScopePaint, scope);if (!box || box.width < 1 || box.height < 1) return "";- return await page.screenshot({ encoding: "base64", type: "png", clip: box });+ return await page.screenshot({+ encoding: "base64",+ type: "png",+ clip: box,+ omitBackground: true,+ });} finally {await page.evaluate(restoreScopePaint);}}// Liveness signs only the scope's subtree, so its frame must show only that paint: anything else behind or-// over the box (a moving background, grain) would read as the scope moving. Hidden like the contrast pass's glyphs.+// over the box (a moving background, grain, the page canvas) would read as the scope moving; the canvas stays clear.function isolateScopePaint(scope: string,): { x: number; y: number; width: number; height: number } | null {@@ -1036,6 +1041,7 @@ function isolateScopePaint(const style = document.createElement("style");style.id = "__hf_capture_scope_style";style.textContent = `:not([data-hf-capture-scope], [data-hf-capture-scope] *) { visibility: hidden !important; }+ :root:not([data-hf-capture-scope]), body:not([data-hf-capture-scope]) { background: none !important; }[data-hf-capture-scope] { visibility: ${visibility} !important; }`;document.head.append(style);const rect = target.getBoundingClientRect();diff --git a/packages/cli/src/utils/checkSweep.chromium.test.ts b/packages/cli/src/utils/checkSweep.chromium.test.tsindex ce018a6e11..70cf5fb7a8 100644--- a/packages/cli/src/utils/checkSweep.chromium.test.ts+++ b/packages/cli/src/utils/checkSweep.chromium.test.ts@@ -150,6 +150,27 @@ describe.skipIf(!RUNS_CHROMIUM)("frozen-sweep guard in Chromium", () => {expect(result.frozen).toEqual([expect.stringContaining("nothing moves within #title")]);});+ it("keeps a still title frozen under keepsMoving while the page's root background changes", async () => {+ const html = film(+ `<h1 id="title" style="position: absolute; left: 120px; top: 120px; margin: 0; padding: 40px;+ color: #fff; font: 600 48px sans-serif">Still</h1>`,+ `document.documentElement.style.background = "rgb(" + Math.round(t * 40) + ", 0, 80)";`,+ );+ const result = await findings(html, [{ kind: "keepsMoving", withinSelector: "#title" }]);+ expect(result.frozen).toEqual([expect.stringContaining("nothing moves within #title")]);+ });++ it("sees dark paint revealed inside a scope, where only its alpha tells it from the cleared page", async () => {+ const html = film(+ `<svg id="scene" width="640" height="360"><defs><mask id="dark"><rect width="640" height="360" fill="black"/>+ <circle id="hole" cx="320" cy="180" r="0" fill="white"/></mask></defs>+ <rect width="640" height="360" fill="#000" mask="url(#dark)"/></svg>`,+ `document.getElementById("hole").setAttribute("r", String(t * 60));`,+ );+ const result = await findings(html, [{ kind: "keepsMoving", withinSelector: "#scene" }]);+ expect(result.frozen).toEqual([]);+ });+it("still warns on a canvas that animates by the wall clock, not by the seek", async () => {const html = film(`<canvas id="c" width="640" height="360"></canvas>