Skip to content

feat(dashboard): live annotation toggle in viewport toolbar#1374

Open
techcomthanh wants to merge 2 commits into
vercel-labs:mainfrom
techcomthanh:feat/dashboard-annotate-toggle
Open

feat(dashboard): live annotation toggle in viewport toolbar#1374
techcomthanh wants to merge 2 commits into
vercel-labs:mainfrom
techcomthanh:feat/dashboard-annotate-toggle

Conversation

@techcomthanh
Copy link
Copy Markdown

Summary

Adds a # toggle in the dashboard viewport toolbar (left of the snapshot icon) that injects the same numbered red boxes used by screenshot --annotate onto the live page, so element refs are visible in the streaming viewport without taking a screenshot.

Motivation: when picking elements interactively from the dashboard, --annotate only labels stills. The labels disappear the moment streaming continues, which is awkward for human-in-the-loop selection. This toggle reuses the existing overlay injector so labels stay on screen while the user identifies the target, then can be removed in one click.

CLI equivalent (also new):

agent-browser --session <name> annotate-overlay on
agent-browser --session <name> annotate-overlay off

The numbers shown on the live overlay match @eN from snapshot -i — the action takes a fresh snapshot on enable so the ref map is current.

Changes

Rust (cli/)

  • native/screenshot.rs: extract a public set_live_annotation(client, session_id, ref_map, on) that reuses the existing inject_annotation_overlay / remove_annotation_overlay helpers (no new injection code).
  • native/actions.rs: new annotate_overlay action. On enable, clears + refills the ref map via snapshot::take_snapshot so overlay numbers match the current DOM.
  • commands.rs: new annotate-overlay on|off CLI verb.

Dashboard (packages/dashboard/)

  • components/viewport.tsx: new Hash icon toggle button placed left of the snapshot button; local annotateOn state; calls runCmd(\"annotate-overlay\", on?\"on\":\"off\"). A 300ms-debounced useEffect on url re-applies the overlay after navigation so labels track the new DOM.

Test plan

  • cargo build --release --manifest-path cli/Cargo.toml — clean build.
  • pnpm --filter dashboard build — clean build.
  • Smoke: agent-browser open https://example.comannotate-overlay on → DOM contains #__agent_browser_annotations__ overlay; viewer shows numbered boxes. off removes them. Verified via agent-browser eval post-toggle.
  • Dashboard button reflects state (background tint when active) and tooltip flips between "Show/Hide element labels".
  • Multi-tab / iframe sanity (not exercised).
  • WebDriver backend (current implementation is Chrome-CDP only, matches screenshot --annotate).

Notes / Open questions

  • Auto-refresh after navigation is heuristic (300ms setTimeout on url change). SPA route changes that don't update activeUrlAtom won't trigger it; users re-click the toggle. A CDP Page.frameNavigated hook on the server side would be more robust — happy to follow up if preferred.
  • Icon choice (Hash from lucide-react) is a guess; open to alternatives.

Adds a `#` toggle button to the viewport toolbar (left of the snapshot
icon) that injects the same numbered red boxes used by
`screenshot --annotate` onto the live page, so element refs are visible
in the streaming viewport without taking a screenshot.

CLI equivalent:
  agent-browser --session <name> annotate-overlay on
  agent-browser --session <name> annotate-overlay off

Numbers shown on the live overlay match `@eN` from `snapshot -i`.

Rust side:
- screenshot.rs: extract a public `set_live_annotation` that reuses the
  existing `inject_annotation_overlay` / `remove_annotation_overlay`
  helpers.
- actions.rs: new `annotate_overlay` action handler. On enable it
  refreshes the ref map via a fresh snapshot so overlay numbers match
  the current DOM.
- commands.rs: new `annotate-overlay on|off` CLI verb.

Dashboard side:
- viewport.tsx: new toolbar toggle button (lucide `Hash`) with a local
  `annotateOn` state; auto re-applies the overlay 300ms after URL
  changes so labels track navigation.
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 18, 2026

@techcomthanh is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The annotateOn state is not reset when switching sessions, causing the annotation overlay toggle to be stale and out of sync with the new session.

Fix on Vercel

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional Suggestion:

The annotateOn state is not reset when switching sessions, causing the annotation overlay toggle to be stale and out of sync with the new session.

Fix on Vercel

The local `annotateOn` state was scoped to the Viewport component, not to
the session. Switching sessions kept the toggle's previous state but the
new session has no overlay injected (and vice versa), so the UI was
out of sync with reality.

Reset to `false` whenever `sessionName` changes — the user re-enables
explicitly per session, which matches the actual overlay state on the
daemon side.

Addresses PR vercel-labs#1374 review feedback.
@techcomthanh
Copy link
Copy Markdown
Author

Addressed in 259430c: reset annotateOn to false in a useEffect keyed on sessionName. Now switching sessions clears the toggle so it matches the new session's actual overlay state (none injected yet). User re-enables explicitly per session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant