// 有头 Chrome 焦点守卫:唯一页面、禁止新建 / 切换标签页、后台建页兜底、前台状态检测。 // 规则见 docs/ui/GLOBAL_UI_BASELINE.md 第 7.1 节。 // Use this for static review captures, not for interaction/animation tests. export async function prepareStaticCapture(page) { await page.evaluate(async () => { await Promise.race([ Promise.all([ document.fonts.ready, ...[...document.images] .filter((image) => image.currentSrc && image.checkVisibility()) .map((image) => image.decode().catch(() => {})), ]), new Promise((_, reject) => setTimeout( () => reject( new Error( 'Static capture fonts/images did not settle within 10s', ), ), 10000, ), ), ]); }); } export const staticScreenshotOptions = { scale: 'css', animations: 'disabled', caret: 'hide', style: '*, *::before, *::after { animation: none !important; transition: none !important; caret-color: transparent !important; }', }; export async function captureStatic(page, options = {}) { await prepareStaticCapture(page); return page.screenshot({ ...options, ...staticScreenshotOptions }); }