-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Different behaviour from native Chrome ReadableStream #10
Comments
It's not restricted to serviceworkers. The polyfill isn't working in the simplest Response case: <html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Simple Stream Pump</title>
</head>
<body>
<h1>Simple Stream Pump</h1>
<p>The left tortoise is the original, the right one is created using a custom stream.</p>
<img src="tortoise.png" width="150" height="84" alt="Tortoise Original">
<img src="tortoise.png" width="150" height="84" alt="Tortoise Copy" id="target">
<script src="polyfill.min.js"></script>
<script>
const image = document.getElementById('target');
// Fetch the original image
fetch('./tortoise.png')
// Retrieve its body as ReadableStream
.then(response => {
const reader = response.body.getReader();
return new ReadableStream({
start(controller) {
return pump();
function pump() {
return reader.read().then(({ done, value }) => {
// When no more data needs to be consumed, close the stream
if (done) {
controller.close();
return;
}
// Enqueue the next data chunk into our target stream
controller.enqueue(value);
return pump();
});
}
}
})
})
.then(stream => new Response(stream))
.then(response => response.blob())
.then(blob => URL.createObjectURL(blob))
.then(url => console.log(image.src = url))
.catch(err => console.error(err));
</script>
</body>
</html> |
This is because of this line in the polyfill. Even though Chrome has native support for It's quite annoying to deal with polyfilled and native stream implementations. Chrome supports I feel like the polyfill should have a better interop story for native streams. Perhaps it could have a non-standard |
The ReadableStream polyfill has different behaviour from Chrome's native ReadableStream when used as the first argument in a Response object from a ServiceWorker. The polyfill doesn't seem to work at all.
I'm working on a minimal way to reproduce the issue, but is there any obvious differences between the APIs that might explain this?
The text was updated successfully, but these errors were encountered: