Skip to content

Clone any website into a pixel-accurate Next.js app with AI — Playwright-measured extraction (no eyeballing), spec-gated parallel builder agents, and scored pixel-diff QA at phone/tablet/desktop. Works with Claude Code, Cursor, Copilot + 9 more.

perf(shots): crop section screenshots out of one full-page capture

Mahanaicoach96c09d90f2c3
diff --git a/scripts/extract/page.mjs b/scripts/extract/page.mjs
index 2a3c0ba..55e45c0 100644
--- a/scripts/extract/page.mjs
+++ b/scripts/extract/page.mjs
@@ -30,6 +30,7 @@ import {
gotoAndSettle,
autoScroll,
freezePage,
+ shootSectionsFromFullPage,
hostOf,
writeJson,
parseArgs,
@@ -163,17 +164,16 @@ if (doShots) {
jobs.push(
...Object.entries(loaded).map(async ([vp, { page }]) => {
await freezePage(page); // deterministic pixels — safe now, measuring is done
- await page.screenshot({ path: `${shotDir}/${pageSlug}-${vp}.png`, fullPage: true });
if (doSectionShots) {
- for (const s of sections) {
- const loc = page.locator(s.selector).first();
- try {
- await loc.scrollIntoViewIfNeeded({ timeout: 3000 });
- await loc.screenshot({ path: `${shotDir}/${s.name}-${vp}.png`, timeout: 5000 });
- } catch {
- console.error(` ! section shot failed: ${s.name} @ ${vp}`);
- }
- }
+ // One full-page capture yields the page shot AND every section crop —
+ // no per-section scroll+shoot chain.
+ const { failed } = await shootSectionsFromFullPage(page, sections, {
+ fullPagePath: `${shotDir}/${pageSlug}-${vp}.png`,
+ pathFor: (s) => `${shotDir}/${s.name}-${vp}.png`,
+ });
+ for (const name of failed) console.error(` ! section shot failed: ${name} @ ${vp}`);
+ } else {
+ await page.screenshot({ path: `${shotDir}/${pageSlug}-${vp}.png`, fullPage: true });
}
console.error(` ✓ screenshots @ ${vp}`);
})
diff --git a/scripts/extract/screenshot.mjs b/scripts/extract/screenshot.mjs
index 731cf10..3db3308 100644
--- a/scripts/extract/screenshot.mjs
+++ b/scripts/extract/screenshot.mjs
@@ -16,6 +16,7 @@ import {
gotoAndSettle,
autoScroll,
freezePage,
+ shootSectionsFromFullPage,
hostOf,
slugify,
parseArgs,
@@ -48,19 +49,14 @@ await forEachViewport(wanted, async (page, vp) => {
console.log(` ✓ ${path}`);
return;
}
- for (const { selector, name } of shots) {
- const path = `${outDir}/${name}-${vp}.png`;
- try {
- const loc = page.locator(selector).first();
- // Short timeouts: a bad selector should cost 3s and a warning, not
- // Playwright's default 30s before the rest of the sections get shot.
- await loc.scrollIntoViewIfNeeded({ timeout: 3000 });
- await loc.screenshot({ path, timeout: 5000 });
- console.log(` ✓ ${path}`);
- } catch (err) {
- // One bad selector must not kill the other sections' shots.
- console.warn(` ⚠ ${vp}: selector "${selector}" failed — ${String(err.message || err).split("\n")[0]}`);
- }
+ // One full-page capture, every section cropped from it — no per-section
+ // scroll+shoot chain, and one bad selector can't slow down the others.
+ const { failed } = await shootSectionsFromFullPage(page, shots, {
+ pathFor: (s) => `${outDir}/${s.name}-${vp}.png`,
+ });
+ for (const { name } of shots) {
+ if (failed.includes(name)) console.warn(` ⚠ ${vp}: section "${name}" failed`);
+ else console.log(` ✓ ${outDir}/${name}-${vp}.png`);
}
});