probe-dom-diagnose3.mjs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /** 诊断 3:用 CDP 真鼠标事件点地图覆盖层标记(票 46 走查的进入路径)。 */
  2. import { cdpLaunch } from '../../../../cockpit-shell-panel-layout/verify/cdp-driver.mjs'
  3. const CHROME = process.env.CHROME_PATH || 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'
  4. const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
  5. const browser = await cdpLaunch({ executablePath: CHROME, headless: true, width: 1680, height: 950 })
  6. const page = await browser.newPage()
  7. await page.goto('http://127.0.0.1:8000/#/cockpit', { timeout: 60000 })
  8. await sleep(2000)
  9. await page.click('[data-cockpit-intro]').catch(() => {})
  10. await page.waitForFunction(() => ['ready', 'failed', 'disabled'].includes(document.querySelector('.cockpit-shell__map .map-canvas')?.dataset.mapEngine || ''), { timeout: 60000 })
  11. await sleep(5000)
  12. const box = await page.evaluate(() => {
  13. const node = document.querySelector('[data-marker-overlay-code="CBWS202610150001"]')
  14. if (!node) return null
  15. const inner = node.querySelector('svg') || node.firstElementChild || node
  16. const r = inner.getBoundingClientRect()
  17. const nr = node.getBoundingClientRect()
  18. return { nodeRect: { x: nr.x, y: nr.y, w: nr.width, h: nr.height }, innerTag: inner.tagName, rect: { x: r.x, y: r.y, w: r.width, h: r.height }, cx: r.x + r.width / 2, cy: r.y + r.height / 2, pe: getComputedStyle(node).pointerEvents }
  19. })
  20. console.log('box:', JSON.stringify(box))
  21. if (box && Number.isFinite(box.cx)) {
  22. const x = box.cx
  23. const y = box.cy
  24. await page._dispatchMouse('mouseMoved', x, y)
  25. await sleep(120)
  26. await page._dispatchMouse('mousePressed', x, y, { button: 'left', buttons: 1, clickCount: 1 })
  27. await sleep(60)
  28. await page._dispatchMouse('mouseReleased', x, y, { button: 'left', buttons: 0, clickCount: 1 })
  29. await sleep(3500)
  30. const card = await page.evaluate(() => {
  31. const c = document.querySelector('[data-point-detail]')
  32. return c ? { level: c.dataset.detailLevel, point: c.dataset.pointCode, kpis: [...c.querySelectorAll('[data-point-kpi]')].map((n) => `${n.dataset.pointKpi}=${n.querySelector('b')?.textContent?.trim()}`) } : null
  33. })
  34. console.log('after real-mouse click:', JSON.stringify(card))
  35. }
  36. await browser.close()