1. Quick connection with the helper
Usewebsocket(url, options) when you want a connected socket from a single await.
2. Constructor style
Usenew WebSocket(...) when you want browser-like shape with CONNECTING state.
3. Sessions, impersonation, and cookies
For authenticated flows, create a session, log in with HTTP, then open the WebSocket with the same session.session.websocket(...) reuses the session transport and context.
4. Event model
Event handlers and listeners follow familiar WebSocket patterns.5. Binary messages
binaryType defaults to nodebuffer. You can set it to arraybuffer or blob.
6. Close behavior
Useclose() or close(code, reason).
1000 or a code in the 3000 to 4999 range.
If you pass a reason, keep it to 123 UTF-8 bytes or fewer.
7. Large frames and message limits
Incoming WebSocket data is bounded by default to avoid unbounded memory use. If a provider sends a very large payload in one frame, you may see an error likeSpace limit exceeded: Message too long.
Raise maxFrameSize when the peer sends large unfragmented frames. Raise maxMessageSize
when the peer sends very large fragmented messages.
Related
- API reference:
websocket() - Session API:
createSession() - Session concepts: /concepts/sessions