#2140
`drag` presses on the wrong element when the target is far down the page
drag reports ✓ Done, but when the target is off-screen the mousedown lands on whatever sits where the source used to be, not on the source.
Repro
cat > drag.html <<'HTML'
<button id=src>source</button>
<div style="height:3000px"></div>
<div id=far style="width:80px;height:80px;background:red"></div>
<script>
window.ev = [];
['mousedown', 'mouseup'].forEach(t =>
addEventListener(t, e => ev.push(`${t} on ${e.target.id || e.target.tagName}`)));
</script>
HTML
agent-browser open "file://$PWD/drag.html"
agent-browser drag '#src' '#far'
agent-browser eval 'ev'
# ["mousedown on DIV", "mouseup on far"] expected "mousedown on src"Without the 3000px spacer the same drag works.
Cause
handle_drag (cli/src/native/actions.rs) looks up the source position, then looks up the target, which scrolls it into view, then presses at the source position it saved before the scroll.
Fix
Press on the source before scrolling to the target. #1073 already does this.
https://github.com/user-attachments/assets/fa3ed8f6-eb99-49ed-a95b-e65ba265854e
The
handle_dragimplementation incli/src/native/actions.rsneeds to re-fetch the source coordinates after the target scroll or perform the mousedown before triggering the viewport shift to prevent the coordinate mismatch.