| 12345678910111213141516171819202122232425262728293031323334 |
- import { chromium } from "playwright";
- import fs from "node:fs";
- const b = await chromium.launch({ channel: "chrome", headless: true });
- const p = await b.newPage({
- viewport: { width: 1440, height: 1000 },
- deviceScaleFactor: 1,
- });
- await p.emulateMedia({ reducedMotion: "reduce" });
- const errors = [];
- p.on("pageerror", (e) => errors.push(e.message));
- await p.goto("http://localhost:5175", { waitUntil: "networkidle" });
- await p.evaluate(async () => {
- for (const i of document.images) {
- i.loading = "eager";
- }
- await Promise.all(
- [...document.images].map((i) => i.decode().catch(() => {})),
- );
- });
- await p.screenshot({ path: "/tmp/adu-desktop-loaded.png", fullPage: true });
- await p.screenshot({ path: "/tmp/adu-hero.png" });
- await p
- .locator(".new-arrivals")
- .screenshot({ path: "/tmp/adu-new-arrivals.png" });
- await p.setViewportSize({ width: 390, height: 844 });
- await p.evaluate(() => window.scrollTo({ top: 0, behavior: "instant" }));
- await p.screenshot({ path: "/tmp/adu-mobile-loaded.png", fullPage: true });
- await p.goto(
- "http://localhost:5175/product/the-original-salted-egg-cornflakes-clan",
- );
- await p.waitForTimeout(700);
- await p.screenshot({ path: "/tmp/adu-product-mobile.png", fullPage: true });
- console.log({ errors });
- await b.close();
|