import { chromium } from 'playwright-core' const BASE = 'http://localhost:5082' const browser = await chromium.launch({ headless: true, executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', }) const page = await browser.newPage({ viewport: { width: 1440, height: 900 }, deviceScaleFactor: 1 }) await page.addInitScript(() => { sessionStorage.setItem('fms-login', JSON.stringify({ loginInfo: { token: 'dev-token', user: { id: 1, name: 'dev', account: 'g3soft' } } })) localStorage.setItem('fms-user', JSON.stringify({ userInfo: { orgId: 'G3HD', account: 'g3soft' } })) }) await page.route('**/api/**', async (route) => { const req = route.request() const url = req.url() let body = {} try { body = req.postDataJSON() || {} } catch {} if (url.includes('/data/loaddata')) { const rows = body.view_name === 's_module' ? [{ b_id: 1, b_code: 'b_port', b_name: '港口管理' }] : body.view_name === 'bf_files_cateid' ? [{ b_id: '10', b_name: '合同文件' }] : [] return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: rows }) }) } if (url.includes('/data/page')) { const files = Array.from({ length: 4 }, (_, i) => ({ subid: String(1000 + i), father: '1001', mx_moduleid: '1', mx_cate_id: '10', mx_filename: `文件-${i + 1}.pdf`, mx_filesize: (i + 1) * 1024 * 1024, mx_fileext: 'pdf', mx_mapfilename: '', })) return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: { rows: files, total: files.length } }) }) } return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ code: 0, data: null }) }) }) await page.goto(`${BASE}/file-demo`, { waitUntil: 'networkidle', timeout: 30000 }) await page.waitForTimeout(2000) await page.locator('button:has-text("声明式弹窗")').click() await page.waitForTimeout(1500) const b64 = await page.screenshot({ encoding: 'base64' }) const analysis = await page.evaluate(async (b64) => { const bin = atob(b64) const bytes = new Uint8Array(bin.length) for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i) const blob = new Blob([bytes], { type: 'image/png' }) const bmp = await createImageBitmap(blob) const canvas = document.createElement('canvas') canvas.width = bmp.width canvas.height = bmp.height const ctx = canvas.getContext('2d') ctx.drawImage(bmp, 0, 0) const { width, height } = canvas const px = (x, y) => { const d = ctx.getImageData(x, y, 1, 1).data return `${d[0]},${d[1]},${d[2]}` } // For each x in the splitter region, count how many sample rows are the border-gray color // and report a compact "row" profile at several y positions const yPositions = [220, 300, 400, 500, 600, 700] const profile = [] for (let x = 370; x <= 930; x++) { const row = {} for (const y of yPositions) row[`y${y}`] = px(x, y) profile.push({ x, ...row }) } return { imgW: width, imgH: height, profile } }, b64) console.log(JSON.stringify(analysis, null, 2)) await browser.close()