import { chromium } from 'playwright'; const b = await chromium.launch(); for (const vp of [{ width: 390, height: 844 }, { width: 1280, height: 800 }]) { const ctx = await b.newContext({ viewport: vp }); const p = await ctx.newPage(); const samples = []; await p.goto('http://localhost:3299/', { waitUntil: 'commit' }).catch(() => {}); for (let i = 0; i < 60; i++) { const s = await p.evaluate(() => { const imgs = [...document.querySelectorAll('header a[aria-label="返回首页"] img')]; const vis = imgs.filter((im) => { const r = im.getBoundingClientRect(); return r.width > 0 && r.height > 0; }); return { t: Math.round(performance.now()), total: imgs.length, vis: vis.length, visCls: vis.map((im) => (im.getAttribute('class') || '').split(' ')[0]).join('|'), theme: document.documentElement.getAttribute('data-theme') ?? '-', firstVisibleBoxH: vis[0] ? Math.round(vis[0].getBoundingClientRect().height) : null, }; }).catch(() => null); if (s) samples.push(s); await p.waitForTimeout(60); } const multi = samples.filter((s) => s.vis > 1); const zero = samples.filter((s) => s.vis === 0); console.log(`viewport ${vp.width}x${vp.height}: 采样 ${samples.length} · 双可见 ${multi.length} · 零可见 ${zero.length} · 首次 data-theme=${samples.find((s) => s.theme !== '-')?.t ?? '未出现'}ms`); if (multi.length) console.log(' 双可见样本:', JSON.stringify(multi.slice(0, 3))); if (zero.length) console.log(' 零可见样本:', JSON.stringify(zero.slice(0, 3))); await ctx.close(); } await b.close();