Test WebSocket and SSE Endpoints Live in Your Browser

A WebSocket is a persistent, two-way connection between a browser and a server; server-sent events (SSE) are a one-way stream of text messages from a server to a browser over plain HTTP. Both carry live data — chat messages, notifications, dashboards, price ticks — but they fail in different ways, and the usual tools for checking them are wrong for the job: curl can fetch one SSE response but cannot hold a WebSocket open, and server logs only show one side of the conversation. This article explains what WebSocket and SSE are, what a live test shows you, what close codes and SSE fields mean, and how to check an endpoint with the WebSocket & SSE Live Tester — in your browser, with nothing uploaded.

What WebSocket and SSE are — and how they differ

A WebSocket starts life as an ordinary HTTP request that asks the server to upgrade the connection — the Upgrade: websocket header and a 101 Switching Protocols answer — and from then on the same TCP connection carries frames in both directions: text or binary, at any time, from either side, with no new request per message. That is what makes it right for chat, multiplayer games, collaborative editing and anything where the server must push data the moment it exists. The protocol is defined by RFC 6455, and every modern browser speaks it through the built-in WebSocket API — no library, no plugin, no server of your own.

Server-sent events are the simpler sibling. The client makes an ordinary HTTP request, the server answers with Content-Type: text/event-stream and then keeps the response open, sending lines of text — event:, data:, id:, retry: — whenever something happens. Traffic flows one way only, server to client, and the browser reconnects automatically if the connection drops, resuming from the last id it saw. SSE is right for notifications, activity feeds, progress updates and live dashboards: anything where the client listens and never talks back. If you need two-way traffic, you need a WebSocket; if you only need a feed, SSE is less machinery for the same result.

What the live log shows you

A live test is a conversation, and the log is the transcript. Every entry carries a direction — sent or received — a timestamp, and the payload itself, so you can see the exact message that went out and the exact frame that came back. For a WebSocket echo test the log also shows the round-trip latency: how long between sending the ping and seeing the echo, which is the number your users feel as lag. State transitions are logged too — connecting, open, closing, closed — so a connection that never opens, or one that drops after three seconds, is visible as a sequence, not a guess.

That transcript is what separates a live tester from a one-shot check. A status code tells you the handshake worked; the log tells you the connection stayed up, the server answered, and the messages arrived intact and in order. The demo in the companion tool connects to a public echo service, sends {"type":"ping","message":"hello from sysosx"} and logs the echo with its latency, so you can see what a healthy connection looks like before you test your own endpoint.

WebSocket close codes: what 1000, 1006 and the rest mean

When a WebSocket closes, it closes with a code, and the code is the diagnosis. 1000 is a normal closure — both sides agreed to end it, and nothing is wrong. 1001 means an endpoint is going away, a server shutting down or a page navigating elsewhere. 1006 is the one to watch: abnormal closure means the connection died without a close frame at all — the network dropped, the server crashed, a proxy killed it — and no reason was ever sent, because there was nobody left to send it. 1011 is a server error, 1008 a policy violation such as a message that broke the server’s rules, and 1005 means no status code was present at all.

Read the code before you read anything else, because it tells you where to look: 1006 points at the network path and the server process, not at your message; 1008 points at what you sent; 1011 points at the server’s own handling. The tester names each code as it appears, with the reason the server sent alongside it when there is one. Two honest limits belong here. First, a close code is a symptom, not a root cause — 1006 says the connection died, not why, and finding the why still takes server logs. Second, the browser’s WebSocket API does not expose the handshake request or response headers, so no browser tool can show them to you; what this tester reports is state transitions, timing and frames, which is everything the browser actually lets a page see.

SSE: events, ids, retries — and why fetch beats EventSource for testing

An SSE stream is plain text with a small grammar. Each event is a block of lines: data: carries the payload (and a single event may carry several data: lines, joined with newlines), event: names the event type so the client can tell a notification from a heartbeat, id: sets the event id the browser sends back as Last-Event-ID when it reconnects, and retry: tells the client how long to wait before reconnecting, in milliseconds. Lines starting with a colon are comments, usually heartbeats that keep proxies from closing an idle stream. If the server sends anything else — HTML, JSON without the SSE framing, or a stream with the wrong Content-Type — a browser EventSource will fail silently or never fire, and you will be left guessing which half is wrong.

