import { chromium, webkit } from 'playwright'; // A) 找出 SSR 阶段 opacity:0 的元素(首屏是否含 h1) const b1 = await chromium.launch(); const c1 = await b1.newContext({ viewport: { width: 1280, height: 900 }, javaScriptEnabled: false }); const p1 = await c1.newPage(); await p1.goto('https://www.novalon.cn/about', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(()=>{}); await p1.waitForTimeout(800); const hidden = await p1.evaluate(() => { const out = []; for (const el of document.querySelectorAll('main *')) { const cs = getComputedStyle(el); if (parseFloat(cs.opacity) === 0) { const r = el.getBoundingClientRect(); out.push({ tag: el.tagName, cls: (el.className||'').toString().slice(0,60), text: (el.innerText||'').slice(0,30), top: Math.round(r.top), h: Math.round(r.height) }); } } return out.slice(0, 24); }); console.log('SSR 隐藏元素:', JSON.stringify(hidden, null, 1)); await b1.close(); // B) WebKit 带 JS 渲染 const b2 = await webkit.launch(); const c2 = await b2.newContext({ viewport: { width: 1280, height: 900 } }); const p2 = await c2.newPage(); const errs = [], cerr = []; p2.on('pageerror', e => errs.push(String(e).slice(0,300))); p2.on('console', m => { if (m.type()==='error') cerr.push(m.text().slice(0,200)); }); const r = await p2.goto('https://www.novalon.cn/about', { waitUntil: 'networkidle', timeout: 60000 }).catch(e=>{console.log('GOTO', e.message);return null;}); await p2.waitForTimeout(2000); const info = await p2.evaluate(() => { const h1 = document.querySelector('h1'); const cs = h1 ? getComputedStyle(h1) : null; const r = h1?.getBoundingClientRect(); return { status: document.readyState, bodyTextLen: (document.body.innerText||'').trim().length, h1: h1?.innerText?.slice(0,20), h1opacity: cs?.opacity, h1visible: !!r && r.height>0 && parseFloat(cs?.opacity||'1')>0, hiddenCount: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length }; }); await p2.screenshot({ path: 'docs/acceptance/2026-10-20-prod-about/about-webkit.png', fullPage: true }); console.log('webkit status', r?.status(), JSON.stringify(info)); console.log('webkit pageerrors', JSON.stringify(errs), 'consoleErrors', JSON.stringify(cerr.slice(0,5))); await b2.close();