Server Architecture

The server acts as a WebSocket relay between clients and inspectors, routing CDP messages bidirectionally.

WebSocket Relay Server

Connection Management

Message Routing

The server routes messages based on the connection type:

  1. Client to Inspector: When a client sends a CDP event or response, the server forwards it to all connected inspectors that have selected that client.

  2. Inspector to Client: When an inspector sends a CDP command, the server forwards it to the selected client.

HTTP Endpoints

The server provides HTTP endpoints for client discovery:

  • GET /json - Get all clients (legacy format)
  • GET /json/clients - Get all clients with details
  • GET /json/inspectors - Get all inspectors
  • GET /json/client/:id - Get specific client
  • GET /client.js - Serve built client script

Features

  • Multiple Client Support: Handle multiple client connections simultaneously
  • Multiple Inspector Support: Support multiple inspectors connecting to the same or different clients
  • Client Switching: Inspectors can switch between different clients
  • Message Relay: Bidirectional message routing between clients and inspectors
  • Connection State Management: Track and manage connection states

Implementation

The server is implemented using:

  • Bun: TypeScript runtime
  • ws: WebSocket library
  • HTTP Server: For serving static files and API endpoints