// 定位 pageerror 来源 const { chromium } = require('playwright') async function main() { const browser = await chromium.launch() const page = await browser.newPage({ viewport: { width: 1440, height: 900 } }) page.on('console', (m) => { if (m.type() === 'error') console.log('CONSOLE ERR @', page.url(), '→', m.text().slice(0, 200)) }) page.on('pageerror', (e) => console.log('PAGE ERR @', page.url(), '→', e.stack?.split('\n').slice(0, 3).join(' | '))) const uname = 'dbg' + Date.now().toString().slice(-6) await page.goto('http://localhost:5173/register', { waitUntil: 'networkidle' }) await page.fill('input[autocomplete="username"]', uname) await page.fill('input[autocomplete="email"]', uname + '@test.com') await page.fill('input[autocomplete="new-password"]', 'password123') await page.locator('input[autocomplete="new-password"]').nth(1).fill('password123') await page.click('button[type="submit"]') await page.waitForURL('**/console/dashboard', { timeout: 10000 }) await page.waitForTimeout(2500) console.log('URL now:', page.url()) // 检查页面内容 const cards = await page.locator('.mt-6.grid .rounded-lg').count() const chart = await page.locator('canvas').count() const empty = await page.locator('text=暂无数据').count() console.log('cards:', cards, 'canvas:', chart, 'emptyState:', empty) const bodyText = (await page.locator('body').innerText()).slice(0, 300) console.log('body:', bodyText.replace(/\n+/g, ' | ')) await browser.close() } main().catch((e) => { console.error(e); process.exit(1) })