Browser Bridge server and CLI for controlling a Chrome extension over WebSocket
Project description
browser-agent-bridge
WebSocket-only browser bridge for remotely controlling a local Chrome extension.
Architecture (WS-only)
Operator CLI (remote/local)
|
| ws(s)://.../ws/operator (auth)
v
Bridge Server
^
| ws(s)://.../ws/client (auth)
|
Chrome Extension (local browser)
|
+-- content script commands: observe/click/type/get_html/ping_tab/etc.
The extension connects outbound to server. Operator sends commands through server to a specific (instance_id, client_id).
Protocol
Client -> Server
auth:{kind, instance_id, client_id, token}result:{kind, command_id, ok, result|error}ping
Server -> Client
auth_ok/auth_errorcommand:{kind, command_id, type, payload, request_id, sent_at}pong
Operator -> Server
auth:{kind, token}list_clientsconnect_status:{kind, instance_id, client_id}send_command:{kind, instance_id, client_id, type, payload, timeout_s, request_id}ping
Server -> Operator
auth_ok/auth_errorclientsconnect_statuscommand_resultpong
Auth Modes
Set BRIDGE_AUTH_MODE:
static(default): compare token againstBRIDGE_SHARED_TOKEN(for clients) andBRIDGE_OPERATOR_TOKEN(for operator; defaults to shared token).jwt: validate JWT withBRIDGE_JWT_SECRET/BRIDGE_JWT_ALG.- Client JWT should include matching
instance_idandclient_idclaims. - Operator JWT should include
role=operator.
- Client JWT should include matching
Production safety
BRIDGE_ENV=productionenforces strong auth config:- static mode:
BRIDGE_SHARED_TOKENmust not be empty/dev default. - jwt mode:
BRIDGE_JWT_SECRETmust not be default.
- static mode:
Install (pipx recommended)
python3 -m pip install --user pipx
python3 -m pipx ensurepath
pipx install browser-agent-bridge
Quick Start
1) (Optional) Generate local JWT secret file
browser-bridge setup-secret
If BRIDGE_AUTH_MODE=jwt and BRIDGE_JWT_SECRET is still default, server startup auto-loads/creates local secret file (~/.browser_bridge/jwt_secret or BRIDGE_JWT_SECRET_FILE).
2) Start server
# static mode example
export BRIDGE_AUTH_MODE=static
export BRIDGE_SHARED_TOKEN='change-me-strong-token'
export BRIDGE_OPERATOR_TOKEN='change-me-strong-operator-token'
browser-bridge-server
3) Load extension
- Open
chrome://extensions - Enable Developer mode
- Load unpacked
extension/ - In popup fill:
Bridge Server WS URL:ws://127.0.0.1:8765/ws/client(orwss://.../ws/client)Instance ID: e.g.local-instanceClient ID: e.g.chrome-mainAuth Token / JWT: client token
- Save + Connect
4) Operator CLI usage
browser-bridge --server-ws-url ws://127.0.0.1:8765/ws/operator --token 'change-me-strong-operator-token' list-clients
browser-bridge --server-ws-url ws://127.0.0.1:8765/ws/operator --token 'change-me-strong-operator-token' connect-status --instance-id local-instance --client-id chrome-main
browser-bridge --server-ws-url ws://127.0.0.1:8765/ws/operator --token 'change-me-strong-operator-token' ping-tab --instance-id local-instance --client-id chrome-main
browser-bridge --server-ws-url ws://127.0.0.1:8765/ws/operator --token 'change-me-strong-operator-token' observe --instance-id local-instance --client-id chrome-main
Raw command:
browser-bridge --server-ws-url ws://127.0.0.1:8765/ws/operator --token '...' \
send-command --instance-id local-instance --client-id chrome-main \
--type get_html --payload '{"max_chars":40000}'
Security Hardening
- Use TLS in non-local deployments (
wss://). - Use strong static tokens or JWT secret.
- Optional command allowlist:
BRIDGE_COMMAND_ALLOWLIST=observe,ping_tab,get_html. - Optional allowed clients allowlist in static mode:
BRIDGE_ALLOWED_CLIENTS=instance1:client1,instance2:client2. - Request idempotency/replay guard is enforced by
request_iddedup window. - Max payload limit is enforced by
BRIDGE_MAX_MESSAGE_BYTES.
Deprecated HTTP Endpoints
Old session-based HTTP endpoints are deprecated and disabled by default:
POST /api/sessionsGET /api/sessions/{session_id}POST /api/sessions/{session_id}/command
Behavior:
- default (
BRIDGE_ENABLE_HTTP_COMPAT=0): returns410 Gonewith migration hint. - compatibility flag on: currently returns
501stub in this build.
Migration from HTTP Session Model
Old flow:
- create session over HTTP
- paste
session_id+ token into extension - send commands over HTTP per session
New flow:
- extension directly authenticates to
/ws/clientwithinstance_id+client_id+ token/JWT - operator authenticates to
/ws/operator - commands routed over WS by
(instance_id, client_id)
No session creation API is required.
Testing
pytest -v
Coverage includes WS auth success/failure, command routing, disconnect handling, wrong target routing, CLI failure paths, and reconnect replacement behavior.
License
MIT (see LICENSE).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file browser_agent_bridge-0.2.0.tar.gz.
File metadata
- Download URL: browser_agent_bridge-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23bba52bfa5991dd4c2e2d8a85c57af27cfdf10c7239662428a2a18ec0d8c0ec
|
|
| MD5 |
3b1de1c02a4b40bbfe7fe5cf9384edd1
|
|
| BLAKE2b-256 |
381ce93136fea7ee1ffa1e72f06f41dd87ce045dc52787d851b1bf74a3f585dd
|
Provenance
The following attestation bundles were made for browser_agent_bridge-0.2.0.tar.gz:
Publisher:
publish.yml on NmadeleiDev/browser_agent_bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
browser_agent_bridge-0.2.0.tar.gz -
Subject digest:
23bba52bfa5991dd4c2e2d8a85c57af27cfdf10c7239662428a2a18ec0d8c0ec - Sigstore transparency entry: 1024233565
- Sigstore integration time:
-
Permalink:
NmadeleiDev/browser_agent_bridge@51bd721d8d06feb61aed6fe535fc0586e8f1af7c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/NmadeleiDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@51bd721d8d06feb61aed6fe535fc0586e8f1af7c -
Trigger Event:
push
-
Statement type:
File details
Details for the file browser_agent_bridge-0.2.0-py3-none-any.whl.
File metadata
- Download URL: browser_agent_bridge-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f056a0f5a39930a47bcd706765466d0adcf4702c63332928d4920001a1908e9
|
|
| MD5 |
b10009849d98345e6d303405615b20cb
|
|
| BLAKE2b-256 |
7b26e001f4d3c18c31bdddefa64aa73ad22dec4ccdab3b25e8d3d6134bcaf763
|
Provenance
The following attestation bundles were made for browser_agent_bridge-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on NmadeleiDev/browser_agent_bridge
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
browser_agent_bridge-0.2.0-py3-none-any.whl -
Subject digest:
4f056a0f5a39930a47bcd706765466d0adcf4702c63332928d4920001a1908e9 - Sigstore transparency entry: 1024233623
- Sigstore integration time:
-
Permalink:
NmadeleiDev/browser_agent_bridge@51bd721d8d06feb61aed6fe535fc0586e8f1af7c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/NmadeleiDev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@51bd721d8d06feb61aed6fe535fc0586e8f1af7c -
Trigger Event:
push
-
Statement type: