@@ -26,7 +26,7 @@ This library comes in multiple variants:
26
26
Recommended for use in web apps supporting older browsers through a ` <script> ` tag.
27
27
28
28
Each variant also includes TypeScript type definitions, compatible with the DOM type definitions for streams included in TypeScript.
29
- These type definitions require TypeScript version 4 .7 or higher.
29
+ These type definitions require TypeScript version 5 .7 or higher.
30
30
31
31
In version 4, the list of variants was reworked to have more modern defaults and to reduce the download size of the package.
32
32
See the [ migration guide] [ migrating ] for more information.
@@ -57,6 +57,45 @@ import "web-streams-polyfill/polyfill";
57
57
const readable = new ReadableStream ();
58
58
```
59
59
60
+ > [ !WARNING]
61
+ > ** Compatibility with built-in streams**
62
+ >
63
+ > If your browser or runtime already supports Web Streams, loading the polyfill will * unconditionally* replace
64
+ > the global ` ReadableStream ` , ` WritableStream ` and ` TransformStream ` classes with the polyfill's versions.
65
+ > However, browser APIs like ` fetch() ` will still return stream objects using the * built-in* stream classes.
66
+ > This can lead to surprising results, for example ` Response.body ` will not be ` instanceof ReadableStream `
67
+ > after the polyfill replaces the global ` ReadableStream ` class.
68
+ >
69
+ > Consider using ` ReadableStream.from() ` to convert a built-in stream (e.g. from ` fetch() ` ) to a polyfilled stream,
70
+ > or try [ loading the polyfill conditionally] ( #conditional-loading ) if you don't always need the polyfill.
71
+ >
72
+ > See [ issue #20 ] ( https://github.com/MattiasBuelens/web-streams-polyfill/issues/20 ) for more details.
73
+
74
+ ## Conditional loading
75
+
76
+ Web Streams are [ widely supported] [ mdn-browser-compatibility ] across all modern browsers
77
+ (including Chrome, Firefox and Safari) and server runtimes (including Node.js, Deno and Bun).
78
+ Consider using feature detection to check if your platform's built-in streams implementation can fulfill your app's needs,
79
+ and load the polyfill only when needed.
80
+
81
+ Here are a couple of examples to load the polyfill conditionally:
82
+ ``` js
83
+ // Check for basic ReadableStream support
84
+ if (! globalThis .ReadableStream ) {
85
+ await import (" web-streams-polyfill/polyfill" );
86
+ }
87
+
88
+ // Check for basic TransformStream support
89
+ if (! globalThis .TransformStream ) {
90
+ await import (" web-streams-polyfill/polyfill" );
91
+ }
92
+
93
+ // Check for async iteration support
94
+ if (typeof globalThis .ReadableStream ? .prototype [Symbol .asyncIterator ] !== ' function' ) {
95
+ await import (" web-streams-polyfill/polyfill" );
96
+ }
97
+ ` ` `
98
+
60
99
## Compatibility
61
100
62
101
The ` polyfill` and ` ponyfill` variants work in any ES2015-compatible environment.
@@ -80,7 +119,7 @@ When using TypeScript, make sure your [`moduleResolution`](https://www.typescrip
80
119
81
120
## Compliance
82
121
83
- The polyfill implements [ version ` fa4891a ` (3 Dec 2024 )] [ spec-snapshot ] of the streams specification.
122
+ The polyfill implements [version ` 080852c ` (3 Apr 2025 )][spec-snapshot] of the streams specification.
84
123
85
124
The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.
86
125
The polyfill aims to pass all tests, although it allows some exceptions for practical reasons:
@@ -104,6 +143,7 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
104
143
105
144
[spec]: https://streams.spec.whatwg.org
106
145
[ref-impl]: https://github.com/whatwg/streams
146
+ [mdn-browser-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API#browser_compatibility
107
147
[ponyfill]: https://github.com/sindresorhus/ponyfill
108
148
[migrating]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/MIGRATING.md
109
149
[promise-support]: https://kangax.github.io/compat-table/es6/#test-Promise
@@ -112,8 +152,8 @@ Thanks to these people for their work on [the original polyfill][creatorrr-polyf
112
152
[ws-controller-signal]: https://streams.spec.whatwg.org/#ws-default-controller-signal
113
153
[abortcontroller-polyfill]: https://www.npmjs.com/package/abortcontroller-polyfill
114
154
[mdn-byob-read]: https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamBYOBReader/read
115
- [ spec-snapshot ] : https://streams.spec.whatwg.org/commit-snapshots/fa4891a35ff05281ff8ed66f8ad447644ea7cec3 /
116
- [ wpt ] : https://github.com/web-platform-tests/wpt/tree/7ef95a1c3f1c178e455b21569eddb31af7c3691f /streams
117
- [ wpt-async-iterator-prototype ] : https://github.com/web-platform-tests/wpt/blob/7ef95a1c3f1c178e455b21569eddb31af7c3691f /streams/readable-streams/async-iterator.any.js#L24
155
+ [spec-snapshot]: https://streams.spec.whatwg.org/commit-snapshots/080852ccd709e063cc6af239ae07fc040e365179 /
156
+ [wpt]: https://github.com/web-platform-tests/wpt/tree/186a9fd7abc3d9c31e2b37680be757e992af9e3a /streams
157
+ [wpt-async-iterator-prototype]: https://github.com/web-platform-tests/wpt/blob/186a9fd7abc3d9c31e2b37680be757e992af9e3a /streams/readable-streams/async-iterator.any.js#L24
118
158
[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4.0.0/src/lib/readable-stream/async-iterator.ts#L143-L147
119
159
[creatorrr-polyfill]: https://github.com/creatorrr/web-streams-polyfill
0 commit comments