Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

ReadableStream with Axios not working in Safari, but working in Chrome and Firefox

I'm building a chat app with AI API like ChatGPT. I'm streaming back the responses, which works fine in chrome and firefox, but does not in Safari. There I always get this error:

[Log] Error: (handleError.ts, line 8)
AxiosError

cause: TypeError: ReadableByteStreamController is not implemented

column: 28

config: {transitional: {silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false}, adapter: "fetch", transformRequest: Array, transformResponse: Array, timeout: 0, …}

line: 1697

message: "ReadableByteStreamController is not implemented"

name: "TypeError"

request: Request

body: ReadableStream {locked: true}

bodyUsed: true

cache: "default"

credentials: "same-origin"

destination: ""

headers: Headers {append: function, delete: function, get: function, has: function, set: function, …}

integrity: ""

keepalive: false

method: "POST"

mode: "cors"

redirect: "follow"

referrer: "about:client"

referrerPolicy: ""

signal: AbortSignal {aborted: false, reason: undefined, onabort: null, throwIfAborted: function, addEventListener: function, …}

url: "http://localhost:3000/conversations/cht_GHyzT4yB35_363xN"

Request Prototyp

sourceURL: "http://localhost:5173/node_modules/.vite/deps/axios.js?v=e4786436"

stack: "AxiosError@http://localhost:5173/node_modules/.vite/deps/axios.js?v=e4786436:375:2…"

AxiosError Prototyp

For my API Calls, I'm using a wrapper around Axios, which makes the streaming request like this:

 async stream(data: any) {
        try {
            console.log("Sending request")
            const response = await instance.post(this.baseUrl, data, { headers: {
                'Accept': 'text/event-stream',
              },
              responseType: 'stream',
              adapter: 'fetch'
             });
            // Handle response data
            console.log("Request sent")
            return { data: response.data, error: null };
        } catch (error) {
            // Handle errors
            const handledError = await handleError(error);
            return { data: null, error: handledError };
        }
    }

With this, the "Request Sent" does not get logged to the console, so the error has to be in the post request.

The request on safari finished quickly, probably with the first chunk of data coming in. in the api logs it says for requests with safari they only take a couple ms to finish.

Answer*

Cancel
3
  • Can you show your workaround. Also see developer.mozilla.org/en-US/docs/Web/API/… (note it is unsupported in Safari) - though it seems strange that axios would have built on something with a major browser missing. Commented Jul 6, 2024 at 11:24
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Jul 6, 2024 at 23:21
  • @DarrenCook edited the answer. Maybe I did something wrong, but as you linked the docs it is not supported by Safari, and that was always the error that I got. Commented Jul 7, 2024 at 15:39