Browser Bridge Protocol

Every WebSocket message the browser bridge accepts, with replies and error codes

The bridge at ws://127.0.0.1:8765/ws routes messages between CLI clients, the bridge’s BrowserAgent and the Chrome extension.

Diagram

Bridge Protocol

💻 Client

🌉 Bridge :8765

🧠 BrowserAgent

🧩 Extension

Quick Start

  1. Register as the extension (JavaScript)
    js
    const ws = new WebSocket("ws://127.0.0.1:8765/ws");
    ws.addEventListener("open", () => {
      ws.send(JSON.stringify({ type: "register", client: "extension" }));
    });
    ws.addEventListener("message", (e) => console.log(JSON.parse(e.data)));
  2. Start a session as a CLI client (Python)
    python
    import asyncio, json, websockets
    
    async def main():
        async with websockets.connect("ws://127.0.0.1:8765/ws") as ws:
            print(await ws.recv())  # "connected" welcome
            await ws.send(json.dumps({"type": "start_session", "goal": "open example.com"}))
            print(await ws.recv())
    
    asyncio.run(main())

Message Catalog

TypeDirectionReply
registerClient → Serverstatus: registered or INVALID_ROLE
start_sessionCLI → Serverstatus or MISSING_GOAL, NO_EXTENSION, EXTENSION_IN_USE
observationExtension → Serveraction or NO_SESSION
stop_session / cancel_sessionAny → ServerSession status
pingAny → Server{"type": "pong"}
heartbeatExtension → Server{"type": "heartbeat_ack", "status": "ok"}

Roles

Each socket is an extension, a CLI, or neither, decided at connect time.

ConnectionRole
chrome-extension:// originExtension
No Origin headerCLI by default; may register as extension or cli
Web originCannot register — INVALID_ROLE

See Role Registration for the handshake.


Error Codes

CodeMeaning
NO_EXTENSIONNo registered extension socket to run the session
INVALID_ROLEregister rejected for this socket or role
UNKNOWN_TYPEMessage type not recognised
MISSING_GOALstart_session without a goal
NO_SESSIONobservation for an unknown session
EXTENSION_IN_USEExtension already owns a session
PARSE_ERRORMessage was not valid JSON
PROCESSING_ERRORUnexpected server error
START_AUTOMATION_FAILEDCould not deliver start_automation to the extension

Best Practices

Register before start_session

Wait for the registered status before sending start_session on the same socket.

Keep the socket alive

Send heartbeat about every 20 seconds from the extension.

Handle error replies

Branch on the code field, not the error text.


Related