v154 · websocket options
Both forms, one server
Real connections to a same-origin echo endpoint, opened three ways. The server sends back what it was offered and what it chose, so each row is confirmed from both ends — not inferred from the client object alone.
Open three sockets
The endpoint is /public/echo-socket, served by this site. It knows echo.v2, echo, chat and soap, and picks the first of those the client offered — so the result depends on what you type above.
| construction | opened? | client protocol | server saw offered | server chose |
|---|---|---|---|---|
| Not run yet. | ||||
code path
const url = "/public/echo-socket"; // resolved against this origin
new WebSocket(url, "chat"); // a single string
new WebSocket(url, ["chat", "echo"]); // a sequence
new WebSocket(url, { protocols: ["chat", "echo"] }); // Chrome 154
// All three send the same Sec-WebSocket-Protocol header, which is why
// the server's view of them is identical.