SSE Chaos
Server-Sent Events use EventSource, not fetch, so streaming UI needs a separate chaos surface. Chaos Maker wraps globalThis.EventSource and intercepts inbound MessageEvents before app listeners see them.
Config shape
Section titled “Config shape”await injectChaos(page, { seed: 42, sse: { drops: [{ urlPattern: '/events', probability: 0.1 }], delays: [{ urlPattern: '/events', delayMs: 500, probability: 1 }], corruptions: [{ urlPattern: '/events', strategy: 'truncate', probability: 0.05 }], closes: [{ urlPattern: '/events', afterMs: 2000, probability: 0.02 }], },});All SSE rules support urlPattern, probability, and request counting with onNth, everyNth, or afterN. Drop, delay, and corruption rules also support eventType.
Event types
Section titled “Event types”sse: { drops: [ { urlPattern: '/events', eventType: 'token', probability: 0.2 }, { urlPattern: '/events', eventType: '*', probability: 0.05 }, ],}eventType: 'message' targets unnamed default events. A named value targets event: frames with that name. eventType: '*' applies to every data event and automatically attaches when the app subscribes to new named events.
Events
Section titled “Events”Chaos Maker emits:
| Event | Meaning |
|---|---|
sse:drop | An inbound SSE event was skipped. |
sse:delay | An inbound event was scheduled for later delivery. |
sse:corrupt | event.data was rewritten. |
sse:close | The EventSource was closed by chaos. |
Each SSE event includes detail.url. Drop, delay, and corruption events include detail.eventType, and corruption events also include detail.strategy. Close events include detail.reason instead of detail.eventType.
Targeting with matchers
Section titled “Targeting with matchers”Every SSE rule accepts the cross-transport matcher surface: urlPattern, hostname, queryParams, and the matcher: 'name' reference into a registered NamedMatcher. Mix and match exactly like network rules, with the same matcher_inline_conflict validation guarantee covering both the matcher-plus-inline conflict and the no-targeting case.
await injectChaos(page, { sse: { drops: [ { urlPattern: '/feed', queryParams: { topic: 'alerts' }, probability: 1, }, ], },});await injectChaos(page, { matchers: { realtimeApi: { hostname: /realtime/ }, }, sse: { drops: [ { matcher: 'realtimeApi', probability: 0.2 }, ], },});See Advanced matchers for the full field semantics and debug attribution.
Preset
Section titled “Preset”import { presets } from '@chaos-maker/core';
await injectChaos(page, { ...presets.unreliableEventStream, seed: 42,});unreliableEventStream combines low-probability drops, a 200 ms delay, and occasional closes.