Skip to content

feat: add --follow flag to console and errors commands#867

Open
mvanhorn wants to merge 4 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-console-follow
Open

feat: add --follow flag to console and errors commands#867
mvanhorn wants to merge 4 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-console-follow

Conversation

@mvanhorn
Copy link
Contributor

Summary

  • Add --follow (-f) flag to the console and errors commands for real-time log streaming
  • Polls the daemon's existing EventTracker at 500ms intervals, printing only new entries since the last poll
  • Supports text mode ([level] text for console, text (url:line:col) for errors) and JSON mode (one JSON object per line, NDJSON)
  • Runs until Ctrl+C or daemon disconnect

Evidence

Source Evidence Engagement
PR #826 WebSocket streaming restored in native daemon Merged
Reddit r/ClaudeCode Debugging browser setups is a common pain point 3 upvotes

Usage

# Stream console logs in real-time (text mode)
agent-browser console --follow

# Stream as JSON lines (one JSON object per line)
agent-browser console --follow --json

# Follow only errors
agent-browser errors --follow
# or with short flag
agent-browser errors -f

Technical notes

The implementation uses a poll-based approach rather than WebSocket streaming. The CLI sends the existing console/errors command to the daemon in a loop, tracking a last_seen index to print only new entries. The daemon's EventTracker uses an append-only model so index tracking is straightforward. This avoids modifying the daemon's streaming protocol while still delivering a good developer experience.

If demand exists for sub-500ms latency, WebSocket-based push can be added later as a follow-up.

Checklist

  • cargo fmt - clean
  • cargo clippy - clean
  • cargo test - 461 passed, 0 failed
  • Changeset included

This contribution was developed with AI assistance (Claude Code).

Add real-time log streaming to the console and errors commands via
--follow (-f). Polls the daemon's EventTracker at 500ms intervals,
printing only new entries since the last poll. Supports both text
mode ([level] text) and JSON mode (one JSON object per line).

Runs until Ctrl+C or the daemon disconnects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Contributor

vercel bot commented Mar 17, 2026

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

A member of the Team first needs to authorize it.

The console log display code used "messages" and "type" to access
console entries, but the daemon's EventTracker returns "entries" and
"level". This meant console logs were never displayed in either
follow mode or normal output.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
mvanhorn added a commit to mvanhorn/agent-browser that referenced this pull request Mar 17, 2026
…d --follow code

Addresses @ctate's review:
1. Moved network_wait text output check above the generic URL handler
   in output.rs so "Matched: POST /api/login -> 200 (xhr)" displays
   correctly instead of being caught by the navigation response handler.
2. Removed --follow flag parsing and docs from this PR - that belongs
   in the separate console --follow PR (vercel-labs#867).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Collaborator

@ctate ctate left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together! The follow mode is a nice addition — polling the existing EventTracker keeps things simple and avoids touching the daemon protocol.

One issue to fix before merging: -f is already the global short flag for --full (full-page screenshots). Since global flags are parsed first, agent-browser console -f would silently set full=true instead of enabling follow mode. I'd suggest dropping the -f alias and keeping only --follow, or picking a different short flag like -F.

A couple smaller things:

  • The last_seen index tracking in run_console_follow uses entries/level keys but run_errors_follow uses errors/text — just want to confirm these match the actual daemon response shape (the output.rs fix in this PR changes messagesentries and typelevel, so it looks like the daemon response was recently updated).
  • If the daemon disconnects or returns an error, the loop retries silently every 500ms forever — might be worth printing a message or backing off after repeated failures.

@ctate
Copy link
Collaborator

ctate commented Mar 17, 2026

Actually - one sec. Moving --full down in #876.

ctate added a commit that referenced this pull request Mar 17, 2026
Move --full/-f from global flags (parsed in flags.rs) to command-level
parsing in commands.rs, scoped to the three commands that actually use
it: `screenshot`, `diff screenshot`, and `diff url`.

This frees up `-f` for other commands (e.g. `--follow` on
`console`/`errors`, see #867) and better reflects that full-page
capture is not a global concern.

Changes:
- Remove `full` from Flags struct, Config struct, and global flag parsing
- Remove `--full`/`-f` from clean_args global boolean flags list
- Parse `--full`/`-f` inline in `screenshot` command handler
- Accept `-f` shorthand in `diff screenshot` and `diff url` (previously
  only `--full` was accepted at command level)
- Remove fallback from global `flags.full` in diff subcommands
- Update tests to pass --full as a command argument rather than a global flag

Fixes #876
Removes -f as a short flag for --follow on console/errors commands
since -f is already the global shorthand for --full (full-page
screenshots). Only --follow is supported now.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mvanhorn
Copy link
Contributor Author

Removed -f shorthand in eca9fbf - only --follow now. Didn't realize it conflicted with --full.

ctate added a commit that referenced this pull request Mar 17, 2026
* refactor: make --full/-f a command-level flag instead of global

Move --full/-f from global flags (parsed in flags.rs) to command-level
parsing in commands.rs, scoped to the three commands that actually use
it: `screenshot`, `diff screenshot`, and `diff url`.

This frees up `-f` for other commands (e.g. `--follow` on
`console`/`errors`, see #867) and better reflects that full-page
capture is not a global concern.

Changes:
- Remove `full` from Flags struct, Config struct, and global flag parsing
- Remove `--full`/`-f` from clean_args global boolean flags list
- Parse `--full`/`-f` inline in `screenshot` command handler
- Accept `-f` shorthand in `diff screenshot` and `diff url` (previously
  only `--full` was accepted at command level)
- Remove fallback from global `flags.full` in diff subcommands
- Update tests to pass --full as a command argument rather than a global flag

Fixes #876

* fix: remove stale AGENT_BROWSER_FULL env var from help and add -f shorthand tests

- Remove AGENT_BROWSER_FULL from help text in output.rs since the env
  var is no longer read after moving --full to command-level parsing
- Add test_screenshot_full_page_shorthand to verify screenshot -f works
- Add test_diff_screenshot_command_full_flag_shorthand to verify
  diff screenshot -f works

---------

Co-authored-by: ctate <366502+ctate@users.noreply.github.com>
@ctate
Copy link
Collaborator

ctate commented Mar 17, 2026

@mvanhorn Sorry for the back and forth. --full is now scoped to screenshot, so you can do -f for follow in logs - which is common for logs

Per @ctate's vercel-labs#876, --full is now scoped to screenshot only,
so -f is free for --follow on console/errors commands.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mvanhorn
Copy link
Contributor Author

Restored -f in bdcd7c7. Thanks for clearing that up in #876.

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.

2 participants