Mike0021's picture
Enable browser HTTP commands with CORS-aware errors and bounded requests
39371ea verified
Raw History Blame Contribute Delete
1.39 kB
import { chromium } from 'playwright';
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
const browser = await chromium.launch({ executablePath: '/usr/bin/chromium', headless: true,
args: ['--disable-gpu', '--disable-software-rasterizer'] });
try {
const page = await browser.newPage();
const requests = []; page.on('request', request => requests.push(request.url()));
await page.goto('http://127.0.0.1:4173/');
await page.waitForFunction(() => window.browserPi); await page.evaluate(() => window.browserPi.ready);
await page.locator('#load').click();
await page.waitForFunction(() => document.querySelector('#notice').textContent.includes('WebGPU'));
assert.equal(await page.evaluate(() => window.browserPi.loaded), false);
await page.locator('#command').fill('echo shell-still-works'); await page.locator('#shell-run').click();
await page.waitForFunction(() => document.querySelector('#terminal-output').textContent.includes('[exit 0]'));
const message = await page.locator('#notice').textContent();
assert(!requests.some(url => url.includes('huggingface.co')));
await fs.writeFile('../validation/agent-browser-no-gpu.json', JSON.stringify({ passed: true, message, shellWorks: true, modelRequests: 0 }, null, 2));
console.log('Unavailable GPU: actionable error; shell works; no model download.');
} finally { await browser.close(); }