import { chromium, webkit, devices } from 'playwright'; const cases = [ ['chromium-mobile', chromium, { ...devices['iPhone 14'] }], ['webkit-mobile', webkit, { ...devices['iPhone 14'] }], ['webkit-reduced-motion', webkit, { viewport:{width:1280,height:900}, reducedMotion:'reduce' }], ['chromium-dark', chromium, { viewport:{width:1280,height:900}, colorScheme:'dark' }], ['chromium-3g', chromium, { viewport:{width:1280,height:900} }], ]; for (const [name, engine, opts] of cases) { const b = await engine.launch(); const ctx = await b.newContext(opts); const p = await ctx.newPage(); const errs = [], cerr = [], failed = []; p.on('pageerror', e => errs.push(String(e).slice(0,200))); p.on('console', m => { if (m.type()==='error') cerr.push(m.text().slice(0,160)); }); p.on('requestfailed', r => failed.push(`${r.failure()?.errorText} ${r.url().slice(0,90)}`)); if (name === 'chromium-3g') { const cdp = await ctx.newCDPSession(p); await cdp.send('Network.enable'); await cdp.send('Network.emulateNetworkConditions', { offline:false, latency:400, downloadThroughput: 200*1024, uploadThroughput: 100*1024 }); } const resp = await p.goto('https://www.novalon.cn/about', { waitUntil: 'networkidle', timeout: 90000 }).catch(e=>{console.log(name,'GOTO',e.message);return null;}); await p.waitForTimeout(2500); const info = await p.evaluate(() => { const h1 = document.querySelector('h1'); const cs = h1 ? getComputedStyle(h1) : null; const r = h1?.getBoundingClientRect(); return { bodyTextLen: (document.body.innerText||'').trim().length, h1visible: !!r && r.height>0 && parseFloat(cs?.opacity||'1')>0, h1opacity: cs?.opacity, hidden: [...document.querySelectorAll('main *')].filter(e=>parseFloat(getComputedStyle(e).opacity)===0).length, mainH: Math.round(document.querySelector('main')?.getBoundingClientRect().height ?? -1) }; }); console.log(name.padEnd(24), 'status', resp?.status(), JSON.stringify(info), 'errs', errs.length, 'cerr', cerr.length, 'failed', failed.length); if (errs.length) console.log(' pageerrors', JSON.stringify(errs.slice(0,2))); if (cerr.length) console.log(' console', JSON.stringify(cerr.slice(0,3))); await b.close(); }