Files
novalon-website/docs/acceptance/2026-10-20-home-multiplatform/probe-multiplatform.mjs
T
zhangxiang ba05b2e57b docs(acceptance): 首页改版生产发布记录与线上多端验收
- 记录 acb6b673 发布、镜像/备份锚点与 14 路由 200
- 补线上多端探针 report-production 与 prod 截图
- 探针先 eager 加载再滚屏,避免把懒加载未触发误报成破图
2026-10-20 11:24:16 +08:00

189 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 2026-10-20 首页多端复核探针
//
// 用途:在**生产 standalone** 服务上,按 9 个宽度档 + 浅/深主题 + chromium/firefox/webkit
// 检查:无横向溢出、图片全加载、页面淡入已落地(祖先链有效 opacity=1)、原始文案在场且无新增文案泄漏、
// 移动端底部 tab bar 在场;并在 1440 / 390 两个代表档跑 axe-core(wcag2a/2aa/21a/21aa)。
//
// 启动服务:
// npm run build
// PORT=3100 HOSTNAME=127.0.0.1 node dist/standalone/server.js
// 运行:
// BASE=http://127.0.0.1:3100/ OUT=/tmp/home-multiplatform node probe-multiplatform.mjs
//
// 判据不是「截图看起来对」:每条运行都要求 pageOpacity ≥ 0.99;否则整页半透明会把 axe
// 误读成 100+ 条对比度违规(本轮实际踩到过,见 docs/lessons-learned.md §5.49)。
import { chromium, firefox, webkit } from 'playwright';
import fs from 'fs';
import path from 'path';
const OUT = process.env.OUT || '/tmp/home-multiplatform';
fs.mkdirSync(OUT, { recursive: true });
const axeSrc = fs.readFileSync('node_modules/axe-core/axe.min.js', 'utf8');
const BASE = process.env.BASE || 'http://127.0.0.1:3100/';
const viewports = [
{ name: 'desktop-1920', width: 1920, height: 1080, mobile: false },
{ name: 'desktop-1440', width: 1440, height: 900, mobile: false },
{ name: 'laptop-1280', width: 1280, height: 800, mobile: false },
{ name: 'tablet-1024', width: 1024, height: 768, mobile: false },
{ name: 'tablet-834', width: 834, height: 1194, mobile: false },
{ name: 'mobile-430', width: 430, height: 932, mobile: true },
{ name: 'mobile-390', width: 390, height: 844, mobile: true },
{ name: 'mobile-375', width: 375, height: 667, mobile: true },
{ name: 'mobile-320', width: 320, height: 568, mobile: true },
];
const results = [];
async function settle(page) {
await page.addInitScript(() => {
localStorage.setItem('novalon-cookie-preferences', JSON.stringify({
necessary: true, analytics: false, marketing: false, functionality: true, timestamp: 1784284000000,
}));
});
await page.goto(BASE, { waitUntil: 'domcontentloaded', timeout: 45000 });
await page.waitForSelector('[data-testid="hero-section"]', { state: 'attached', timeout: 20000 });
await page.waitForLoadState('load').catch(() => {});
// PageTransition 是 hydration 后才挂上的 0.28s 淡入;若在 0.15~0.5 的不透明度上截图/跑 axe,
// 会把「整页半透明」误读成 100+ 个对比度违规。先等这一层退场或归 1。
await page.waitForFunction(() => {
const wrappers = [...document.querySelectorAll('main div')].filter(el => {
const r = el.getBoundingClientRect();
return r.height > 2000 && (el.getAttribute('style') || '').includes('opacity');
});
return wrappers.every(el => parseFloat(getComputedStyle(el).opacity) > 0.99);
}, { timeout: 12000 }).catch(() => {});
// 线上 CDN 的懒加载图在「快速滚到底再回顶」时不会全部触发;先把 loading 改 eager,
// 再等首页图全部 complete。否则会把「还没轮到加载」误报成破图。
await page.evaluate(() => document.querySelectorAll('img').forEach((i) => { i.loading = 'eager'; }));
await page.evaluate(async () => {
for (let y = 0; y < document.body.scrollHeight; y += 500) {
window.scrollTo(0, y);
await new Promise(r => setTimeout(r, 150));
}
window.scrollTo(0, 0);
});
await page.waitForFunction(() => {
const imgs = [...document.querySelectorAll('img')].filter((i) => i.src.includes('/images/home/') || i.src.includes('/logo'));
return imgs.every((i) => i.complete && i.naturalWidth > 0);
}, { timeout: 20000 }).catch(() => {});
await page.waitForTimeout(300);
await page.evaluate(() => document.fonts?.ready);
await page.evaluate(() => document.querySelectorAll('img').forEach(i => { if (!i.complete) i.loading = 'eager'; }));
await page.waitForTimeout(800);
}
async function probe(browser, vp, theme) {
const isChromium = browser.browserType().name() === 'chromium';
const context = await browser.newContext({
viewport: { width: vp.width, height: vp.height },
...(isChromium ? { isMobile: vp.mobile, hasTouch: vp.mobile, deviceScaleFactor: vp.mobile ? 2 : 1 } : {}),
reducedMotion: 'reduce',
colorScheme: theme === 'dark' ? 'dark' : 'light',
});
const page = await context.newPage();
const consoleErrors = [];
page.on('console', m => { if (m.type() === 'error') consoleErrors.push(m.text().slice(0, 200)); });
page.on('pageerror', e => consoleErrors.push('PAGEERROR: ' + String(e).slice(0, 200)));
await settle(page);
if (theme === 'dark') {
await page.evaluate(() => document.documentElement.setAttribute('data-theme', 'dark'));
await page.waitForTimeout(300);
}
const data = await page.evaluate(() => {
const visible = (el) => {
if (!el) return false;
const r = el.getBoundingClientRect();
const s = getComputedStyle(el);
return r.width > 0 && r.height > 0 && s.display !== 'none' && s.visibility !== 'hidden' && s.opacity !== '0';
};
const headerLogo = [...document.querySelectorAll('header img[alt="四川睿新致远科技有限公司"]')].find(visible);
const headerLogoRect = headerLogo?.getBoundingClientRect();
const hero = document.querySelector('[data-testid="hero-section"]');
const h1 = hero?.querySelector('h1');
const heroRect = hero?.getBoundingClientRect();
const sections = ['home-ledger','home-insights','home-industries','home-capabilities','home-cta'].map(id => {
const el = document.querySelector(`[data-testid="${id}"]`);
return { id, present: !!el, top: el ? Math.round(el.getBoundingClientRect().top + window.scrollY) : null };
});
const imgs = [...document.querySelectorAll('[data-testid="hero-section"] img, [data-testid="home-insights"] img, [data-testid="home-industries"] img, [data-testid="home-capabilities"] img, [data-testid="home-cta"] img')]
.map(i => ({ src: (i.currentSrc || i.src).split('/').pop(), nw: i.naturalWidth, complete: i.complete }));
const pageWrapper = [...document.querySelectorAll('main div')].find(el => {
const r = el.getBoundingClientRect();
return r.height > 2000 && (el.getAttribute('style') || '').includes('opacity');
});
const bodyText = document.body.innerText;
const newCopy = ['新闻和最新趋势','我们的行业专长','我们为何能够打动客户','准备好聊聊了吗','NOVALON CONSULTING','Field notes','Strategy · Delivery','从诊断到交接','四阶段交付方法论','全部行业','阅读全文','Our method','MANUFACTURING','RETAIL & TRADE'];
return {
pageOpacity: pageWrapper ? parseFloat(getComputedStyle(pageWrapper).opacity) : 1,
innerWidth: window.innerWidth,
scrollWidth: document.documentElement.scrollWidth,
bodyScrollWidth: document.body.scrollWidth,
overflowX: document.documentElement.scrollWidth > window.innerWidth + 1,
headerLogo: headerLogoRect ? { w: Math.round(headerLogoRect.width), h: Math.round(headerLogoRect.height), visible: true } : { visible: false },
hero: heroRect ? { top: Math.round(heroRect.top + window.scrollY), h: Math.round(heroRect.height), h1: h1?.innerText?.trim() ?? null } : null,
h1Visible: visible(h1),
sections,
sectionOrder: sections.filter(s => s.present).map(s => s.id),
imgs,
brokenImgs: imgs.filter(i => !i.complete || i.nw === 0),
copy: {
hasOriginal: ['我们怎么判断、怎么交付','按行业的问题空间,不是按我们的产品线','四种陪跑方式','现在有什么卡住你了?'].every(t => bodyText.includes(t)),
leakedNewCopy: newCopy.filter(t => bodyText.includes(t)),
},
cookieBannerVisible: visible(document.querySelector('[data-testid="cookie-consent-banner"]')) || /\u63a5\u53d7\u6240\u6709/.test(bodyText),
mobileNavVisible: !!document.querySelector('[data-testid="mobile-tab-bar"]') && visible(document.querySelector('[data-testid="mobile-tab-bar"]')),
};
});
// axe(只跑 1440 / 390 两个代表档,浅/深各一次)
if ((vp.width === 1440 || vp.width === 390) && (theme === 'light' || theme === 'dark')) {
await page.addScriptTag({ content: axeSrc });
const axe = await page.evaluate(async () => await window.axe.run(document, {
runOnly: { type: 'tag', values: ['wcag2a','wcag2aa','wcag21a','wcag21aa'] },
}));
data.axe = {
violations: axe.violations.map(v => ({ id: v.id, impact: v.impact, nodes: v.nodes.length })),
incomplete: axe.incomplete.map(v => ({ id: v.id, nodes: v.nodes.length })),
};
}
data.consoleErrors = consoleErrors;
const tag = `${vp.name}-${theme}`;
await page.screenshot({ path: path.join(OUT, `${tag}-hero.png`), fullPage: false });
await page.screenshot({ path: path.join(OUT, `${tag}-full.png`), fullPage: true });
results.push({ tag, browser: browser.browserType().name(), ...data });
await context.close();
}
const browsers = { chromium: await chromium.launch(), firefox: await firefox.launch(), webkit: await webkit.launch() };
// 宽度档用 chromium 全跑;firefox / webkit 各跑 1440 与 390 两个代表档
for (const vp of viewports) await probe(browsers.chromium, vp, 'light');
for (const vp of [viewports[1], viewports[6]]) {
await probe(browsers.chromium, vp, 'dark');
await probe(browsers.firefox, vp, 'light');
await probe(browsers.webkit, vp, 'light');
}
await browsers.chromium.close(); await browsers.firefox.close(); await browsers.webkit.close();
fs.writeFileSync(path.join(OUT, 'report.json'), JSON.stringify(results, null, 2));
console.log(JSON.stringify(results.map(r => ({
tag: r.tag,
browser: r.browser,
pageOpacity: r.pageOpacity,
innerWidth: r.innerWidth,
scrollWidth: r.scrollWidth,
overflowX: r.overflowX,
logo: r.headerLogo,
h1: r.hero?.h1,
h1Visible: r.h1Visible,
heroH: r.hero?.h,
sectionOrder: r.sectionOrder,
broken: r.brokenImgs.length,
copy: r.copy,
cookie: r.cookieBannerVisible,
mobileNav: r.mobileNavVisible,
axe: r.axe,
consoleErrors: r.consoleErrors.length,
})), null, 2));