For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.

JavaScript: getWebSocketConstructor

Returns the best available WebSocket constructor for the current runtime.

Examples

Example with error handling

try {
  const WS = WebSocketFactory.getWebSocketConstructor()
  const socket = new WS('wss://example.com/socket')
} catch (error) {
  console.error('WebSocket not available in this environment.', error)
}