WebSocket Interception
To capture WebSocket messages, you must first enable interception. You can then retrieve messages usingrunner.getWebsocketMessages().
Event Object
| Field | Type | Description |
|---|---|---|
url | string | The URL of the WebSocket connection. |
type | string | Either send (client to server) or receive (server to client). |
message | string | The payload data of the frame. |
opcode | number | The WebSocket opcode (e.g., 1 for text, 2 for binary). |
timestamp | number | Browser timestamp of the event. |
Server-Sent Events (SSE)
Similarly, you can enable SSE interception and poll for messages.Event Object
| Field | Type | Description |
|---|---|---|
url | string | The URL of the event stream. |
eventName | string | The name of the event (defaults to message). |
eventId | string | The ID of the event if provided by the server. |
message | string | The payload data. |
timestamp | number | Browser timestamp of the event. |
Best Practices
Real-time streams can be high-volume. To prevent memory issues or database spam:- Filter early: Only process or publish messages that contain the data you need.
- Handle state: Use a local variable in your script to accumulate data and only call
publishItemsonce a specific condition is met or the run is about to finish. - Wait for completion: Use
runner.waitFor()to give the stream enough time to arrive before the script terminates.