diff --git a/README.md b/README.md index 7357651..465c2bf 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ renderdiff [options] | `--left-selector `, `--right-selector ` | That side's selector, over `--selector`. One without the other side (or `--selector`) is an error. | | `--mask ` | Paint this Playwright selector over on both sides, on every route; repeatable. Added to the config's masks and listed in the report as coverage given up. | | `--mask-media` | Mask every `iframe` on every route, as config `maskMedia: true` does. Video isn't masked: it is frozen by default, so the player's box is still compared. | -| `--no-freeze-video` | Leave videos playing and video.js overlays visible, as config `freezeVideo: false` does. By default every video shows its poster ([how it works](https://github.com/tmashara/renderdiff/blob/main/docs/how-it-works.md)); unfrozen, expect unstable pixels or `did not settle`. `--mask-media` doesn't mask them either. | +| `--no-freeze-video` | Leave videos playing and video.js overlays visible, as config `freezeVideo: false` does. By default every video is paused on frame 0 (its poster if it never loads) ([how it works](https://github.com/tmashara/renderdiff/blob/main/docs/how-it-works.md)); unfrozen, expect unstable pixels or `did not settle`. `--mask-media` doesn't mask them either. | | `--storage-state ` | Start both sides with this Playwright storage state (cookies, localStorage), e.g. signed in. Relative to cwd. Over the config's `storageState`. | | `--left-storage-state `, `--right-storage-state ` | That side's storage state, over `--storage-state`. One side alone is fine. | | `--accept ` | Record this run's differences as accepted, with a reason. See **Accepted differences and reruns**. | diff --git a/docs/how-it-works.md b/docs/how-it-works.md index 4dd69d4..04436c8 100644 --- a/docs/how-it-works.md +++ b/docs/how-it-works.md @@ -17,7 +17,7 @@ honestly. This is what renderdiff does to make sure of that. - **Pins what varies between loads**, identically on both sides: the clock starts at one instant per run (floored to the minute) on every load and then runs, `Math.random` is seeded, timezone (UTC), locale (en-US), colour scheme (light) and - `prefers-reduced-motion` are fixed, and videos are kept from playing (each shows its poster) with video.js captions and control bars hidden (`--no-freeze-video` opts out). A clock that shows + `prefers-reduced-motion` are fixed, and videos are kept from playing and, once their metadata loads, rewound to frame 0 (one that never loads shows its poster) with video.js captions and control bars hidden (`--no-freeze-video` opts out). A clock that shows seconds can still tick between the two sides and may need a mask. - **Kills animation, transitions and caret blink**, and hides common consent banners and dev toolbars. Animated images (GIF, WebP, APNG) and SVG animations show their first frame; diff --git a/renderdiff.config.example.ts b/renderdiff.config.example.ts index 206eb6c..a5eb2b2 100644 --- a/renderdiff.config.example.ts +++ b/renderdiff.config.example.ts @@ -80,8 +80,8 @@ export default { // a selector list cannot express. extraCss: `.chat-launcher { visibility: hidden !important }`, - // Videos are kept from playing (each shows its poster) and video.js captions and - // control bars are hidden. false, or --no-freeze-video, lets them play. + // Videos are kept from playing on frame 0 (their poster if they never load) and video.js + // captions and control bars are hidden. false, or --no-freeze-video, lets them play. freezeVideo: true, // Mask every iframe on every route (embeds that differ per load). Same as --mask-media. diff --git a/skills/renderdiff/reference.md b/skills/renderdiff/reference.md index f70bd7a..70a88c1 100644 --- a/skills/renderdiff/reference.md +++ b/skills/renderdiff/reference.md @@ -179,8 +179,9 @@ computed: 2 findings; dom identical on 2 of 3 route(s), differs /pricing (1), so - Every mask is coverage surrendered and listed in the report with its reason. `--mask-media` gives up every iframe. Video is not masked: it is frozen by default (no `video` plays, each - shows its poster, video.js captions and control bars hidden), so its box is still compared. - `--no-freeze-video` lets it play: expect `unstable` or `did not settle`. + shows frame 0, or its poster if it never loads, video.js captions and control bars hidden), + so its box is still compared. `--no-freeze-video` lets it play: expect `unstable` or + `did not settle`. - Masks hide text too, so masked text leaves the text diff. - Pages see `window.__RENDERDIFF__ === true` before their first script; anything hidden on it must be hidden in both builds. diff --git a/src/capture.ts b/src/capture.ts index acf1026..a37c6c8 100644 --- a/src/capture.ts +++ b/src/capture.ts @@ -26,7 +26,8 @@ export interface Shot { /** * Runs in the page, behind `prepare`'s init script: pause every video, open shadow roots - * included. One that played anyway is rewound to frame 0; one that hasn't keeps its poster. + * included. Once its metadata loads (waited for up to 2s), each is seeked to 0, so it shows + * frame 0 at its own aspect ratio; one that never loads keeps its poster. */ function freezeVideo() { const videos = (root: Document | ShadowRoot): HTMLVideoElement[] => [ @@ -36,14 +37,18 @@ function freezeVideo() { ), ]; return Promise.all( - videos(document).map((v) => { + videos(document).map(async (v) => { v.autoplay = false; v.pause(); - if (!v.readyState || (!v.played.length && !v.currentTime)) return; - const seeked = new Promise((r) => { - v.addEventListener("seeked", r, { once: true }); - setTimeout(r, 2_000); - }); + const until = (...events: string[]) => + new Promise((r) => { + for (const e of events) v.addEventListener(e, r, { once: true }); + setTimeout(r, 2_000); + }); + if (!v.readyState && v.networkState === v.NETWORK_LOADING) + await until("loadedmetadata", "error"); + if (!v.readyState) return; + const seeked = until("seeked"); v.currentTime = 0; return seeked; }), @@ -139,7 +144,7 @@ export async function prepare(page: Page, cfg: ResolvedConfig, now: number): Pro } // Time flows, so Date-based debounce and busy-waits work; `capture` rewinds it per load. await page.clock.install({ time: now }); - // From the first script on, so no video starts and each keeps its poster however fast it loads. + // From the first script on, so no video starts however fast it loads. if (cfg.freezeVideo) await page.addInitScript(() => { HTMLMediaElement.prototype.play = () => Promise.resolve(); diff --git a/src/config.ts b/src/config.ts index 552db1c..d9e5a14 100644 --- a/src/config.ts +++ b/src/config.ts @@ -266,7 +266,7 @@ export interface RenderdiffConfig { computed?: boolean; /** Mask every `iframe` on every route. */ maskMedia?: boolean; - /** Keep every video from playing, so it shows its poster, and hide video.js overlays. Default true. */ + /** Keep every video paused on frame 0 (its poster if it never loads) and hide video.js overlays. Default true. */ freezeVideo?: boolean; } diff --git a/tests/fixtures/pages/README.md b/tests/fixtures/pages/README.md index 804d90a..830b2bc 100644 --- a/tests/fixtures/pages/README.md +++ b/tests/fixtures/pages/README.md @@ -19,7 +19,7 @@ Three groups: elements each change names (`margin`, `color`, `nav`), and a lost `::before` line and a re-parented pairing (`divider`). - **Guard rails** — `blank`, `tall`, `animated`, `lazy`, `lazy-deep`, `lazy-js`, `lazy-grow`, `consent`, - `drifting`, `tracker`, `clock`, `ticker`, `unsettled`, `sprite`, `short`, `tall-region`, `reorder`, `stripe`, `frameset`, `menu`, `signed-in`, `fixed`, `inserted`, `labelled`, `broken-asset`, `media`, `long`, `video`, `hang`, `origin`, `cooperate`. + `drifting`, `tracker`, `clock`, `ticker`, `unsettled`, `sprite`, `short`, `tall-region`, `reorder`, `stripe`, `frameset`, `menu`, `signed-in`, `fixed`, `inserted`, `labelled`, `broken-asset`, `media`, `long`, `video`, `video-seek`, `hang`, `origin`, `cooperate`. One per defence in `src/capture.ts` / `src/config.ts`. ## Authoring rules diff --git a/tests/fixtures/pages/video-seek/left.html b/tests/fixtures/pages/video-seek/left.html new file mode 100644 index 0000000..78f24b5 --- /dev/null +++ b/tests/fixtures/pages/video-seek/left.html @@ -0,0 +1,22 @@ + + + + +Video seek guard rail + + + + +
+

Video seek guard rail

+

One video with a poster and no set height, so its box takes the aspect ratio of whatever it shows. The page rewinds it to the start, on one side before its metadata loads and on the other after.

+ + +
+ + diff --git a/tests/fixtures/pages/video-seek/right.html b/tests/fixtures/pages/video-seek/right.html new file mode 100644 index 0000000..24897ba --- /dev/null +++ b/tests/fixtures/pages/video-seek/right.html @@ -0,0 +1,22 @@ + + + + +Video seek guard rail + + + + +
+

Video seek guard rail

+

One video with a poster and no set height, so its box takes the aspect ratio of whatever it shows. The page rewinds it to the start, on one side before its metadata loads and on the other after.

+ + +
+ + diff --git a/tests/fixtures/pages/video/left.html b/tests/fixtures/pages/video/left.html index 55493fa..3188b13 100644 --- a/tests/fixtures/pages/video/left.html +++ b/tests/fixtures/pages/video/left.html @@ -7,7 +7,7 @@ diff --git a/tests/fixtures/pages/video/right.html b/tests/fixtures/pages/video/right.html index 55493fa..3188b13 100644 --- a/tests/fixtures/pages/video/right.html +++ b/tests/fixtures/pages/video/right.html @@ -7,7 +7,7 @@ diff --git a/tests/helpers/corpus.ts b/tests/helpers/corpus.ts index ff9818a..0b3e7bd 100644 --- a/tests/helpers/corpus.ts +++ b/tests/helpers/corpus.ts @@ -53,6 +53,7 @@ export const GUARDRAILS = [ "media", "long", "video", + "video-seek", "hang", "origin", "cooperate", diff --git a/tests/visual/guardrails.test.ts b/tests/visual/guardrails.test.ts index d20fa60..d01ff69 100644 --- a/tests/visual/guardrails.test.ts +++ b/tests/visual/guardrails.test.ts @@ -505,13 +505,20 @@ describe("selector masks", () => { ]); }); - test("autoplaying, script-played and late videos keep their poster on both sides", async () => { + test("autoplaying, script-played and late videos stay on frame 0 on both sides", async () => { const run = await capture(["/video"]); assert.equal(run.code, 0, context(run)); const r = result(results(run.outDir), "/video", 1440); assert.deepEqual([r.diffPixels, r.unstablePixels], [0, 0], context(run)); }); + test("a video seeked before its metadata on one side and after it on the other shows frame 0 on both", async () => { + const run = await capture(["/video-seek"]); + assert.equal(run.code, 0, context(run)); + const r = result(results(run.outDir), "/video-seek", 1440); + assert.deepEqual([r.diffPixels, r.unstablePixels], [0, 0], context(run)); + }); + test("--mask-media paints iframes; freezing video hides video.js overlays", async () => { const bare = await capture(["/media"]); assert.ok(result(results(bare.outDir), "/media", 1440).diffPixels > 0, context(bare));