That is why the tester connects with fetch and a ReadableStream instead of EventSource. Fetch shows the HTTP status and the Content-Type header, so a 404, a 500, or a response that claims to be text/html instead of text/event-stream is visible immediately, and the stream can be stopped cleanly instead of relying on EventSource’s automatic reconnect. The trade-off is honest: fetch does not reconnect for you, so a dropped SSE stream stays dropped until you connect again — which is exactly what you want in a test, where an automatic reconnect would hide the drop you are trying to see.

How to test an endpoint with the companion tool

Pick a mode and paste a URL. In WebSocket mode the URL must start with ws:// or wss://; in SSE mode it must start with http:// or https:// — anything else is rejected with a clear error, because a URL with the wrong scheme cannot connect and a vague failure would waste your time. Then connect: in WebSocket mode you can send the preset ping or your own message and watch the reply arrive in the log; in SSE mode events appear as the server sends them, each with its timestamp and type. The status panel shows the connection state and, in SSE mode, the HTTP status and whether the Content-Type is text/event-stream.

If you have no endpoint of your own yet, use the demo buttons. The WebSocket demo connects to the public echo service at wss://echo.websocket.events, sends the ping above and logs the echo with its latency; the SSE demo connects to the Wikimedia recent-change stream at https://stream.wikimedia.org/v2/stream/recentchange, which emits a flow of recentchange events within seconds, no account needed. Both demos run entirely in your browser — the connection goes straight from your machine to the endpoint, nothing passes through a server of ours — and the log can be cleared, copied, or downloaded as a text or JSON file to keep as a record.

Reading the result: a healthy connection, and what to fix first

A healthy WebSocket test reads like this: the state moves from connecting to open quickly, the ping goes out, the echo comes back with a low, steady latency, and the connection closes with code 1000 when you ask it to. A healthy SSE test reads like this: HTTP 200, Content-Type: text/event-stream, and events arriving at the rate the server promises, each with a data: payload you can read. Keep the log: a latency that creeps up over minutes, or events that arrive in bursts instead of steadily, is the early warning of a server or network under strain.

Fix in the order the evidence points. A 1006 close means the path or the server died — check the server process, the proxy idle timeout, and whether an intermediate closed the connection. An SSE stream with the wrong Content-Type means the server is not configured to serve events at that URL — fix the response headers before anything else. No events at all on an SSE stream that returns 200 usually means the endpoint needs authentication or a parameter you have not supplied, and the status and headers the tester shows are the fastest way to see that. And remember what the tool cannot tell you: it cannot see handshake headers, it cannot read your server configuration, and it cannot test what happens under real load — for that you need the server’s own logs and a load test.

Try it yourself: a minimal WebSocket echo and SSE reader

// WebSocket echo: connect, send a ping, log the reply
const ws = new WebSocket('wss://echo.websocket.events');
ws.addEventListener('open', () => {
  ws.send(JSON.stringify({ type: 'ping', message: 'hello from sysosx' }));
});
ws.addEventListener('message', (event) => console.log('echo:', event.data));
ws.addEventListener('close', (event) => console.log('closed:', event.code));

// Server-sent events: read the stream with fetch, not EventSource
const res = await fetch('https://stream.wikimedia.org/v2/stream/recentchange');
console.log(res.status, res.headers.get('content-type'));
const reader = res.body.getReader();
const decoder = new TextDecoder();
for (;;) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log(decoder.decode(value, { stream: true }));
}

Sources

Frequently asked questions

Why can’t the tester show the WebSocket handshake headers?

Because the browser does not expose them. The built-in WebSocket API reports state changes, messages, errors and the close code, but the HTTP request and response of the upgrade handshake stay inside the browser — no page, and no browser tool, can read them. To inspect handshake headers you need a proxy or a packet capture, not a web page. The SSE side is different: because the tester reads the stream with fetch instead of EventSource, it can show the HTTP status and the Content-Type header directly.

Can I test a local endpoint, like ws://localhost:8080?

Yes. The tester runs entirely in your browser, so it can connect to anything your browser can reach, including a server on your own machine. One browser rule still applies: the tool page is served over https, and a secure page may only open plain ws:// connections to localhost — ws://localhost works, but a plain ws:// URL to any other host is blocked as mixed content. For anything beyond your own machine, serve the endpoint over wss://, which is the right choice in production anyway.

Is anything I type or receive uploaded anywhere?

No. The tester makes the connection directly from your browser to the endpoint you type — there is no proxy server, nothing is sent to us, and the URLs and messages you enter are never stored. The log lives in the page only, and downloading it saves a file on your own machine. That also means the tester can only test endpoints your browser can reach: an endpoint behind a firewall or VPN that your browser cannot see will fail here exactly as it would fail for any other web page.