datawhalechina/hello-agents · error

浏览器不支持流式响应,无法获取研究进度

Error message

浏览器不支持流式响应,无法获取研究进度

What it means

Guard in the SSE client: after a successful (2xx) response to POST /research/stream, it checks response.body (a ReadableStream). If the browser does not expose a body stream, reading progress via getReader() is impossible, so it throws this error. All evergreen browsers support fetch body streams; hitting it means an old browser, a polyfilled fetch, or a non-standard webview.

Source

Thrown at Co-creation-projects/JJason-DeepCastAgent/frontend/src/services/api.ts:52

    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Accept: "text/event-stream"
    },
    body: JSON.stringify(payload),
    signal: options.signal
  });

  if (!response.ok) {
    const errorText = await response.text().catch(() => "");
    throw new Error(
      errorText || `研究请求失败,状态码:${response.status}`
    );
  }

  const body = response.body;
  if (!body) {
    throw new Error("浏览器不支持流式响应,无法获取研究进度");
  }

  const reader = body.getReader();
  const decoder = new TextDecoder("utf-8");
  let buffer = "";

  while (true) {
    const { value, done } = await reader.read();
    buffer += decoder.decode(value || new Uint8Array(), { stream: !done });

    let boundary = buffer.indexOf("\n\n");
    while (boundary !== -1) {
      const rawEvent = buffer.slice(0, boundary).trim();
      buffer = buffer.slice(boundary + 2);

      if (rawEvent.startsWith("data:")) {
        const dataPayload = rawEvent.slice(5).trim();
        if (dataPayload) {

View on GitHub (pinned to 606a07d341)

Solutions

  1. Feature-detect and fall back to a non-streaming JSON endpoint (or XHR + readline polyfill) when response.body is missing
  2. Upgrade/require a modern browser (Chrome/Firefox/Edge/Safari 10.1+) and show a clear compatibility banner otherwise
  3. In tests, polyfill ReadableStream (web-streams-polyfill) so getReader() exists

Example fix

// before
const body = response.body;
if (!body) {
    throw new Error("浏览器不支持流式响应,无法获取研究进度");
}

// after
const body = response.body;
if (!body) {
    // degrade to non-streaming endpoint
    const r = await fetch(`${baseURL}/research`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
    return onEvent(JSON.stringify({ type: 'final', data: await r.json() }));
}
Defensive patterns

Strategy: fallback

Validate before calling

const supportsStreams = typeof ReadableStream !== 'undefined' && typeof (fetch('').body) !== 'undefined'; if (!supportsStreams) useNonStreamingEndpoint();

Type guard

function hasBodyStream(resp) { return typeof resp.body?.getReader === 'function'; }

Try / catch

if (!response.body) { return await nonStreamingFallback(payload); }

Prevention

When it happens

Trigger: Running the app in IE11 or old Edge/Safari (<10.1), an environment where fetch is polyfilled by whatwg-fetch (which historically did not expose body streams), or a locked-down embedded webview with an old engine. It is NOT thrown for server errors — those are caught by the !response.ok branch above.

Common situations: Corporate environments forcing IE mode, old iOS Safari via intrinsic webview, testing in JSDOM/happy-dom without a body stream polyfill, React Native webview with legacy fetch.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/3aee9dc56d2e8329. Report an issue: GitHub.