d878f0db21
统一设备配置和浏览器启动入口,加入窗口焦点守卫,并按运行隔离报告和追踪文件。
60 lines
2.0 KiB
JavaScript
60 lines
2.0 KiB
JavaScript
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
// 有头 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 });
|
|
}
|