Add browse cdp command for streaming CDP events#1905
Open
derekmeegan wants to merge 3 commits intomainfrom
Open
Add browse cdp command for streaming CDP events#1905derekmeegan wants to merge 3 commits intomainfrom
browse cdp command for streaming CDP events#1905derekmeegan wants to merge 3 commits intomainfrom
Conversation
Adds a new `browse cdp <url|port>` command that connects to any Chrome DevTools Protocol target and streams events as NDJSON to stdout. Supports --domain filtering, --pretty for human-readable output, and clean piping to files or jq. Enables Network, Console, Runtime, Log, and Page domains by default with automatic multi-tab target tracking. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 2737c27 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 4/5
- This PR looks safe to merge overall: the reported issue is low-to-moderate severity (4/10) and focused on error visibility rather than core command execution flow.
- In
packages/cli/src/index.ts, CDP command failures are currently only surfaced in pretty output, so NDJSON users can miss invalid domains or failedenablecalls when piping output. - Pay close attention to
packages/cli/src/index.ts- ensure CDP errors are logged in NDJSON mode to avoid silent operational failures.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/cli/src/index.ts">
<violation number="1" location="packages/cli/src/index.ts:2962">
P2: Log CDP command errors even in NDJSON mode. Right now errors are only printed in pretty mode, so invalid domains or failed enable calls are silently ignored when piping output.</violation>
</file>
Architecture diagram
sequenceDiagram
participant User as User / Shell
participant CLI as Browse CLI
participant Resolver as resolveWsTarget
participant Browser as CDP Server (Chrome/Browserbase)
Note over User,Browser: Initialization Flow
User->>CLI: browse cdp <url|port> [--pretty] [--domain]
CLI->>Resolver: resolveWsTarget(target)
Resolver-->>CLI: ws://... URL
CLI->>Browser: NEW: Establish WebSocket Connection
opt Connection Successful
Browser-->>CLI: onOpen
CLI->>Browser: NEW: Target.setAutoAttach (filter: page)
CLI->>Browser: NEW: Target.setDiscoverTargets (discover: true)
end
Note over User,Browser: Session & Event Handling
loop Every Message
Browser-->>CLI: Protocol Message (NDJSON)
alt Message is response to CLI command
CLI->>CLI: Match ID & discard
else NEW: Message is "Target.attachedToTarget"
CLI->>CLI: Track targetId -> sessionId map
loop for each requested domain
CLI->>Browser: NEW: [Domain].enable (with sessionId)
end
else NEW: Message is "Target.detachedFromTarget"
CLI->>CLI: Remove session from tracking
else NEW: General CDP Event (Network/Console/etc)
alt --pretty flag set
CLI->>CLI: Format human-readable string
else default (NDJSON)
CLI->>CLI: Stringify original JSON
end
CLI->>User: Write to stdout (+ \n)
opt Pipe Broken (EPIPE)
CLI->>CLI: Graceful exit(0)
end
end
end
Note over User,Browser: Shutdown Flow
alt SIGINT / SIGTERM received
CLI->>Browser: Close WebSocket
CLI->>User: Exit process
else Browser closes connection
CLI-->>User: "Disconnected" (if --pretty)
end
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Also adds @types/ws to fix typecheck. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2 tasks
Previously CDP command errors (e.g. failed domain enable) were only logged in pretty mode. Now errors always go to stderr regardless of output mode, so piped NDJSON users see failures too. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
browse cdp <url|port>command that connects to any CDP WebSocket target and streams DevTools protocol events as NDJSON to stdout--domainfiltering (defaults to Network, Console, Runtime, Log, Page),--prettyfor human-readable outputbrowse cdp ws://... > log.jsonl) or jq (browse cdp ws://... | jq '.method')browse cdp 9222) via existingresolveWsTargetutilityTest plan
--prettymode shows human-readable event summaries--remote-debugging-port=9222--domainfiltering (e.g.--domain Networkonly)🤖 Generated with Claude Code