Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
67 lines
2.8 KiB
JavaScript
67 lines
2.8 KiB
JavaScript
// Photographs the real Sabiá interface (served by `sabia ui`) with `/api/*` answered by
|
|
// mock-api.mjs. Called by scripts/screenshots.sh; env: BASE_URL, TOKEN, OUT, VERSION,
|
|
// CHROME, PUPPETEER_CORE.
|
|
import { mockFor, LAB_BSSID } from './mock-api.mjs';
|
|
|
|
const { BASE_URL, TOKEN, OUT, VERSION, CHROME, PUPPETEER_CORE } = process.env;
|
|
const puppeteer = (await import(PUPPETEER_CORE)).default;
|
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
|
|
const browser = await puppeteer.launch({ executablePath: CHROME, args: ['--no-sandbox'], defaultViewport: { width: 1600, height: 940, deviceScaleFactor: 1 } });
|
|
|
|
async function newPage(theme, lang) {
|
|
const page = await browser.newPage();
|
|
await page.evaluateOnNewDocument((t, l) => {
|
|
try {
|
|
localStorage.setItem('sabia-theme', t);
|
|
localStorage.setItem('sabia-lang', l);
|
|
localStorage.setItem('sabia-view', 'nets');
|
|
} catch { /* storage unavailable */ }
|
|
}, theme, lang);
|
|
await page.setRequestInterception(true);
|
|
page.on('request', (req) => {
|
|
const u = new URL(req.url());
|
|
if (!u.pathname.startsWith('/api/')) return req.continue();
|
|
const body = JSON.stringify(mockFor(req.method(), u.pathname, VERSION));
|
|
req.respond({ status: 200, contentType: 'application/json', body });
|
|
});
|
|
await page.goto(`${BASE_URL}/?token=${TOKEN}`, { waitUntil: 'networkidle0' });
|
|
await page.emulateMediaFeatures([{ name: 'prefers-color-scheme', value: theme }]);
|
|
return page;
|
|
}
|
|
|
|
async function startCapture(page) {
|
|
await page.click('#btnScan');
|
|
await page.waitForSelector('.net-row', { timeout: 15000 });
|
|
await sleep(1500);
|
|
}
|
|
|
|
for (const lang of ['pt', 'en']) {
|
|
for (const theme of ['dark', 'light']) {
|
|
const page = await newPage(theme, lang);
|
|
await startCapture(page);
|
|
await page.screenshot({ path: `${OUT}/networks-${theme}-${lang}.png` });
|
|
|
|
await page.click(`.ssid-btn[data-bssid="${LAB_BSSID}"]`);
|
|
await page.waitForSelector('#targetDlg[open]');
|
|
await page.click('#targetDlg .tabs [data-tab="attacks"]');
|
|
await sleep(600);
|
|
await page.click('#authChk');
|
|
await sleep(600);
|
|
await page.screenshot({ path: `${OUT}/attack-${theme}-${lang}.png` });
|
|
await page.close();
|
|
}
|
|
// Small dialog shot, light theme, as in the docs.
|
|
const page = await newPage('light', lang);
|
|
await startCapture(page);
|
|
await page.click('#settingsBtn');
|
|
await page.waitForSelector('#settingsDlg[open]');
|
|
await sleep(500);
|
|
const r = await page.$eval('#settingsDlg', (el) => { const b = el.getBoundingClientRect(); return { x: b.x, y: b.y, width: b.width, height: b.height }; });
|
|
const pad = 24;
|
|
await page.screenshot({ path: `${OUT}/settings-language-${lang}.png`, clip: { x: Math.round(r.x - pad), y: Math.round(r.y - pad), width: Math.floor(r.width + 2 * pad), height: Math.floor(r.height + 2 * pad) } });
|
|
await page.close();
|
|
}
|
|
await browser.close();
|
|
console.log('ok');
|