clawdie-ai/scripts/browser-jail-clone-validation/clone-smoke.mjs
Operator & Codex f8938285a7 Document browser clone validation findings
---
Build: pass | Tests: pass — 2382 passed (175 files)
2026-05-11 13:49:39 +02:00

24 lines
1.1 KiB
JavaScript

import { writeFile } from 'node:fs/promises';
import puppeteer from 'puppeteer-core';
const endpoint = process.env.CDP_ENDPOINT ?? 'http://127.0.0.1:9222';
const expected = process.env.VALIDATION_COOKIE ?? 'clawdie-validation-cookie';
const screenshotPath = process.env.SCREENSHOT_PATH ?? '/var/tmp/browser-clone-smoke.png';
const browser = await puppeteer.connect({ browserURL: endpoint });
const page = await browser.newPage();
const cookies = await page.cookies('https://example.com/');
const found = cookies.find((cookie) => cookie.name === 'clawdie_validation');
if (!found || found.value !== expected) {
await browser.disconnect();
throw new Error(`cookie missing or mismatched: ${JSON.stringify(cookies)}`);
}
await page.setViewport({ width: 800, height: 600 });
await page.goto('data:text/html,<html><body><h1>clone validation</h1><p>ok</p></body></html>');
const text = await page.$eval('h1', (el) => el.textContent);
const screenshot = await page.screenshot({ type: 'png' });
await writeFile(screenshotPath, screenshot);
await page.close();
await browser.disconnect();
console.log(JSON.stringify({ ok: true, text, cookie: found.value, screenshotPath }));