JavaScript fetch stream not working on iOS

1 day ago 3
ARTICLE AD BOX

I'm trying to read the stream response from my API in iOS (specifically Safari, but seems to be the same issue for any browser on iOS).

The issue appears to be when attempting to read the stream, in this case:

for await (const byteArray of stream) { ... }

Which throws an exception will be thrown on iOS:

TypeError: undefined is not a function (near '...byteArray of stream...')

Stream is, in all environments, a ReadableStream as far as I can tell. But there is a difference and I cannot work out why or what to do about it.

In iOS it represents as:

ReadableStream locked: false ReadableStream Prototype cancel(reason) constructor: function() getReader() locked pipeThrough(dest, options) pipeTo(streams, options) tee() Symbol(Symbol.toStringTag): "ReadableStream" Object Prototype

In Windows:

ReadableStream {locked: false} locked: false [[Prototype]]: ReadableStream cancel: ƒ cancel() getReader: ƒ getReader() locked: (…) pipeThrough: ƒ pipeThrough() pipeTo: ƒ pipeTo() tee: ƒ tee() values: ƒ values() constructor: ƒ ReadableStream() Symbol(Symbol.asyncIterator): ƒ values() Symbol(Symbol.toStringTag): "ReadableStream" get locked: ƒ locked() [[Prototype]]: Object

It would appear that the version in iOS is not iterable, which would explain the problem, but I cannot understand why or what the correct way to read the stream should be.

Read Entire Article