// Drive the in-browser proof cell in a real headless Chromium and capture the // signed cell it mints. Serves the crate dir over http (so the ES module + wasm // load under a normal origin), navigates to the harness page, waits for the // wasm to run prove(), and writes the resulting SignedProofCell JSON to stdout. import { createServer } from "node:http"; import { readFile } from "node:fs/promises"; import { extname, join, normalize } from "node:path"; import { chromium } from "playwright"; const ROOT = normalize(join(import.meta.dirname, "..")); const MIME = { ".html": "text/html", ".js": "text/javascript", ".mjs": "text/javascript", ".wasm": "application/wasm", ".json": "application/json", }; const server = createServer(async (req, res) => { try { const path = normalize(join(ROOT, decodeURIComponent(req.url.split("?")[0]))); if (!path.startsWith(ROOT)) { res.writeHead(403).end(); return; } const body = await readFile(path); res.writeHead(200, { "content-type": MIME[extname(path)] ?? "application/octet-stream" }); res.end(body); } catch { res.writeHead(404).end("not found"); } }); await new Promise((r) => server.listen(0, "127.0.0.1", r)); const port = server.address().port; const browser = await chromium.launch({ headless: true }); const version = browser.version(); const page = await browser.newPage(); page.on("console", (m) => process.stderr.write(`[page] ${m.text()}\n`)); page.on("pageerror", (e) => process.stderr.write(`[pageerror] ${e}\n`)); await page.goto(`http://127.0.0.1:${port}/browser/index.html`); const cell = await page.waitForFunction(() => window.__SANDBOX_CELL__, null, { timeout: 15000 }) .then((h) => h.jsonValue()); await browser.close(); server.close(); process.stderr.write(`engine: Chromium ${version}\n`); process.stdout.write(cell + "\n");