fix(check): a media source that failed to load is not reported as a timeout (#7954)

When an <audio> clip's source failed to load (a 404, a format Chrome
can't play), the slot-fit audit put it with the clips whose metadata
was still loading and told the person to re-run with a longer --timeout,
next to the http_error for the same file. The audit's probe already
stops waiting on the error, so the timeout was never the cause. Record
whether the element or its probe errored, and report those clips as
failed to load, without the timeout advice.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
wonjang
2026-11-16 18:16:26 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent d7f8d77fb4
commit 5e0c3db128
2 changed files with 54 additions and 10 deletions
@@ -99,4 +99,30 @@ describe("audio the page never loaded", () => {
expect.stringContaining('Audio "voice" is 3.00s'),
]);
});
it("says a source that failed to load is not a timeout", async () => {
class MissingProbe extends EventTarget {
preload = "";
duration = Number.NaN;
error: { code: number } | null = null;
set src(_url: string) {
queueMicrotask(() => {
this.error = { code: 4 };
this.dispatchEvent(new Event("error"));
});
}
}
vi.stubGlobal("Audio", MissingProbe);
document.body.innerHTML = '<audio id="voice" src="missing.wav" data-duration="5"></audio>';
const evaluate: Page["evaluate"] = async (fn, ...args) => {
if (typeof fn !== "function") throw new Error("Expected a browser function");
return window.eval(`(${fn.toString()})`)(...args);
};
const warnings = await auditClipDurations({ evaluate }, analyzeClipMediaFit, 1000);
expect(warnings).toHaveLength(1);
expect(warnings[0]?.text).toContain("failed to load (voice)");
expect(warnings[0]?.text).not.toContain("Re-run with a longer --timeout");
});
});
+28 -10
View File
@@ -140,6 +140,29 @@ export function raceMediaReady(
});
}
function unmeasuredClipWarnings(unreadable: string[], unloadable: string[]): ConsoleEntry[] {
const warnings: ConsoleEntry[] = [];
if (unreadable.length > 0) {
warnings.push({
level: "warning",
text:
`Could not read the duration of ${unreadable.length} media element(s) within the ` +
`validate timeout (${unreadable.join(", ")}); their slot vs. source fit was not checked. ` +
`Re-run with a longer --timeout if the source is slow to load.`,
});
}
if (unloadable.length > 0) {
warnings.push({
level: "warning",
text:
`${unloadable.length} media element(s) failed to load (${unloadable.join(", ")}), so ` +
`their slot vs. source fit was not checked. A longer --timeout will not help: check ` +
`that the source exists and plays in Chrome.`,
});
}
return warnings;
}
/**
* Flag `<audio>` clips whose source is meaningfully shorter than their
* `data-duration` slot (the slot gets silently shortened in renders). Videos
@@ -205,6 +228,7 @@ export async function auditClipDurations(
attributes: Record<string, string | null>;
duration: number;
loop: boolean;
failed: boolean;
}> = [];
for (const el of nodes) {
const slot = parseFloat(el.getAttribute("data-duration") ?? "");
@@ -223,6 +247,7 @@ export async function auditClipDurations(
? el.duration
: (reads.get(el)?.duration ?? Number.NaN),
loop: el.loop || el.getAttribute("data-loop") === "true",
failed: Boolean(el.error ?? reads.get(el)?.error),
});
}
return rows;
@@ -230,11 +255,12 @@ export async function auditClipDurations(
const warnings: ConsoleEntry[] = [];
const unreadable: string[] = [];
const unloadable: string[] = [];
for (const clip of clips) {
if (!Number.isFinite(clip.duration) || clip.duration <= 0) {
// Metadata never loaded (e.g. slow remote source) — record so the gap in
// coverage isn't silent, rather than dropping it.
unreadable.push(clip.id);
(clip.failed ? unloadable : unreadable).push(clip.id);
continue;
}
const mediaSeconds = resolveNaturalMediaTimelineDuration(
@@ -252,15 +278,7 @@ export async function auditClipDurations(
`Set data-duration to ~${mediaSeconds.toFixed(2)}s if that isn't intended.`,
});
}
if (unreadable.length > 0) {
warnings.push({
level: "warning",
text:
`Could not read the duration of ${unreadable.length} media element(s) within the ` +
`validate timeout (${unreadable.join(", ")}); their slot vs. source fit was not checked. ` +
`Re-run with a longer --timeout if the source is slow to load.`,
});
}
warnings.push(...unmeasuredClipWarnings(unreadable, unloadable));
return warnings;
}