Files
monkey-ai-web/scripts/browser-capture.mjs
zhanjunhao 2aa9d73325 chore(repo): 移除重复版权文件头并纳入共享单测
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
2026-11-20 11:23:49 +08:00

41 lines
1.2 KiB
JavaScript

// 有头 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 });
}