WebSocket: readyState property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

The WebSocket.readyState read-only property returns the current state of the WebSocket connection.

Value

A number which is one of the four possible state constants defined on the WebSocket interface:

WebSocket.CONNECTING (0)

Socket has been created. The connection is not yet open.

WebSocket.OPEN (1)

The connection is open and ready to communicate.

WebSocket.CLOSING (2)

The connection is in the process of closing.

WebSocket.CLOSED (3)

The connection is closed or couldn't be opened.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Opera Safari Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet WebView Android
readyState 5 12 7 12.1 5 18 7 12.1 4.2 1.0 4.4

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/readyState