/** Opt-in live check of the Playwright sidecar. Not part of CI. */ import { BrowserClient } from '../browser-use/client.js'; const client = new BrowserClient({ timeoutMs: 45_000 }); const results = []; const check = (condition, message) => { if (!condition) throw new Error(message); }; async function step(name, fn) { await fn(); results.push(name); console.log('PASS ' + name); } try { await step('fetch example.com in Chromium', async () => { const page = await client.call('fetch', { url: 'https://example.com' }, 30_000); check(!page.error, page.error || 'fetch failed'); check(/example/i.test(String(page.text || page.title || '')), 'unexpected example.com body'); check(page.via === 'browser' || page.status, 'missing browser fetch metadata'); }); await step('search example domain', async () => { const hits = await client.call('search', { query: 'example domain', engine: 'duckduckgo', limit: 5 }, 30_000); check(!hits.error, hits.error || 'search failed'); check(Array.isArray(hits) && hits.length > 0, 'no search hits'); check(/^https?:/i.test(hits[0].url), 'search hit is not http(s)'); }); await step('snapshot the open tab', async () => { const shot = await client.call('snapshot', {}, 10_000); check(!shot.error, shot.error || 'snapshot failed'); check(Array.isArray(shot.refs), 'snapshot missing refs'); }); console.log('browser live smoke ok: ' + results.join(', ')); } catch (error) { console.error(error.message || error); console.error('Install Chromium with: npm install && npm run browser:install'); process.exitCode = 1; } finally { client.close(); }