Skip to content

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Nov 9, 2025

Add CDP Connection Manager for Direct Chrome DevTools Protocol Support

Summary

Implements a new CDPConnectionManager class in src/cdp/connection-manager.ts that provides direct Chrome DevTools Protocol (CDP) communication without Playwright. This is foundational infrastructure for Task 1.1 of the Playwright removal effort.

Key capabilities:

  • Launch Chrome locally using chrome-launcher with configurable options
  • Connect to remote CDP endpoints via WebSocket
  • Manage CDP session lifecycle with proper cleanup
  • Handle multiple pages/tabs using CDP Target domain
  • Automatic reconnection logic for dropped connections
  • Comprehensive error handling with [CDP] prefixed logging

Dependencies added:

  • ws (^8.18.3) - WebSocket client for CDP communication
  • chrome-launcher (^1.2.1) - Chrome process management
  • @types/ws (^8.18.1) - TypeScript types for ws

Note: This PR does NOT modify any existing files - it only adds new infrastructure that will be integrated in subsequent tasks.

Review & Testing Checklist for Human

Risk Level: 🟡 Yellow (foundational infrastructure, not yet integrated)

  • Type safety review: Check the type assertions in createSession(), listTargets(), and createTarget(). The sendBrowserCommand() method returns unknown and requires casting - verify these casts are safe.
  • Message routing logic: Review handleBrowserMessage() and the session management in sendBrowserCommand(). The "browser" session pattern for browser-level commands vs target-specific sessions is complex - verify it handles edge cases correctly.
  • Test existing functionality: Run a few example scripts (e.g., examples/llms/openai.ts) to ensure the new dependencies don't break anything. The build passes but integration testing is needed.
  • Chrome launcher compatibility: Note the experimental warning about loading ES modules in CommonJS. Consider if this needs to be addressed before merging.

Test Plan

  1. Verify build passes: yarn build
  2. Run lint: yarn lint (existing lint errors in other files are pre-existing)
  3. Test a few example scripts to ensure no regressions
  4. Consider creating a simple integration test that uses the CDP connection manager

Notes

- Implement CDPConnectionManager class with WebSocket-based CDP communication
- Add launchLocal() method to launch Chrome locally with chrome-launcher
- Add connect() method to connect to remote CDP endpoints via WebSocket
- Add createSession() method for CDP session management with Target domain
- Add sendCommand() method with proper error handling and timeouts
- Implement CDP Target domain methods: listTargets, createTarget, attachToTarget, closeTarget
- Add reconnection logic for dropped connections
- Add comprehensive error handling and [CDP] prefixed logging
- Add ws, chrome-launcher, and @types/ws dependencies

This is foundational infrastructure for replacing Playwright's browser launching and connection handling.

Co-Authored-By: devin@hyperbrowser.ai <devindenggithub@gmail.com>
@devin-ai-integration
Copy link
Author

Original prompt from devin
### Task 1.1: Create CDP Connection Manager  
**Execution**: Sequential, first task    
**Estimated Complexity**: Medium-High  
  
**Detailed Prompt:**  

Create a new CDP connection management system to replace Playwright's browser launching and connection handling.

CONTEXT:
The HyperAgent codebase currently uses Playwright to launch Chrome and manage browser connections. There are two browser providers:

  1. LocalBrowserProvider - launches Chrome locally using Playwright's chromium.launch()
  2. HyperbrowserProvider - connects to remote browser using Playwright's connectOverCDP()

YOUR TASK:
Create a new module at src/cdp/connection-manager.ts that provides direct CDP connection capabilities without Playwright.

REQUIREMENTS:

  1. Create a CDPConnectionManager class with these capabilities:

    • Launch local Chrome using Node.js child_process with --remote-debugging-port flag
    • Connect to remote CDP endpoints via WebSocket
    • Manage CDP session lifecycle (connect, disconnect, reconnect)
    • Handle multiple pages/tabs using CDP Target domain
    • Emit connection status events (connected, disconnected, error)
  2. Implement these core methods:

    • launchLocal(options): Launch Chrome locally, return CDP endpoint URL
    • connect(endpoint): Connect to a CDP endpoint via WebSocket
    • createSession(targetId?): Create a new CDP session for a target (page/frame)
    • sendCommand(session, method, params): Send CDP commands with proper error handling
    • close(): Clean up all connections and processes
  3. Use the CDP Target domain to:

    • List available targets (pages/tabs)
    • Create new targets
    • Attach to existing targets
    • Close targets
  4. Implementation notes:

    • Use 'ws' package for WebSocket connections (add to dependencies if needed)
    • Consider using 'chrome-launcher' package for local Chrome management
    • devtools-protocol package is already available for Typ... (782 chars truncated...)
</details>

@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

- Add type assertions for sendBrowserCommand return values
- Cast attachResult to { sessionId: string }
- Cast Target.getTargets result to { targetInfos: Protocol.Target.TargetInfo[] }
- Cast Target.createTarget result to Protocol.Target.CreateTargetResponse
- Build now passes successfully

Co-Authored-By: devin@hyperbrowser.ai <devindenggithub@gmail.com>
@devin-ai-integration
Copy link
Author

Closing due to inactivity for more than 7 days. Configure here.

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