Reputation: 5962
Both MDN, caniuse.com, and Microsoft Edge's own "Platform Status" page state that Microsoft Edge supports ReadableStream
since build number 16299+ (released 09/26/2017).
However, when I try to create a ReadableStream in the latest Edge (Microsoft Edge 44.17763.1.0, Microsoft EdgeHTML 18.17763) I get the error Function expected
.
Both
new ReadableStream()
and
new ReadableStream({
start: function(controller) {},
pull: function(controller) {},
cancel: function() {}
})
throw the Function expected
error. Omitting the new
also doesn't work.
What am I doing wrong?
Upvotes: 1
Views: 426
Reputation: 21656
You could try to use the following code to read the data in Edge:
function pump(reader, context) {
return reader.read().then(function (result) {
if (result.done) {
console.log('ReadableStreamReader: complete! Received ' + context.receivedLength);
} else {
var chunk = result.value;
console.log('ReadableStreamReader: Partial chunk, chunkSize = ' + chunk.byteLength);
context.receivedLength += chunk.byteLength;
return pump(reader, context);
}
}).catch(function (e) {
throw e;
});
}
function fetchVideo() {
var url = 'xxxxxxxx';
var headers = new Headers();
var param = {
method: 'GET',
headers: headers,
mode: 'cors',
cache: 'default'
};
var context = {
receivedLength: 0
};
fetch(url, param).then(function (res) {
console.log('Content-Length: ' + res.headers.get('Content-Length'));
return pump(res.body.getReader(), context);
}).catch(function (e) {
throw e;
});
}
Upvotes: 0
Reputation: 21656
According to the ReadableSream doc example, I reproduce the issue on my Edge 44, but it works well on Edge 42. So, I suppose the issue is related to Edge 44, as a workaround I suggest you could try to downgrade the Edge version to 42 version. And, I will try to feedback this issue to Edge Platform.
Upvotes: 0