Snapshot refs survive a click-triggered navigation and the next `click @ref` is a silent no-op

Author: dwin-gharibiCreated Sep 18, 2026Updated Sep 28, 2026

Summary

A snapshot ref stays resolvable after a click navigates the page away. Clicking such a ref on the new document does nothing at all, yet the command prints ✓ Done and exits 0. Explicit navigation already invalidates refs; a navigation the daemon did not initiate does not.

Severity

High.

Affected version

Found on agent-browser 0.37.1 (shipped npm binary, Chrome on Linux). The code path is unchanged in v0.38.0 / cd063d1.

Steps to reproduce

bash
agent-browser open file:///tmp/v1.html
agent-browser snapshot                      # button "Delete" [ref=e7]
agent-browser find text "Go Second" click   # navigates to v2.html
agent-browser click @e7; echo "exit=$?"
agent-browser get text '#log'               # empty
agent-browser click '#danger2'              # this one does register
agent-browser get text '#log'

Actual behaviour

click @e7 prints ✓ Done and exits 0, but the page log stays empty: nothing was clicked. A CSS-selector click such as click '#danger2' on the same page does register, which shows the page itself is live and only the ref is stale.

Expected behaviour

A navigation caused by a click invalidates the refs issued for the previous document, exactly as an explicit open or goto already does, so click @e7 fails with a stale-ref error instead of reporting success.

Root cause

cli/src/native/actions.rs:1775, the Page.frameNavigated arm of the CDP event loop. When the main frame navigates (frame.get("parentId").is_none()) the handler clears WebMCP page scope and updates frame origins, but it never touches self.ref_map. Ref invalidation lived only on the explicit navigation commands, which call into RefMap in cli/src/native/element.rs. A click that causes a navigation reaches the daemon only as this event, so the old document's refs are left in the map. The ref then resolves to a backend node id belonging to a document that no longer exists, the CDP call targeting it is a no-op, and the command reports success because nothing raised an error.

Impact

An AI agent that snapshots once and then acts on refs will, after any click that navigates, issue clicks that do nothing while every one of them reports success. The agent believes it deleted the record, accepted the dialog or submitted the form, and keeps building on that false state. Worse, the refs may point at elements whose labels described the previous page, so the agent's own reasoning about what it clicked is wrong too.

Source: vercel-labs/agent-browser