{"record":{"id":"3aee9dc56d2e8329","repo":"datawhalechina/hello-agents","slug":"error-3aee9d","errorCode":null,"errorMessage":"浏览器不支持流式响应，无法获取研究进度","messagePattern":"浏览器不支持流式响应，无法获取研究进度","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"Co-creation-projects/JJason-DeepCastAgent/frontend/src/services/api.ts","lineNumber":52,"sourceCode":"    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n      Accept: \"text/event-stream\"\n    },\n    body: JSON.stringify(payload),\n    signal: options.signal\n  });\n\n  if (!response.ok) {\n    const errorText = await response.text().catch(() => \"\");\n    throw new Error(\n      errorText || `研究请求失败，状态码：${response.status}`\n    );\n  }\n\n  const body = response.body;\n  if (!body) {\n    throw new Error(\"浏览器不支持流式响应，无法获取研究进度\");\n  }\n\n  const reader = body.getReader();\n  const decoder = new TextDecoder(\"utf-8\");\n  let buffer = \"\";\n\n  while (true) {\n    const { value, done } = await reader.read();\n    buffer += decoder.decode(value || new Uint8Array(), { stream: !done });\n\n    let boundary = buffer.indexOf(\"\\n\\n\");\n    while (boundary !== -1) {\n      const rawEvent = buffer.slice(0, boundary).trim();\n      buffer = buffer.slice(boundary + 2);\n\n      if (rawEvent.startsWith(\"data:\")) {\n        const dataPayload = rawEvent.slice(5).trim();\n        if (dataPayload) {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/JJason-DeepCastAgent/frontend/src/services/api.ts#L34-L70","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Feature-detect and fall back to a non-streaming JSON endpoint (or XHR + readline polyfill) when response.body is missing","Upgrade/require a modern browser (Chrome/Firefox/Edge/Safari 10.1+) and show a clear compatibility banner otherwise","In tests, polyfill ReadableStream (web-streams-polyfill) so getReader() exists"],"exampleFix":"// before\nconst body = response.body;\nif (!body) {\n    throw new Error(\"浏览器不支持流式响应，无法获取研究进度\");\n}\n\n// after\nconst body = response.body;\nif (!body) {\n    // degrade to non-streaming endpoint\n    const r = await fetch(`${baseURL}/research`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });\n    return onEvent(JSON.stringify({ type: 'final', data: await r.json() }));\n}","handlingStrategy":"fallback","validationCode":"const supportsStreams = typeof ReadableStream !== 'undefined' && typeof (fetch('').body) !== 'undefined'; if (!supportsStreams) useNonStreamingEndpoint();","typeGuard":"function hasBodyStream(resp) { return typeof resp.body?.getReader === 'function'; }","tryCatchPattern":"if (!response.body) { return await nonStreamingFallback(payload); }","preventionTips":["Feature-detect ReadableStream before advertising streaming features","Keep a non-streaming endpoint as a fallback","Polyfill in test environments (web-streams-polyfill)"],"tags":["sse","browser-compatibility","readable-stream","feature-detection"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}