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


var readyState = aWebSocket.readyState;


One of the following unsigned short values:

Value State Description
0 CONNECTING Socket has been created. The connection is not yet open.
1 OPEN The connection is open and ready to communicate.
2 CLOSING The connection is in the process of closing.
3 CLOSED The connection is closed or couldn't be opened.


Specification Status Comment
HTML Living Standard
The definition of 'WebSocket: readyState' in that specification.
Living Standard Initial definition

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
readyStateChrome Full support 43Edge Full support 12Firefox Full support 19IE Full support 10Opera Full support 30Safari Full support 10WebView Android Full support 43Chrome Android Full support 43Firefox Android Full support 19Opera Android Full support 30Safari iOS Full support 10Samsung Internet Android Full support 4.0


Full support  
Full support