Skip to content

Conversation

@Gongcong
Copy link

Feature Description

This PR adds support for remote CDP connections and WebSocket protocol.

Key Changes

  • ✅ Support connecting to remote CDP endpoints via full URL (http://, https://)
  • ✅ Support WebSocket protocol (ws://, wss://)
  • ✅ Maintain backward compatibility - port numbers still work for local connections
  • ✅ Updated type definitions and protocol validation

Usage Examples

# Local connection (existing functionality)
agent-browser --cdp 9222 snapshot

# Remote HTTP connection
agent-browser --cdp http://remote-host:9222 snapshot

# WebSocket connection
agent-browser --cdp ws://remote-host:9222 snapshot

# Secure WebSocket connection
agent-browser --cdp wss://secure-host:9222 snapshot

Modified Files

  • src/types.ts - Updated type definitions to support string | number
  • src/protocol.ts - Updated protocol validation to support multiple URL formats
  • src/browser.ts - Updated connection logic to support remote and WebSocket connections
  • cli/src/main.rs - Updated CLI argument parsing to support URL formats

Testing

  • Type checking passes
  • Code formatting passes
  • Backward compatibility maintained

- 支持通过完整 URL 连接到远程 CDP 端点
- 支持 ws:// 和 wss:// WebSocket 协议
- 保持向后兼容,端口号仍然支持本地连接
- 更新类型定义和协议验证以支持多种 URL 格式
@vercel
Copy link
Contributor

vercel bot commented Jan 15, 2026

Someone 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

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a2a8c0b18f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

(val) => {
// Accept port numbers as strings, or full URLs
if (/^\d+$/.test(val)) {
const port = parseInt(val, 10);
Copy link
Contributor

@vercel vercel bot Jan 15, 2026

Choose a reason for hiding this comment

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

Protocol validation accepts HTTPS, WS, and WSS URLs that connectOverCDP cannot handle, causing runtime failures

Fix on Vercel

cdpPort: z.number().positive().optional(),
cdpPort: z
.union([
z.number().positive(),
Copy link
Contributor

@vercel vercel bot Jan 15, 2026

Choose a reason for hiding this comment

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

Fixed: CDP port number validation now includes upper bound check and integer validation for numeric ports

Fix on Vercel

- Check if string is numeric and treat it as port number
- Convert numeric strings to http://localhost:port format
- Fixes runtime regression for JSON callers that serialize ports as strings
@Gongcong
Copy link
Author

Fixed the issue with numeric-string cdpPort handling.

The code now checks if a string is numeric (e.g., "9222") and treats it as a port number, converting it to http://localhost:9222 format. This ensures backward compatibility for JSON callers that serialize ports as strings while still supporting full URLs for remote connections.

rgarcia added a commit to kernel/agent-browser that referenced this pull request Jan 18, 2026
When JSON callers serialize port numbers as strings (e.g., "9222" instead
of 9222), the CDP connection should still work correctly. Added explicit
regex check for numeric strings to handle this edge case gracefully.

Inspired by PR vercel-labs#110's approach to handling this scenario.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
rgarcia added a commit to kernel/agent-browser that referenced this pull request Jan 18, 2026
When JSON callers serialize port numbers as strings (e.g., "9222" instead
of 9222), the CDP connection should still work correctly. Added explicit
regex check for numeric strings to handle this edge case gracefully.

Inspired by PR vercel-labs#110's approach to handling this scenario.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@district10
Copy link

Similar logic already merged: #99

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