Skip to content

feat: add Server-Sent Events (SSE) support#60

Merged
GrinZero merged 1 commit into
GrinZero:mainfrom
BAIXIONGSODA:feat/sse-support
Apr 17, 2026
Merged

feat: add Server-Sent Events (SSE) support#60
GrinZero merged 1 commit into
GrinZero:mainfrom
BAIXIONGSODA:feat/sse-support

Conversation

@BAIXIONGSODA
Copy link
Copy Markdown
Collaborator

@BAIXIONGSODA BAIXIONGSODA commented Apr 16, 2026

PR: feat: add Server-Sent Events (SSE) support

Summary

Add support for Server-Sent Events (SSE) / EventStream in Chrome DevTools Network panel.

Problem

Previously, SSE responses (content-type: text/event-stream) were not properly displayed in DevTools because:

  1. response.clone().arrayBuffer() waits for the entire stream to end before returning data
  2. For long-running SSE connections (like AI chat completions), the stream never ends, so no data is shown
  3. Even after stream ends, only the final combined data is shown without individual events

Solution

  • Detect SSE responses by checking text/event-stream content-type
  • Use ReadableStream to read chunks incrementally
  • Parse SSE events (data, event, id fields) according to the SSE specification
  • Send each event via Network.eventSourceMessageReceived CDP protocol
  • Mark SSE responses as EventSource type in the Network panel

Changes

  • packages/network-debugger/src/core/fetch.ts: Add SSE stream handling
  • packages/network-debugger/src/fork/module/network/index.ts: Add eventSourceMessage handler
  • Added comprehensive tests for SSE functionality
  • Added SSE example endpoint in koa-esm demo

Testing

All 841 tests pass including new SSE-specific tests.

- Add SSE stream detection in fetch proxy (text/event-stream content-type)
- Parse SSE events (data, event, id fields) and send via eventSourceMessage
- Handle Network.eventSourceMessageReceived CDP protocol for DevTools display
- Identify SSE responses as 'EventSource' type in Network panel
- Add comprehensive tests for SSE functionality
- Add SSE example endpoint in koa-esm demo

This enables real-time viewing of SSE events in Chrome DevTools Network panel,
similar to how WebSocket messages are displayed.
@GrinZero
Copy link
Copy Markdown
Owner

😊Thanks for your PR, I'll take a look over the weekend or on Friday

@GrinZero
Copy link
Copy Markdown
Owner

It's great, it looks like it's done to the basics mvp.

@GrinZero GrinZero merged commit 2052d4d into GrinZero:main Apr 17, 2026
1 check passed
@GrinZero
Copy link
Copy Markdown
Owner

If you have time, you can improve it later:

  1. Evenstream tab seems to have nothing
  2. No way to know where the request was made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants