#22252: fix(chrome-extension): connection validation and clarify relay port derivation
docs
size: XS
Cluster:
Chrome Extension Enhancements
## Problem
When users configure a custom gateway port, the Chrome extension requires the **relay port** (gateway + 3), not the gateway port itself. However:
1. The documentation didn't explain the port derivation formula
2. The Options page validation only checked HTTP 200 status, not response content
3. Users got misleading "success" when configuring the gateway port because it returned HTTP 200 with HTML instead of CDP JSON
This caused WebSocket connection failures with confusing "pairing required" errors.
## Solution
### 1. Documentation
Added "Custom Gateway ports" section to `docs/tools/chrome-extension.md` explaining:
- **Extension Relay Port = Gateway Port + 3**
- Example: gateway 19001 → relay 19004
### 2. Validation Fix
Updated `assets/chrome-extension/options.js` to:
- Validate `Content-Type: application/json` header
- Check for CDP response fields (`Browser`, `Protocol-Version`)
- Show helpful error with formula when wrong port is configured
## Testing
Verified both ports with gateway at 18964:
- Port 18964 (gateway): Now shows error "Wrong port: this is the gateway, not the relay. Use gateway port + 3"
- Port 18967 (relay): Shows success "Relay reachable and authenticated"
## Example Error Messages
**Gateway port (wrong):**
```
Wrong port: this is the gateway, not the relay. Use gateway port + 3 (e.g., if gateway is 18789, use 18792).
```
**Relay port (correct):**
```
Relay reachable and authenticated at http://127.0.0.1:18967/
```
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Enhanced Chrome extension setup by adding port derivation documentation and improving relay endpoint validation.
- Added "Custom Gateway ports" section to docs explaining the **relay port = gateway port + 3** formula with examples
- Updated `options.js` validation to check `Content-Type: application/json` header and verify CDP response fields (`Browser`, `Protocol-Version`)
- Improved error messages to guide users when they mistakenly configure the gateway port (18964) instead of the relay port (18967)
- Added error handling to distinguish between JSON parsing errors (wrong endpoint) and connectivity issues
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The changes are well-targeted fixes that improve user experience without modifying core logic. The port derivation formula (gateway + 3) is verified correct by the codebase (`controlPort = gateway + 2`, `relayPort = controlPort + 1`). The validation improvements properly check content-type and response structure, preventing false positives. Error messages are clear and actionable.
- No files require special attention
<sub>Last reviewed commit: 5295543</sub>
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#22571: fix(browser): complete extension relay handshake on connect.challenge
by pandego · 2026-02-21
79.7%
#21314: feat: enhance browser relay with custom naming and diagnostic tools
by kelvinCB · 2026-02-19
79.1%
#20688: fix(browser): allow extension reconnect when stale websocket linger...
by HOYALIM · 2026-02-19
75.5%
#5278: fix(browser): prevent DNS rebinding in extension relay HTTP endpoints
by webvijayi · 2026-01-31
75.5%
#15817: fix(chrome-relay): auto-reconnect, MV3 persistence, and keepalive
by derrickburns · 2026-02-13
75.1%
#8745: fix(gateway): respect gateway.port config and --port CLI flag
by revenuestack · 2026-02-04
75.0%
#19766: fix: Chrome relay extension auto-reattach after SPA navigation
by nishantkabra77 · 2026-02-18
74.9%
#16060: fix(browser): require relay auth token for /extension WebSocket and...
by coygeek · 2026-02-14
74.6%
#16689: browser: support multiple Chrome extension connections to relay
by globalcaos · 2026-02-15
73.6%
#17588: fix(relay): survive WS disconnects and MV3 worker restarts
by Unayung · 2026-02-15
73.5%