txw/tmp-snap2.mjs
2026-06-05 12:54:11 +08:00

43 lines
1.5 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.

import { chromium } from 'playwright';
const BASE = 'http://localhost:9027';
(async () => {
const browser = await chromium.launch();
const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 } });
const page = await ctx.newPage();
// 直接访问 gxnlpt?anchor=content-1不要先访问 home看看非 keep-alive 场景是否正常
await page.goto(`${BASE}/view/mhzc/gxnlpt?anchor=content-1`, { waitUntil: 'networkidle', timeout: 30000 });
await page.waitForSelector('.gxnlpt-page', { timeout: 20000 });
await page.waitForTimeout(3500);
await page.screenshot({ path: 'tmp-direct-1.png', fullPage: false });
// 滚动到顶部
await page.evaluate(() => {
const w = document.querySelector('.content-wrap');
if (w) w.scrollTop = 0;
});
await page.waitForTimeout(500);
await page.screenshot({ path: 'tmp-direct-2.png', fullPage: false });
// 在视口顶部 evaluate 一下
const data = await page.evaluate(() => {
const outlet = document.querySelector('.portal-route-outlet');
const child = outlet && outlet.firstElementChild;
return {
outletChildCount: outlet ? outlet.children.length : 0,
childClass: child && child.className,
contentWrapScrollTop: document.querySelector('.content-wrap').scrollTop,
url: location.href,
};
});
console.log('data:', JSON.stringify(data));
await browser.close();
})().catch((e) => {
console.error('TEST ERROR', e);
process.exit(1);
});