Why Your CDP Clicks Silently Fail: Smooth Scroll, Minimised Windows, and JS-Dispatched Events
说明与用途
通过 CDP 自动化的点击因平滑滚动、窗口隐藏和表单拒绝而无效。解决方案包括禁用平滑滚动、激活标签页以及通过 JS 发送事件。
问题
Automated CDP scripts report successful clicks but the page does not react, causing silent failures.
结果
After applying the three fixes—disabling smooth scroll, ensuring tab visibility, and detecting app-side rejections—the automated clicks reliably triggered UI changes.
工作流
- 1. Identify click helper using scrollIntoView and getBoundingClientRect.
- 2. Detect smooth scrolling causing stale rects; disable scroll-behavior and use instant scroll with a short wait before reading rect.
- 3. Detect window minimised state; use Page.bringToFront or dispatch mouse events via JS to bypass visibility restrictions.
- 4. Inject global event listeners to confirm whether click events reach the page; if not, diagnose causes 1 or 2.
- 5. If events reach page but no UI change, inspect app logic or form validation that rejects action.
- 6. Use document.elementFromPoint and querySelectorAll to debug element visibility and selector accuracy.
证据
Scroll into view, read the element's rectangle, click its centre. Correct — unless the page has scroll-behavior: smooth
CDP-synthesised mouse events at coordinates are unreliable when the target tab is not the active tab of a visible window
The form refuses a second voucher of that type. No field-level red text, no toast in the first 500 ms, the URL unchanged.
- 记录日期: 2026-10-23T06:26:07.241Z