Skip to main content
Figranium exposes two Server-Sent Events endpoints, and the SDK surfaces both as AsyncIterable<StreamEvent>. You consume them with for await, cancel them with an AbortSignal, and read event names, IDs, and parsed data straight off each event.

Streams

Both take an optional RequestOptions argument (signal, timeoutMs, headers).

StreamEvent shape

The SDK tries JSON.parse on the data lines. If parsing fails, data is the raw string and raw still contains the original payload.

Consume execution events

1

Create a client

Initialize the SDK with your API key.
2

Iterate the stream

Use for await to consume events as they arrive.
Iteration ends when the server closes the connection or when your loop breaks. Breaking out of the loop cancels the underlying reader.

Cancel a stream

Streams honor AbortSignal. Aborting cancels the reader and terminates iteration.

Terminal timeouts

Streams have no default timeout. Set timeoutMs only when you want a hard deadline; the stream aborts as soon as the timer fires:

Typed payloads

stream() accepts a generic type parameter that types the parsed data:
Because the server may add fields over time, keep type guards defensive and treat unknown status values as forward-compatible additions.

Selector stream from a headful browser

The selector stream reports element highlights from a headful browser session. Use it to power visual inspectors:
See Browser resource for opening, inspecting, and stopping headful sessions.

Errors

Streams throw FigraniumError in the same conditions as regular requests, plus:
  • EMPTY_STREAM: the response arrived with no body.
  • REQUEST_ABORTED: the caller aborted, or the terminal timeoutMs fired.
See Errors for the full error surface.
For long-running streams, prefer AbortSignal over timeoutMs so you can stop cleanly when your application state changes.