|
// Usage: REQ_FROM=<worktree>/apps/web/package.json node capture.mjs <label> <origin> <pairUrlFile> <outDir> <rows,comma> |
|
import { createRequire } from "node:module"; |
|
import { readFileSync } from "node:fs"; |
|
const { chromium } = createRequire(process.env.REQ_FROM)("playwright"); |
|
const [label, origin, pairFile, outDir, rowArg] = process.argv.slice(2); |
|
const rows = new Set(rowArg.split(",")); |
|
// Defaults to 1440 light. MATRIX=1 adds 390 and dark for local review only. |
|
const VIEWPORTS = [ |
|
{ name: "1440", width: 1440, height: 900 }, |
|
...(process.env.MATRIX === "1" ? [{ name: "390", width: 390, height: 844 }] : []), |
|
]; |
|
const THEMES = process.env.MATRIX === "1" ? ["light", "dark"] : ["light"]; |
|
|
|
const browser = await chromium.launch(); |
|
const context = await browser.newContext({ viewport: VIEWPORTS[0], deviceScaleFactor: 1, reducedMotion: "reduce" }); |
|
const page = await context.newPage(); |
|
await page.clock.setFixedTime(new Date("2026-10-26T12:00:00Z")); |
|
await page.goto(readFileSync(pairFile, "utf8").trim()); |
|
await page.waitForURL((u) => !u.pathname.startsWith("/pair"), { timeout: 30000 }); |
|
|
|
// The environment label is the host's computer name; replace it so no machine name is published. |
|
const mask = () => |
|
page.evaluate(() => { |
|
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); |
|
for (let n = walker.nextNode(); n; n = walker.nextNode()) { |
|
if (/Mac Studio/.test(n.nodeValue)) n.nodeValue = n.nodeValue.replace(/\S+[’']s Mac Studio/g, "this server"); |
|
} |
|
}); |
|
|
|
async function settle() { |
|
await page.waitForLoadState("networkidle").catch(() => {}); |
|
await page.evaluate(() => document.fonts.ready); |
|
for (let i = 0; i < 20; i++) { |
|
await mask(); |
|
const a = await page.screenshot(); |
|
await page.waitForTimeout(500); |
|
await mask(); |
|
const b = await page.screenshot(); |
|
if (a.equals(b)) return b; |
|
} |
|
throw new Error("frame never settled"); |
|
} |
|
|
|
async function each(name, prepare) { |
|
for (const vp of VIEWPORTS) { |
|
for (const theme of THEMES) { |
|
await page.setViewportSize({ width: vp.width, height: vp.height }); |
|
await page.emulateMedia({ colorScheme: theme, reducedMotion: "reduce" }); |
|
await prepare(); |
|
const buf = await settle(); |
|
const file = `${outDir}/${label}-${name}-${vp.name}-${theme}.png`; |
|
(await import("node:fs")).writeFileSync(file, buf); |
|
console.log(file); |
|
} |
|
} |
|
} |
|
|
|
const go = async (path) => { |
|
await page.goto(`${origin}${path}`); |
|
await page.getByText("Settings", { exact: true }).first().waitFor(); |
|
}; |
|
const closeDialogs = async () => { |
|
while (await page.getByRole("dialog").or(page.getByRole("alertdialog")).count()) { |
|
await page.keyboard.press("Escape"); |
|
await page.waitForTimeout(300); |
|
} |
|
}; |
|
const listed = () => page.getByRole("button", { name: "Toggle account visibility" }); |
|
const emptyState = () => page.getByText("No secret providers configured."); |
|
|
|
async function removeAll() { |
|
await go("/settings/secrets"); |
|
await listed().or(emptyState()).first().waitFor(); |
|
while (await page.getByRole("button", { name: "Remove", exact: true }).count()) { |
|
await page.getByRole("button", { name: "Remove", exact: true }).first().click(); |
|
await page.getByRole("button", { name: "Remove provider" }).click(); |
|
await page.waitForTimeout(500); |
|
} |
|
await emptyState().waitFor(); |
|
} |
|
async function addProvider(name, account) { |
|
await page.getByRole("button", { name: "Add provider" }).first().click(); |
|
await page.getByRole("textbox", { name: "Name" }).fill(name); |
|
await page.getByRole("textbox", { name: "Account" }).fill(account); |
|
await page.getByRole("dialog").getByRole("button", { name: "Add provider" }).click(); |
|
await page.getByText(name, { exact: true }).waitFor(); |
|
await go("/settings/secrets"); |
|
} |
|
|
|
if (rows.has("general")) await each("general", () => go("/settings/general")); |
|
if (rows.has("secrets-url")) await each("secrets-url", async () => { await page.goto(`${origin}/settings/secrets`); await page.waitForTimeout(1500); }); |
|
if (rows.has("search")) { |
|
await each("search", async () => { |
|
await go("/settings/general"); |
|
const input = page.getByRole("combobox", { name: "Search settings" }); |
|
if (!(await input.isVisible())) await page.getByRole("button", { name: "Search settings" }).click(); |
|
await input.fill("secret"); |
|
await page.waitForTimeout(300); |
|
}); |
|
} |
|
if (rows.has("empty")) { |
|
await removeAll(); |
|
await each("empty", async () => { await go("/settings/secrets"); await emptyState().waitFor(); }); |
|
} |
|
if (rows.has("add")) { |
|
await each("add", async () => { |
|
await go("/settings/secrets"); |
|
await emptyState().waitFor(); |
|
await page.getByRole("button", { name: "Add provider" }).first().click(); |
|
await page.getByRole("textbox", { name: "Name" }).fill("Personal"); |
|
await page.getByRole("textbox", { name: "Account" }).fill("my.1password.com"); |
|
}); |
|
} |
|
if (rows.has("add-invalid")) { |
|
await each("add-invalid", async () => { |
|
await go("/settings/secrets"); |
|
await page.getByRole("button", { name: "Add provider" }).first().click(); |
|
await page.getByRole("textbox", { name: "Account" }).fill("-bad"); |
|
await page.getByRole("dialog").getByRole("button", { name: "Add provider" }).click(); |
|
await page.getByRole("alert").first().waitFor(); |
|
}); |
|
} |
|
if (rows.has("list")) { |
|
await page.setViewportSize({ width: 1440, height: 900 }); |
|
await go("/settings/secrets"); |
|
await addProvider("Personal", "my.1password.com"); |
|
await addProvider("Work", "acme.1password.com"); |
|
await each("list", async () => { await go("/settings/secrets"); await page.getByText("Work", { exact: true }).waitFor(); }); |
|
} |
|
if (rows.has("list-revealed")) { |
|
await each("list-revealed", async () => { |
|
await go("/settings/secrets"); |
|
await listed().first().click(); |
|
await page.mouse.move(0, 0); |
|
await page.evaluate(() => document.activeElement?.blur()); |
|
await page.getByText("my.1password.com").waitFor(); |
|
await page.waitForTimeout(400); |
|
}); |
|
} |
|
if (rows.has("edit")) { |
|
await each("edit", async () => { |
|
await go("/settings/secrets"); |
|
await page.getByRole("button", { name: "Edit", exact: true }).first().click(); |
|
await page.getByRole("dialog").waitFor(); |
|
}); |
|
} |
|
if (rows.has("remove")) { |
|
await each("remove", async () => { |
|
await go("/settings/secrets"); |
|
await page.getByRole("button", { name: "Remove", exact: true }).first().click(); |
|
await page.getByRole("button", { name: "Remove provider" }).waitFor(); |
|
}); |
|
} |
|
await browser.close(); |