// Captures Playwright de la fiche logement à 6 largeurs (QA visuelle). // Usage : node frontend/scripts/shots.mjs [uid] [baseUrl] [outDir] import { chromium, devices } from "playwright"; const UID = process.argv[2] || "zumper:60608306"; const BASE = process.argv[3] || "http://127.0.0.1:8095"; const OUT = process.argv[4] || "/tmp"; const shots = [ ["iphone14", { ...devices["iPhone 14"] }], ["w375", { viewport: { width: 375, height: 812 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }], ["w430", { viewport: { width: 430, height: 932 }, deviceScaleFactor: 2, isMobile: true, hasTouch: true }], ["w768", { viewport: { width: 768, height: 1024 }, deviceScaleFactor: 1 }], ["w1024", { viewport: { width: 1024, height: 800 }, deviceScaleFactor: 1 }], ["w1440", { viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 }], ]; const browser = await chromium.launch(); for (const [name, opts] of shots) { const ctx = await browser.newContext(opts); const page = await ctx.newPage(); const errs = []; page.on("pageerror", (e) => errs.push("PAGEERROR " + e.message)); page.on("console", (m) => { if (m.type() === "error") errs.push(m.text().slice(0, 200)); }); await page.goto(`${BASE}/logement/${encodeURIComponent(UID)}`, { waitUntil: "networkidle" }); await page.waitForSelector(".lk-hero", { timeout: 20000 }); // défilement complet (déclenche les chargements différés) puis retour en haut await page.evaluate(async () => { for (let y = 0; y < document.body.scrollHeight; y += 600) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 120)); } window.scrollTo(0, 0); }); await page.waitForTimeout(3500); const ov = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth); await page.screenshot({ path: `${OUT}/lk-${name}-full.png`, fullPage: true }); await page.screenshot({ path: `${OUT}/lk-${name}-top.png` }); await page.evaluate(() => window.scrollTo(0, 900)); await page.waitForTimeout(600); await page.screenshot({ path: `${OUT}/lk-${name}-scrolled.png` }); console.log(name, "overflow", ov, "errors", errs.length, errs.slice(0, 3).join(" | ")); await ctx.close(); } await browser.close();