Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(compiler): don't scan media tags inside comments/scripts; DOM-check auto-start (#1938) (#1940)
Miguel Ángel1a3330a972d9
diff --git a/packages/core/src/compiler/timingCompiler.test.ts b/packages/core/src/compiler/timingCompiler.test.tsindex f32f0df17a..86e7dfe7ce 100644--- a/packages/core/src/compiler/timingCompiler.test.ts+++ b/packages/core/src/compiler/timingCompiler.test.ts@@ -128,6 +128,35 @@ describe("compileTimingAttrs", () => {expect(unresolved).toHaveLength(0);});++ it("ignores media tags mentioned inside comments (issue #1938)", () => {+ const html =+ "<!-- this comment mentions a <video> and an <audio> tag -->\n<p>no media here</p>";+ const { html: compiled, unresolved } = compileTimingAttrs(html);++ // Comment text is preserved verbatim — no id/data-start/data-hf-auto-start injected.+ expect(compiled).toBe(html);+ expect(compiled).not.toContain("data-hf-auto-start");+ expect(unresolved).toHaveLength(0);+ });++ it("ignores media tags inside <script> string literals", () => {+ const html = '<script>const x = "<video src=\\"a.mp4\\">";</script>';+ const { html: compiled, unresolved } = compileTimingAttrs(html);++ expect(compiled).toBe(html);+ expect(unresolved).toHaveLength(0);+ });++ it("still compiles real media tags alongside a comment that mentions them", () => {+ const html =+ '<!-- a <video> in prose -->\n<video src="a.mp4" data-start="0" data-duration="2">';+ const { html: compiled } = compileTimingAttrs(html);++ expect(compiled).toContain("<!-- a <video> in prose -->");+ expect(compiled).toContain('id="hf-video-0"');+ expect(compiled).toContain('data-end="2"');+ });});describe("injectDurations", () => {diff --git a/packages/core/src/compiler/timingCompiler.ts b/packages/core/src/compiler/timingCompiler.tsindex c4d74d8b82..eb55a112a8 100644Binary files a/packages/core/src/compiler/timingCompiler.ts and b/packages/core/src/compiler/timingCompiler.ts differdiff --git a/packages/producer/src/services/render/stages/probeStage.test.ts b/packages/producer/src/services/render/stages/probeStage.test.tsindex 5ca0d64dce..ebab7bd907 100644--- a/packages/producer/src/services/render/stages/probeStage.test.ts+++ b/packages/producer/src/services/render/stages/probeStage.test.ts@@ -1,5 +1,5 @@import { describe, expect, it, mock } from "bun:test";-import { hasScriptedAudioVolumeAutomation } from "./probeStage.js";+import { hasAutoStartVideos, hasScriptedAudioVolumeAutomation } from "./probeStage.js";// ── Mocks for runProbeStage tests ────────────────────────────────────────────// Capture the cfg passed to createCaptureSession so we can assert it carries@@ -224,6 +224,26 @@ describe("hasScriptedAudioVolumeAutomation", () => {});});+describe("hasAutoStartVideos", () => {+ it("detects a real auto-start video element", () => {+ expect(hasAutoStartVideos(`<video src="a.mp4" data-hf-auto-start="">`)).toBe(true);+ });++ it("ignores the attribute mentioned in a comment (issue #1938)", () => {+ expect(hasAutoStartVideos(`<!-- videos get data-hf-auto-start injected --><p>hi</p>`)).toBe(+ false,+ );+ });++ it("ignores the attribute in prose text", () => {+ expect(hasAutoStartVideos(`<p>the data-hf-auto-start sentinel</p>`)).toBe(false);+ });++ it("returns false when there is no media", () => {+ expect(hasAutoStartVideos(`<div class="clip"></div>`)).toBe(false);+ });+});+describe("runProbeStage — forceScreenshot threading", () => {it("passes forceScreenshot:true to createCaptureSession when stage input carries it but cfg does not (low-memory mode fix #1236)", async () => {capturedCfgs.length = 0;diff --git a/packages/producer/src/services/render/stages/probeStage.ts b/packages/producer/src/services/render/stages/probeStage.tsindex 3dbc45b7c0..248dad4390 100644--- a/packages/producer/src/services/render/stages/probeStage.ts+++ b/packages/producer/src/services/render/stages/probeStage.ts@@ -114,6 +114,17 @@ export function hasScriptedAudioVolumeAutomation(html: string, audioCount: numbe);}+/**+ * True when the compiled HTML has at least one `<video>` carrying the+ * auto-injected `data-hf-auto-start` sentinel. Uses a DOM query, not a+ * substring scan — `html.includes("data-hf-auto-start")` false-fires on any+ * comment or prose that merely mentions the attribute (issue #1938).+ */+export function hasAutoStartVideos(html: string): boolean {+ const { document } = parseHTML(html);+ return document.querySelector("video[data-hf-auto-start]") !== null;+}+export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageResult> {const {projectDir,@@ -139,7 +150,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageRlet lastBrowserConsole: string[] = [];const probeStart = Date.now();- const hasAutoStartVideos = compiled.html.includes("data-hf-auto-start");+ const hasAutoStart = hasAutoStartVideos(compiled.html);const hasScriptedAudio = hasScriptedAudioVolumeAutomation(compiled.html,composition.audios.length,@@ -147,7 +158,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageRconst needsBrowser =composition.duration <= 0 ||compiled.unresolvedCompositions.length > 0 ||- hasAutoStartVideos ||+ hasAutoStart ||hasScriptedAudio;if (needsBrowser) {@@ -155,6 +166,7 @@ export async function runProbeStage(input: ProbeStageInput): Promise<ProbeStageRif (composition.duration <= 0) reasons.push("root duration unknown");if (compiled.unresolvedCompositions.length > 0)reasons.push(`${compiled.unresolvedCompositions.length} unresolved composition(s)`);+ if (hasAutoStart) reasons.push("auto-start video(s)");if (hasScriptedAudio) reasons.push("scripted audio volume");log.info("Launching browser for composition probe...", {