Open History to see the last commit
1// Captures web stills of the seeded usage-limit evidence threads (see usage-limit-web-evidence-seed.ts).
2// node usage-limit-web-evidence-stills.mjs <pairingUrl> <outDir> <label> [rows]
3// Resolves playwright from apps/web. Every usage-limit failure shown is a SYNTHETIC fixture.
4import * as NodeModule from "node:module";
5import * as NodeFS from "node:fs";
6import * as NodePath from "node:path";
7
8const [pairingUrl, outDir, label, rowList = "W0,W1,W2,W7,W8"] = process.argv.slice(2);
9if (!pairingUrl || !outDir || !label)
10 throw new Error("usage: <pairingUrl> <outDir> <label> [rows]");
11const require = NodeModule.createRequire(
12 NodePath.resolve(import.meta.dirname, "../../web/package.json"),
13);
14const { chromium } = require("playwright");
15const rows = rowList.split(",");
16const variants = [
17 { width: 1440, height: 900, theme: "light" },
18 { width: 1440, height: 900, theme: "dark" },
19 { width: 390, height: 844, theme: "light" },
20 { width: 390, height: 844, theme: "dark" },
21];
22NodeFS.mkdirSync(outDir, { recursive: true });
23const browser = await chromium.launch();
24const origin = new URL(pairingUrl).origin;
25const pairContext = await browser.newContext({ viewport: { width: 1440, height: 900 } });
26const page = await pairContext.newPage();
27await page.goto(pairingUrl);
28await page.waitForURL((url) => !url.pathname.startsWith("/pair"), { timeout: 180_000 });
29const urls = {};
30for (const row of rows) {
31 const title = page.getByText(new RegExp(`^${row} `)).first();
32 await title.waitFor({ timeout: 60_000 });
33 await title.click();
34 await page.waitForURL((url) => url.pathname.includes(encodeURIComponent(`evidence:${row}`)), {
35 timeout: 60_000,
36 });
37 urls[row] = page.url();
38}
39const storageState = await pairContext.storageState();
40await pairContext.close();
41const env = { browser: `chromium ${browser.version()}`, node: process.version, origin, label };
42const shots = [];
43for (const variant of variants) {
44 const context = await browser.newContext({
45 viewport: { width: variant.width, height: variant.height },
46 colorScheme: variant.theme,
47 storageState,
48 });
49 const tab = await context.newPage();
50 for (const row of rows) {
51 await tab.goto(urls[row]);
52 await tab.waitForLoadState("networkidle").catch(() => {});
53 await tab.waitForTimeout(2500);
54 const file = NodePath.join(outDir, `${row}-${variant.width}-${variant.theme}-${label}.png`);
55 await tab.screenshot({ path: file });
56 shots.push({ row, ...variant, file, at: new Date().toISOString() });
57 }
58 await context.close();
59}
60NodeFS.writeFileSync(
61 NodePath.join(outDir, `shots-${label}.json`),
62 JSON.stringify({ env, urls, shots }, null, 2),
63);
64await browser.close();
65console.log(JSON.stringify({ env, count: shots.length }));