diff --git a/docs/how-it-works.md b/docs/how-it-works.md index 15c1162..04d3782 100644 --- a/docs/how-it-works.md +++ b/docs/how-it-works.md @@ -22,7 +22,7 @@ honestly. This is what renderdiff does to make sure of that. - **Kills animation, transitions and caret blink**, and hides common consent banners and dev toolbars. - **Settles the page** — makes native lazy images eager, scrolls every viewport-height - slice a frame at a time so script lazy loaders fire, waits for every image to decode, + slice a frame at a time, to the bottom even as the page grows, so script lazy loaders fire, waits for every image to decode, `document.fonts.ready` (at most 5s) and up to 3s for the network to go 250ms with nothing in flight (server-sent events and beacons don't count), then re-injects the stylesheet to catch late-injected chrome. Stylesheets that failed or answered ≥ 400 (blocked URLs diff --git a/src/capture.ts b/src/capture.ts index 070169b..0d57408 100644 --- a/src/capture.ts +++ b/src/capture.ts @@ -190,8 +190,11 @@ export async function capture( // The fake clock drives rAF too, so add wall time for a real paint per slice. const frame = () => new Promise((r) => requestAnimationFrame(() => setTimeout(r, 32))); Array.from(document.images).forEach((img) => (img.loading = "eager")); - const h = Math.min(document.documentElement.scrollHeight, maxHeight); - for (let y = 0; y < h; y += window.innerHeight) { + for ( + let y = 0; + y < Math.min(document.documentElement.scrollHeight, maxHeight); + y += window.innerHeight + ) { window.scrollTo(0, y); await frame(); } diff --git a/tests/fixtures/pages/README.md b/tests/fixtures/pages/README.md index 5b4adb5..37108ef 100644 --- a/tests/fixtures/pages/README.md +++ b/tests/fixtures/pages/README.md @@ -18,7 +18,7 @@ Three groups: alignment (`taller`, `nav`, and `shifted`, which has no band), the text diff (`nav`) and the 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`, `consent`, +- **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`. One per defence in `src/capture.ts` / `src/config.ts`. diff --git a/tests/fixtures/pages/lazy-grow/left.html b/tests/fixtures/pages/lazy-grow/left.html new file mode 100644 index 0000000..188c93c --- /dev/null +++ b/tests/fixtures/pages/lazy-grow/left.html @@ -0,0 +1,51 @@ + + + + +Layout parity + + + + +
+

Growing page guard rail

+

A section appended when the bottom scrolls into view, with four images more than four thousand pixels down, loaded by an IntersectionObserver on this side and directly on the other.

+ +
+
+
+ + +
+

Notes

+

Parity here means the capture followed the page down as it grew and every image it added was fetched and decoded before the shot.

+
+
+ + diff --git a/tests/fixtures/pages/lazy-grow/right.html b/tests/fixtures/pages/lazy-grow/right.html new file mode 100644 index 0000000..6650e8a --- /dev/null +++ b/tests/fixtures/pages/lazy-grow/right.html @@ -0,0 +1,34 @@ + + + + +Layout parity + + + + +
+

Growing page guard rail

+

A section appended when the bottom scrolls into view, with four images more than four thousand pixels down, loaded by an IntersectionObserver on this side and directly on the other.

+ +
+
+
+
+ +
+

Notes

+

Parity here means the capture followed the page down as it grew and every image it added was fetched and decoded before the shot.

+
+
+ + diff --git a/tests/helpers/corpus.ts b/tests/helpers/corpus.ts index 067da16..e4d3201 100644 --- a/tests/helpers/corpus.ts +++ b/tests/helpers/corpus.ts @@ -31,6 +31,7 @@ export const GUARDRAILS = [ "lazy", "lazy-deep", "lazy-js", + "lazy-grow", "consent", "drifting", "tracker", diff --git a/tests/visual/guardrails.test.ts b/tests/visual/guardrails.test.ts index 6104fcd..8d58194 100644 --- a/tests/visual/guardrails.test.ts +++ b/tests/visual/guardrails.test.ts @@ -218,7 +218,7 @@ describe("motion", () => { }); describe("lazy images", () => { - for (const route of ["/lazy-deep", "/lazy-js"]) { + for (const route of ["/lazy-deep", "/lazy-js", "/lazy-grow"]) { test(`${route}: images more than 4,000px below the fold load before the shot`, async () => { const run = await capture([route], { widths: [1440, 375] }); assert.equal(run.code, 0, context(run));