Why Your CDP Clicks Silently Fail: Smooth Scroll, Minimised Windows, and JS-Dispatched Events
Originally published on my blog — read it there with the full context, code and updates . If you drive a web app with the Chrome DevTools Protocol, you have met this failure: your script reports clicked @591,361 , the element is there, the click landed — and nothing happens. No exception, no console error, no change on the page. I spent an evening on exactly this while automating a marketplace's…
When automating web applications using the Chrome DevTools Protocol, you may encounter silent failures where clicks appear to be registered, but nothing happens on the page. This issue can stem from three main causes: stale rectangles due to smooth scrolling, minimised windows causing coordinate clicks to be dropped, and the page rejecting the click event.
Cause 1 involves stale rectangles caused by smooth scrolling. When a page scrolls smoothly, the rect returned by getBoundingClientRect() may not reflect the element's actual position. Consequently, clicking the coordinates of the rect lands on whatever is underneath the element, resulting in a seemingly successful click with no visible change on the page. To fix this, scroll into view should be performed with behavior: instant, and the rect should be read after a brief wait to ensure the element's new position is captured.
Cause 2 is related to minimised windows, where clicks dispatched to a hidden or inactive tab may be dropped. In such cases, window.mouse events might not trigger the intended click behaviour. Two fixes are provided: bringing the tab to the front of its window using Page.bringToFront and using a JS-dispatched click event, which bypasses the window's visibility and works reliably, even in custom controls. However, note that event dispatching skips hit-testing, which could lead to unintended clicks on unreachable elements.
Cause 3 involves the page rejecting the click event after the click has been registered and executed. This can be a tricky issue to diagnose, as there would be no error message or console warning. To detect this problem, an event listener should be injected to track all clicks, and a comparison should be made between the recorded events and the actual application response.
If the event buffer is filled up but no action occurs in the application, it suggests the click was successful, but the app itself is rejecting it—possibly due to custom business logic or form validation rules.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.