Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ renderdiff <left-origin> <right-origin> <route…> [options]
| `--left-selector <sel>`, `--right-selector <sel>` | That side's selector, over `--selector`. One without the other side (or `--selector`) is an error. |
| `--mask <sel>` | 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 <file>` | 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 <file>`, `--right-storage-state <file>` | That side's storage state, over `--storage-state`. One side alone is fine. |
| `--accept <reason>` | Record this run's differences as accepted, with a reason. See **Accepted differences and reruns**. |
Expand Down
2 changes: 1 addition & 1 deletion docs/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions renderdiff.config.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions skills/renderdiff/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 13 additions & 8 deletions src/capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] => [
Expand All @@ -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;
}),
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/pages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/pages/video-seek/left.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Video seek guard rail</title>
<link rel="stylesheet" href="/shared/base.css">
<style>
/* GUARD RAIL for the seek after metadata. The poster is 16:10 and the clip 16:9, so the box is
400px tall while it shows the poster and 360px once a seek follows metadata. The left side
seeks after metadata, the right before it; frozen, both are seeked after metadata. */
video { display: block; width: 640px; margin-top: var(--gap); }
</style>
</head>
<body>
<div class="page">
<h1>Video seek guard rail</h1>
<p class="lede">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.</p>
<video id="v" muted poster="/shared/img/azure.svg" src="/shared/video/clip.webm"></video>
<script>document.getElementById("v").addEventListener("loadedmetadata", (e) => { e.target.currentTime = 0; });</script>
</div>
</body>
</html>
22 changes: 22 additions & 0 deletions tests/fixtures/pages/video-seek/right.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Video seek guard rail</title>
<link rel="stylesheet" href="/shared/base.css">
<style>
/* GUARD RAIL for the seek after metadata. The poster is 16:10 and the clip 16:9, so the box is
400px tall while it shows the poster and 360px once a seek follows metadata. The left side
seeks after metadata, the right before it; frozen, both are seeked after metadata. */
video { display: block; width: 640px; margin-top: var(--gap); }
</style>
</head>
<body>
<div class="page">
<h1>Video seek guard rail</h1>
<p class="lede">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.</p>
<video id="v" muted poster="/shared/img/azure.svg" src="/shared/video/clip.webm"></video>
<script>document.getElementById("v").currentTime = 0;</script>
</div>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/fixtures/pages/video/left.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<style>
/* GUARD RAIL for video freezing. The same autoplaying, script-played and late-inserted videos on
both sides; the fixture server delays the right side's video, so without freezing one side
shows the poster while the other plays. Frozen, both keep the poster. */
shows the poster while the other plays. Frozen, both stay on frame 0. */
video { display: block; width: 640px; height: 360px; margin-top: var(--gap); }
</style>
</head>
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/pages/video/right.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<style>
/* GUARD RAIL for video freezing. The same autoplaying, script-played and late-inserted videos on
both sides; the fixture server delays the right side's video, so without freezing one side
shows the poster while the other plays. Frozen, both keep the poster. */
shows the poster while the other plays. Frozen, both stay on frame 0. */
video { display: block; width: 640px; height: 360px; margin-top: var(--gap); }
</style>
</head>
Expand Down
1 change: 1 addition & 0 deletions tests/helpers/corpus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const GUARDRAILS = [
"media",
"long",
"video",
"video-seek",
"hang",
"origin",
"cooperate",
Expand Down
9 changes: 8 additions & 1 deletion tests/visual/guardrails.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading