WebSocketsBaseline · Widely available
The WebSocket API opens a two-way communication channel between the user's browser and a server.
Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Jul 29, 2015. Widely available since Jan 29, 2018.
Browser support
DesktopChrome
1–4Not supported
5+Supportedsince May 25, 2010
Current: 155Edge
12+Supportedsince Jul 29, 2015
Current: 154Firefox
1–10Not supported
11+Supportedsince Mar 13, 2012
Current: 157Safari
1–4Not supported
5+Supportedsince Jun 7, 2010
Current: 27MobileChrome Android
18+Supportedsince Jun 27, 2012
Current: 155Firefox Android
4–10Not supported
14+Supportedsince Jun 26, 2012
Current: 157Safari iOS
1–4Not supported
4.2+Supportedsince Nov 22, 2010
Current: 27How to use
This feature is Baseline widely available — use it freely, no fallback needed.
Example
JS
const socket = new WebSocket("wss://example.com/chat");
socket.addEventListener("open", () => socket.send(JSON.stringify({ hello: "world" })));
socket.addEventListener("message", (event) => console.log(JSON.parse(event.data)));
socket.addEventListener("close", () => console.log("disconnected"));Feature detection
JS · check before using
if ("WebSocket" in globalThis) {
// WebSocket is available
} else {
// load a polyfill or use a fallback
}Documentation (MDN)
Specification
Usage share
Sub-features
Support for each part of the feature (31). The overall table above shows when the whole feature works.
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| CloseEvent | 15 | 12 | 8 | 6 | 18 | 8 | 6 |
| CloseEvent.CloseEvent | 16 | 14 | 11 | 6 | 18 | 14 | 6 |
| CloseEvent.code | 15 | 12 | 8 | 6 | 18 | 8 | 6 |
| CloseEvent.reason | 15 | 12 | 8 | 6 | 18 | 8 | 6 |
| CloseEvent.wasClean | 15 | 12 | 8 | 6 | 18 | 8 | 6 |
| WebSocket | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.WebSocket | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.WebSocket.url_parameter_http_https_relative | 125 | 125 | 124 | 17.3 | 125 | 124 | 17.3 |
| WebSocket.binaryType | 15 | 12 | 11 | 6 | 18 | 14 | 6 |
| WebSocket.bufferedAmount | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.close | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.close_event | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.error_event | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.extensions | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| WebSocket.message_event | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.open_event | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.protocol | 15 | 12 | 11 | 6 | 18 | 14 | 6 |
| WebSocket.protocol_rfc_6455 | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| WebSocket.readyState | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
| WebSocket.send | 5 | 12 | 11 | 5 | 18 | 14 | 4.2 |
Show 11 more
| Sub-feature | Chrome | Edge | Firefox | Safari | Chrome Android | Firefox Android | Safari iOS |
|---|---|---|---|---|---|---|---|
| WebSocket.url | 18 | 12 | 11 | 6 | 18 | 14 | 6 |
| WebSocket.worker_support | 5 | 12 | 37 | 5 | 18 | 37 | 5 |
| WebSocketError | 124 | 124 | ✕ | ✕ | 124 | ✕ | ✕ |
| WebSocketError.WebSocketError | 124 | 124 | ✕ | ✕ | 124 | ✕ | ✕ |
| WebSocketError.closeCode | 124 | 124 | ✕ | ✕ | 124 | ✕ | ✕ |
| WebSocketError.reason | 124 | 124 | ✕ | ✕ | 124 | ✕ | ✕ |
| http.headers.Sec-WebSocket-Accept | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| http.headers.Sec-WebSocket-Extensions | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| http.headers.Sec-WebSocket-Key | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| http.headers.Sec-WebSocket-Protocol | 16 | 12 | 11 | 6 | 18 | 14 | 6 |
| http.headers.Sec-WebSocket-Version | 16 | 12 | 11 | 6 | 18 | 14 | 6 |