Developer and Text Tools

How to Test WebSocket and Server-Sent Events Endpoints in a Browser

How WebSockets and Server-Sent Events work, when to use each, and how to connect, send templated messages, read close codes and export frame logs.

Saizul Amin
Saizul Amin2 Nov 2026 · 4 min read
How to Test WebSocket and Server-Sent Events Endpoints in a Browser

How to Test WebSocket and Server-Sent Events Endpoints in a Browser

Real-time features such as chat, live dashboards, notifications and streamed AI responses rely on long-lived connections rather than one request and one response. Debugging them with ordinary HTTP tools is awkward, because the interesting part happens after the connection opens. This guide explains the two browser-native options, WebSocket and Server-Sent Events, and shows how to test both with a free in-browser client.

WebSocket versus Server-Sent Events

A WebSocket, defined in RFC 6455, starts as an HTTP request that upgrades to a persistent, two-way channel. Either side can send text or binary frames at any time. Client and server may agree on a subprotocol during the handshake. When the connection ends, a close code explains why: 1000 is a normal closure, while 1006 means the connection dropped without a proper close frame.

Server-Sent Events are simpler: a normal HTTP response with the content type text/event-stream that the server keeps open and writes to. Communication is one-way, from server to client. The format, defined in the HTML standard, is line-based. data: lines carry the payload and are joined with newlines, event: names the event type, id: sets the last event id, retry: suggests a reconnect delay in milliseconds, lines starting with a colon are comments, and a blank line dispatches the event.

Use WebSocket when the client needs to send frequent messages too. Use SSE when the server pushes updates and the client mostly listens; it works over ordinary HTTP infrastructure and reconnects on its own.

The EventSource catch

Browsers provide EventSource for SSE. It handles reconnection and last event ids automatically, but it cannot set custom headers or send a request body. Many APIs, including streaming AI endpoints, need an Authorization header or a POST body, so clients read the stream with fetch and parse it themselves.

Testing with the tool

Open the WebSocket and Server-Sent Events Tester and press + Session. Name it and choose WebSocket, SSE (EventSource) or SSE via fetch. A session remembers the URL, subprotocols, headers and saved messages, so you can keep one per service or environment.

In WebSocket mode, enter a wss:// address and press Connect. The log records how long the connection took and which subprotocol was agreed. Write a message and press Send. Messages can contain {{counter}}, {{timestamp}}, {{iso}}, {{uuid}} and {{rand}}, filled in at send time; text that looks like JSON is validated first. The repeat option sends the message every n milliseconds, at least 100, which helps with keep-alive pings. Binary frames appear as hexadecimal bytes, and the close code and reason are logged when the socket ends.

For SSE via EventSource, unnamed events arrive as message; save the names of custom events in the session to listen for them. For SSE via fetch, add headers or a body, and the tool parses the stream with the standard's rules.

The log colours incoming frames blue, outgoing green, system lines grey and errors red. Filter by text, switch on pretty JSON, and export as JSON or CSV with ISO timestamps for a bug report. Save message keeps useful payloads in the session.

Worked example

Create a WebSocket session for a public echo server such as wss://echo.websocket.org, connect, and send { "type": "ping", "n": {{counter}} } three times. The log shows three outgoing frames with n equal to 1, 2 and 3 and an echoed reply after each, with timestamps that reveal the round trip. Close the connection and the log records code 1000. Export the log as CSV to attach to a ticket.

Tips and common mistakes

  • An HTTPS page cannot open ws:// or http:// endpoints; use wss:// and https://.
  • If a WebSocket closes immediately with 1006, check whether the server rejects your page's origin.
  • For SSE, make sure proxies do not buffer the response, or events arrive in bursts.
  • Send a heartbeat on long idle connections; some load balancers close quiet sockets.
  • Keep test payloads in saved messages so a teammate can reproduce the same sequence.

Limits

The browser connects directly from this page, so the server must accept it: WebSocket servers may check the Origin header, and cross-origin SSE or fetch streams need CORS headers. Browsers do not allow custom headers on the WebSocket handshake, so token-in-header authentication cannot be tested in WebSocket mode. Mixed content is blocked, public test servers may be offline, and the tool is not a load-testing system.

Completely freeNo cost, no sign-up
Files stay privateEverything runs in your browser
Easy in your languageAvailable in many languages