WebSocket client in the browser

The PolyApiIDE WebSocket client opens a ws or wss connection, logs every frame in both directions, and substitutes environment variables straight into the connection URL.

A WebSocket starts life as an ordinary HTTP request with Upgrade: websocket, the server answers 101 Switching Protocols, and from then on the channel stays open while frames travel both ways. That is awkward to inspect with curl: you need a client that holds the connection and shows the message history.

When a dedicated WebSocket client helps

The usual questions are simple ones: does the server accept a connection on this address, is the token accepted, does the expected first frame arrive, and does the server react to the message you sent. All of that is only visible in a live channel — a frame log with timestamps and direction answers who stopped responding first far faster than application logs do.

In PolyApiIDE a WebSocket is a workspace type that sits in the same project as your REST and GraphQL requests. Hosts, tokens and channel names live in environments, so moving a connection between dev, test and production is a single switch.

How to check a WebSocket connection

1. Create a WebSocket workspace

The protocol type is set per workspace or per request. Use ws:// for local development and wss:// for everything else — a browser will not open an insecure socket from a secure page.

2. Put variables in the address

Move host, channel id and token into an environment: wss://{{host}}/ws?token={{token}}. The {{var}} and {var} substitution works in URLs exactly as it does for REST, so one request serves every stage.

3. Open the connection

A successful handshake means a 101 Switching Protocols response. If you get 401, 403 or 404 instead, the problem is still at the HTTP layer: address, auth, or proxy routing.

4. Send frames and watch the log

Messages go out as text — a JSON subscribe command, for example — and land in the same log as whatever the server pushes back. The log shows frame order, delays, and the moment the channel closed.

5. Read the close code

When the socket closes, the code tells you whether it was a clean shutdown, a drop, or a refusal. The common ones are in the table below.

Common WebSocket close codes

CodeMeaningWhere to look
1000 Normal closure agreed by both sides Nothing broke
1001 One side is going away — tab closed or server restarting Deploys, restarts, worker shutdown
1006 Abnormal closure with no close frame Proxy, idle timeout, network drop
1008 Message violated server policy Auth, frame format, limits
1009 Frame too large Server message size limit
1011 Internal server error Application logs, handler exception
4000-4999 Application-defined codes Your service documentation

Code 1006 usually means an intermediary cut the connection rather than your code: nine times out of ten it is an idle timeout on nginx or a load balancer.

What the WebSocket workspace does

  • Connect over ws and wss with variable substitution in the URL
  • Send text frames and read one log covering both directions
  • Environments and the request → collection → workspace → environment hierarchy
  • Collections and folders, so connections sit beside the rest of the project
  • Pre-request and after-response scripts
  • SSE in the same project when the server streams events over HTTP
  • Local-first storage; the cloud is only used on your command

Limits worth knowing up front

The client lives inside the browser and uses the browser WebSocket API, which has its own rules. Custom headers cannot be set during the handshake — that is a platform restriction, not an extension one. Tokens therefore travel as a query parameter, a cookie or a subprotocol, not as an Authorization header. If your server accepts the header only, that check has to be done with a server-side tool.

Raw TCP sockets and binary protocols on top of them are out of reach as well: a browser speaks HTTP and WebSocket, nothing lower. Load profiles in the extension target HTTP requests, not thousands of concurrently held sockets.

Frequently asked questions

Is a sign-up required?

No. Free works as soon as the extension is installed; no account is needed to send requests or open a WebSocket connection.

Can I pass the token in a header?

No — the browser WebSocket API does not allow handshake headers. Working options are a query parameter, a cookie or a subprotocol. This is a platform limit and applies to every browser-based client.

Why does the connection drop after a minute or two?

Usually an idle timeout on a reverse proxy. Check the nginx or balancer settings and send ping frames from the application. In the log it shows up as code 1006 with no close frame.

Can I open ws:// against a production host?

For local development yes; for anything else the browser will insist on wss:// and refuse to mix a secure page with an insecure socket.

Are connections kept between sessions?

The requests and addresses are — they live in collections stored locally in the browser. An open socket, naturally, only lasts while the extension is running.