const { chromium } = require('playwright-core'); (async () => { const CHROME = String.raw`C:\Program Files\Google\Chrome\Application\chrome.exe`; const browser = await chromium.launch({ executablePath: CHROME, headless: true }); const page = await browser.newPage({ viewport: { width: 1280, height: 800 } }); const errs = []; page.on('pageerror', e => errs.push(e.message)); page.on('console', m => { if (m.type()==='error') errs.push(m.text()); }); // 1) Verify SEO meta tags on a normal page await page.goto('http://127.0.0.1:5175/login'); await page.waitForTimeout(2000); const desc = await page.locator('meta[name="description"]').getAttribute('content').catch(()=> ''); const ogTitle = await page.locator('meta[property="og:title"]').getAttribute('content').catch(()=> ''); const themeColor = await page.locator('meta[name="theme-color"]').getAttribute('content').catch(()=> ''); const noscript = await page.locator('noscript').count(); console.log('META description:', desc ? desc.slice(0,50)+'...' : 'MISSING'); console.log('META og:title:', ogTitle || 'MISSING'); console.log('META theme-color:', themeColor || 'MISSING'); console.log('noscript fallback:', noscript > 0 ? 'PRESENT' : 'MISSING'); // 2) Test shallow 404 (within AppLayout) await page.goto('http://127.0.0.1:5175/nonexistent-page'); await page.waitForTimeout(1500); const title404 = (await page.locator('.nf-title').textContent().catch(()=> '')) || ''; const code404 = (await page.locator('.nf-code').textContent().catch(()=> '')) || ''; console.log('\nSHALLOW 404 (/nonexistent-page):'); console.log(' nf-code:', code404.trim()); console.log(' nf-title:', title404.trim()); console.log(' has home btn:', await page.locator('.nf-btn.primary').count()); // 3) Test deep 404 await page.goto('http://127.0.0.1:5175/foo/bar/baz/deep'); await page.waitForTimeout(1500); const deepTitle = (await page.locator('.nf-title').textContent().catch(()=> '')) || ''; console.log('\nDEEP 404 (/foo/bar/baz/deep):'); console.log(' nf-title:', deepTitle.trim()); // 4) Test that clicking "返回首页" works await page.goto('http://127.0.0.1:5175/xyz'); await page.waitForTimeout(1500); await page.locator('.nf-btn.primary').click(); await page.waitForTimeout(1500); console.log('\nCLICK HOME -> url:', page.url()); console.log(' landed on home:', page.url().endsWith('/login') || page.url().endsWith('/5175/')); // 5) screenshot await page.goto('http://127.0.0.1:5175/nonexistent'); await page.waitForTimeout(1500); await page.screenshot({ path: '../audit_shots/_404_page.png' }); console.log('\nERRORS:', errs.length); if (errs.length) console.log('ERR_DETAIL:', [...new Set(errs)].slice(0,5)); await browser.close(); })();