import { chromium } from 'playwright' import fs from 'node:fs/promises' import path from 'node:path' const origin = process.env.PLUGIN_BROWSER_ORIGIN || 'http://127.0.0.1:18081' const entry = `${origin}/extensions/qiu.subscription-admin/admin/` const outputDir = process.env.PLUGIN_SCREENSHOT_DIR || '.playwright-cli/subscription-admin' await fs.mkdir(path.resolve(outputDir), { recursive: true }) const launchOptions = { headless: true } if (process.env.PLAYWRIGHT_EXECUTABLE_PATH) launchOptions.executablePath = process.env.PLAYWRIGHT_EXECUTABLE_PATH const browser = await chromium.launch(launchOptions) try { for (const width of [425, 900, 1440]) { const page = await browser.newPage({ viewport: { width, height: 900 }, deviceScaleFactor: 1 }) const responseLeaks = [] page.on('response', async (response) => { if (!response.headers()['content-type']?.includes('application/json')) return try { const body = await response.text() if (/access_token|refresh_token|admin[_-]?api[_-]?key|password|client_secret/i.test(body)) responseLeaks.push(response.url()) } catch (_) {} }) await page.goto(entry, { waitUntil: 'domcontentloaded' }) await page.getByRole('heading', { name: '订阅管理已纳入统一控制面' }).waitFor() if (await page.locator('input[type="password"], form').count()) throw new Error('subscription module exposed an independent login form') await page.waitForTimeout(50) if (responseLeaks.length) throw new Error(`sensitive response field exposed at ${width}px: ${responseLeaks.join(', ')}`) await page.reload({ waitUntil: 'domcontentloaded' }) await page.getByRole('heading', { name: '订阅管理已纳入统一控制面' }).waitFor() const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth) if (overflow) throw new Error(`horizontal overflow at ${width}px`) await page.screenshot({ path: path.join(outputDir, `subscription-admin-${width}.png`), fullPage: true }) await page.close() } } finally { await browser.close() }