import puppeteer from "puppeteer-core"; import { config } from "dotenv"; const TOK = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb2xsZWN0aW9uSWQiOiJwYmNfMzE0MjYzNTgyMyIsImV4cCI6MTc4NDAyNjY5MiwiaWQiOiI4bjdrNmE1NmVrMng5ZzEiLCJyZWZyZXNoYWJsZSI6dHJ1ZSwidHlwZSI6ImF1dGgifQ.yUEfTJ-hHbjz21QjERs-uoJSp8wR8oYsKG5k7vPLBPU"; async function getAppToken() { const res = await fetch("http://pocketbase-zinlbpsext2ro0lgb2558vfy.169.239.180.130.sslip.io/api/collections/users/auth-with-password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ identity: "david@rjbulk.local", password: "ChangeMe123!" }), }); const data = await res.json(); return data.token; } async function shoot(url, name, viewport = { width: 1280, height: 900 }, action) { const browser = await puppeteer.launch({ executablePath: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome", headless: "new", args: ["--no-sandbox", "--disable-gpu"], }); const page = await browser.newPage(); await page.setViewport(viewport); const token = await getAppToken(); await page.setCookie({ name: "pb_auth", value: token, domain: "localhost", path: "/" }); await page.goto(`http://localhost:4004${url}`, { waitUntil: "networkidle2" }); if (action) { await page.evaluate(action); await new Promise((r) => setTimeout(r, 600)); } await page.screenshot({ path: `/tmp/rjbulk-screens/${name}.png` }); await browser.close(); console.log(` ✓ ${name}.png`); } async function main() { // New delivery note form await shoot("/delivery-notes/new", "20-new-dn-form"); // Click the Auto-Number button await shoot("/delivery-notes/new", "21-new-dn-form-autonumber", { width: 1280, height: 900 }, () => { const btn = Array.from(document.querySelectorAll("button")).find((b) => b.textContent?.includes("Auto-Number")); if (btn) btn.click(); }); // Open the customer combobox await shoot("/delivery-notes/new", "22-new-dn-combobox-open", { width: 1280, height: 900 }, () => { const inp = document.querySelector("input[role=combobox]"); if (inp) inp.focus(); }); } main().catch((e) => { console.error(e); process.exit(1); });