WebSocket
Recon has two WebSocket modes. recon ws runs a scripted exchange: it connects, sends the frames you give it, collects replies until a limit, and closes. The Studio and the HTTP API also offer an interactive session that stays open while you send frames one at a time. Use the scripted mode in a terminal, a CI job or an agent, and the interactive mode to explore a socket by hand.
Quick example
Section titled “Quick example”Start the Studio server to get the offline echo socket at /_sandbox/ws/echo. It sends a banner frame when you connect and echoes each text frame back as JSON.
recon init --demorecon ui --port 4600 --no-open &recon ws ws://127.0.0.1:4600/_sandbox/ws/echo --send '{"type":"ping"}' --send hello --max-receive 3WebSocket ws://127.0.0.1:4600/_sandbox/ws/echo (connect=0.4ms, total=46.5ms, frames=5, airlock=false) → [0.5ms] text {"type":"ping"} → [0.5ms] text hello ← [0.5ms] text {"banner":"Recon WS Sandbox Echo Ready","connected":true} ← [44.3ms] text {"contact":"elena@westminster.edu","echo":"{\"type\":\"ping\"}","ts":"2026-11-30T15:47:42.922673005+00:00"} ← [44.4ms] text {"contact":"elena@westminster.edu","echo":"hello","ts":"2026-11-30T15:47:42.966370904+00:00"}→ marks a frame Recon sent and ← a frame it received. The number in brackets is the frame’s offset in milliseconds.
Scripted mode: recon ws
Section titled “Scripted mode: recon ws”Targets
Section titled “Targets”<TARGET> is one of:
- a URL starting with
ws://orwss://; - a URL starting with
http://orhttps://, which Recon rewrites tows://orwss://; - the ID or name of a saved request. Its URL (which can use either scheme pair) and headers are used.
Anything else fails with E_NOT_FOUND and exit code 2. {{variables}} in the URL and headers are resolved from the selected environment.
Sequence
Section titled “Sequence”- Resolve variables, secrets and auth, then check the request with the secret firewall.
- Connect and complete the WebSocket upgrade. This step must finish within
--timeout-ms. - Send every
--sendvalue as a text frame, in the order given, without waiting for replies. - Read incoming frames until
--max-receiveframes are collected, the server closes, or--timeout-mspasses. This receive window starts after the last send. - Send a close frame and return the transcript.
Because the connect step and the receive window each get the full --timeout-ms, a run can take up to about twice that value.
Frame handling
Section titled “Frame handling”| Incoming frame | What Recon does |
|---|---|
| Text | Recorded with opcode text. Counts toward --max-receive. |
| Binary | Recorded with opcode binary and payload <binary N bytes>. The bytes are not shown. Counts toward --max-receive. |
| Ping, pong | Not recorded and not counted. |
| Close | Ends the exchange. The close frame is not recorded, and frames after it are not read. |
Frames you send are always text frames. A receive error after the connection is up fails the command with WebSocket receive error: .... Reaching the time limit is not an error: the command exits 0 with whatever it collected.
recon ws ws://127.0.0.1:4600/_sandbox/ws/echo --timeout-ms 1000WebSocket ws://127.0.0.1:4600/_sandbox/ws/echo (connect=0.2ms, total=1003.6ms, frames=1, airlock=false) ← [0.2ms] text {"banner":"Recon WS Sandbox Echo Ready","connected":true}Headers and subprotocols
Section titled “Headers and subprotocols”Headers from a saved request are added to the upgrade request, with these exceptions:
Host,Connection,Upgradeand every header starting withSec-WebSocket-are dropped, because the WebSocket library sets them.- If two headers have the same name, only the last one is sent.
The CLI has no flag for extra headers. To send headers such as Authorization, save the socket as a request in a .http file:
### Echo Socket# @name Echo SocketGET ws://127.0.0.1:4600/_sandbox/ws/echoAuthorization: Bearer {{DEV_API_TOKEN}}recon ws "Echo Socket" --send hi --max-receive 2WebSocket ws://127.0.0.1:4600/_sandbox/ws/echo (connect=0.4ms, total=2.6ms, frames=3, airlock=false) → [0.4ms] text hi ← [0.5ms] text {"banner":"Recon WS Sandbox Echo Ready","connected":true} ← [0.5ms] text {"contact":"elena@westminster.edu","echo":"hi","ts":"2026-11-30T15:53:16.317185484+00:00"}Timing
Section titled “Timing”| Field | Meaning |
|---|---|
connected_ms |
Time to connect and finish the upgrade. |
total_ms |
Time for the whole exchange. |
frames[].offset_ms |
Milliseconds from the start of the connection attempt to the moment the frame was sent or read. |
frames[].ts_utc |
Wall-clock time of the frame in RFC 3339 format. |
Output
Section titled “Output”human format prints the summary line and one line per frame. json and agent format print the full report:
recon --format json ws ws://127.0.0.1:4600/_sandbox/ws/echo --send '{"email":"elena.original@westminster.edu"}' --max-receive 2 --airlock{ "url": "ws://127.0.0.1:4600/_sandbox/ws/echo", "connected_ms": 0.37434700000000004, "total_ms": 2.6591050000000003, "frames": [ { "seq": 0, "ts_utc": "2026-11-30T15:47:47.581625843+00:00", "offset_ms": 2.4919059999999997, "direction": "sent", "opcode": "text", "payload": "{\n \"email\": \"micah.vaughn.9383@example.edu\"\n}", "is_json": true }, { "seq": 1, "ts_utc": "2026-11-30T15:47:47.581691381+00:00", "offset_ms": 2.551695, "direction": "received", "opcode": "text", "payload": "{\n \"banner\": \"Recon WS Sandbox Echo Ready\",\n \"connected\": true\n}", "is_json": true },... ], "airlocked": true, "compliance_receipt": { "salt_fingerprint": "9d2de0d49b08", "fields_masked": 1, "secrets_scrubbed": 0, "headers_stripped": 0, "verified_zero_leak": true, "leaked_tokens_found": [], "receipt_hash": "ebe21469763a42aa7110c1f5f2720a905a107289e0b482510d661de4e2845783" }}| Field | Meaning |
|---|---|
url |
The resolved URL, with secret values replaced by [SECRET:NAME]. |
connected_ms, total_ms |
See Timing. |
frames[] |
Sent and received frames in order: seq (from 0), ts_utc, offset_ms, direction (sent or received), opcode (text or binary), payload, is_json. |
frames[].is_json |
true when the payload starts with { or [ and parses as JSON. |
airlocked |
true when --airlock was passed. |
compliance_receipt |
The PII Airlock receipt for all captured payloads joined together. It is produced on every run. |
--airlock
Section titled “--airlock”With --airlock, the payload of every sent and received text frame is masked before it is recorded. JSON payloads are re-serialised during masking, which is why they appear pretty-printed in the example. Binary frames are never shown, so there is nothing to mask.
--airlock only changes what Recon records and prints. The frames sent over the wire carry your original --send text.
Interactive mode (Studio and HTTP API)
Section titled “Interactive mode (Studio and HTTP API)”The interactive session is available through the Studio server only. It keeps the socket open in the background:
- One session per server. Connecting again closes the previous session first.
- The connect step has no timeout.
- Sent and received frames are recorded the same way as in scripted mode (text and binary only; ping, pong and close are not recorded). A close frame or a read error ends the session.
- The server keeps the most recent 500 frames. Older frames are dropped.
- Airlock is chosen when you connect and applies to every frame in the session.
| Route | Body | Returns |
|---|---|---|
POST /api/v1/ws/connect |
url, optional headers, env, airlock |
connected, url, airlocked, frames |
POST /api/v1/ws/send |
message |
sent, connected, frames |
POST /api/v1/ws/close |
none | closed, connected |
GET /api/v1/ws/status |
none | connected, url, airlocked, frames |
Sending on a session that is closed fails with WebSocket session is closed. Sending with no session fails with no active WebSocket connection. Headers passed to connect follow the same rules as in scripted mode. See HTTP API for authentication of these routes.
In the Web Studio, open Protocols and pick the WebSocket tab, or use the command palette entry “Open WebSocket Console”. The URL defaults to the sandbox echo socket. Connect opens the session, Send Frame (or Enter) sends the message box as a text frame, and the frame timeline refreshes every 700 ms while connected. The Airlock toggle in the modal header starts on.
Secrets, auth and transport
Section titled “Secrets, auth and transport”-
Secret firewall. Both modes resolve variables, secret URIs and auth, then pass the upgrade request through the Outbound Secret Firewall before connecting. A blocked request exits with
1:### Leaky Socket# @name Leaky SocketGET ws://127.0.0.1:4600/_sandbox/ws/echoAuthorization: Bearer {{PROD_STRIPE_KEY}}Terminal window recon ws "Leaky Socket"error E_FIREWALL_BLOCKED: Blocked secret `PROD_STRIPE_KEY` bound for `api.stripe.com` from being sent to unauthorized host `127.0.0.1`.hint: Switch environment or update secret allowed_hosts. -
Auth and signing. A saved request’s auth block is applied before the upgrade. See Auth & Request Signing.
-
TLS.
wss://uses TLS with the bundled Mozilla root certificates. -
Not supported. The global
--proxy,--no-proxy,--ca-cert,--client-cert,--client-key,--insecure,--cookiesand--cookie-jarflags, and.recon/network.json, have no effect on WebSocket connections. There is no proxy support, no custom CA, no client certificate and no way to accept a self-signed certificate.
Neither mode writes to the Flight Recorder.
| Flag | Default | Description |
|---|---|---|
<TARGET> |
required | ws://, wss://, http:// or https:// URL, or a saved request ID or name. |
--env <ENV> |
workspace default_env |
Environment used for variables and secrets. |
--send <TEXT> |
none | Text frame to send after the upgrade. Repeat for more frames. |
--max-receive <N> |
10 |
Stop after this many received frames. Values below 1 become 1. |
--timeout-ms <MS> |
5000 |
Limit for the connect step, and again for the receive window. Minimum effective value 500. |
--airlock |
off | Mask PII in recorded payloads. |
Global flags such as --workspace, --format and --salt also apply. See the CLI Reference.
Errors and exit codes
Section titled “Errors and exit codes”| Exit | Code | When |
|---|---|---|
0 |
The exchange ran. This includes runs that stopped at the time limit. | |
1 |
E_FIREWALL_BLOCKED |
The secret firewall blocked the request. |
2 |
E_NOT_FOUND |
The target is not a URL with a supported scheme and not a saved request. |
2 |
E_CLI_RUNTIME |
Any other failure, for example WebSocket error: WebSocket connect failed: ... (refused connection, or a server that answered without upgrading, such as HTTP error: 200 OK), protocol operation timed out after <ms> ms when the upgrade did not finish in time, or WebSocket receive error: .... |
Also available via
Section titled “Also available via”| Surface | Name | Notes |
|---|---|---|
| MCP tool | recon_ws_exchange |
Scripted mode. Takes url or request, plus env, messages (array of strings), max_receive (default 10, capped at 50) and timeout_ms (default 5000, clamped to 500 to 30000). Airlock is always on. Agent policy treats the call as GET when messages is empty and as POST when it sends frames. |
| HTTP API | /api/v1/ws/connect, /api/v1/ws/send, /api/v1/ws/close, /api/v1/ws/status |
Interactive mode, see above. |
| Web Studio | Protocols, tab WebSocket | Interactive mode, see above. |