Skip to content

feat: add network wait subcommand for request-specific sync#866

Open
mvanhorn wants to merge 3 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-network-wait
Open

feat: add network wait subcommand for request-specific sync#866
mvanhorn wants to merge 3 commits intovercel-labs:mainfrom
mvanhorn:osc/feat-network-wait

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

Summary

  • Add network wait <url-pattern> subcommand that waits for a network response matching a URL substring pattern
  • Support --status <code>, --method <method>, and --timeout <ms> filters
  • Reuse existing CDP Network.responseReceived event subscription (same pattern as handle_responsebody)
  • Include changeset, help text, and README updates

Motivation

AI agents need to wait for specific API responses before proceeding. Currently the only synchronization is wait --load networkidle, which waits for ALL network activity to stop. For SPAs where background polling keeps the network active, networkidle never resolves or resolves at the wrong time.

Playwright has page.waitForResponse(urlPattern) for this - agent-browser has no equivalent.

Evidence

Source Evidence Signal
#555 network requests doesn't capture document navigations - agents can't inspect what loaded Open issue
PR #847 Network idle detection fix for cached pages - active work on network sync Merged
PR #464 "network response + dump" proposed but closed (scope too broad) Closed
Reddit r/mcp AI browser tool benchmarking - sync overhead matters for cost 10 upvotes

Usage

# Wait for any response matching a URL pattern
agent-browser network wait "/api/users"

# Wait for a specific status code
agent-browser network wait "/api/login" --status 200

# With method filter
agent-browser network wait "/api/orders" --method POST

# With custom timeout (default: 30s)
agent-browser network wait "/api/data" --timeout 10000

Text output: Matched: POST /api/login -> 200 (xhr)

JSON output: {"url":"https://example.com/api/login","method":"POST","status":200,"resourceType":"xhr"}

Technical notes

  • The implementation subscribes to CDP Network.responseReceived events via mgr.client.subscribe(), matching the exact pattern used by handle_responsebody (line ~4133)
  • Enables Network.enable if request tracking isn't already active
  • URL matching uses substring contains (consistent with network requests --filter)
  • Method extraction reads from the response's :method request header
  • ~170 lines of Rust + docs

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

Add `network wait <url-pattern>` command that waits for a network
response matching a URL pattern with optional --status, --method,
and --timeout filters. Reuses existing CDP Network.responseReceived
events with a poll-based timeout loop, matching the pattern used
by handle_responsebody.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@vercel
Copy link
Copy Markdown
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 `:method` pseudo-header in response.requestHeaders only exists
for HTTP/2 connections, causing --method filtering to silently fail
on HTTP/1.1. Track methods from Network.requestWillBeSent events
(which include request.method for all protocol versions) and look
them up by requestId when processing Network.responseReceived.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Copy Markdown
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 this! Waiting for specific network responses is a much-needed improvement over networkidle — nice work.

Two things to fix: First, the pretty text output (Matched: POST /api/login -> 200 (xhr)) never actually displays — the generic URL handler in output.rs catches it first. Moving the network_wait check above line 152 should do it. Second, the --follow flag for console/errors is parsed and documented here but the backend doesn't implement it — best to pull that out into its own PR.

…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 <[email protected]>
@mvanhorn
Copy link
Copy Markdown
Contributor Author

Fixed in 4f5a6d5: moved the network_wait output check above the generic URL handler in output.rs so the pretty text displays correctly. Also removed the --follow flag parsing and docs from this PR - that's in #867.

@mvanhorn
Copy link
Copy Markdown
Contributor Author

Both fixed in 4f5a6d5:

  1. Moved network_wait check above the generic URL handler so the pretty output displays correctly
  2. Removed the --follow flag code that leaked from feat: add --follow flag to console and errors commands #867

@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Apr 1, 2026

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