@@ -26,7 +26,7 @@ This library comes in multiple variants:
2626 Recommended for use in web apps supporting older browsers through a ` <script> ` tag.
2727
2828Each 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.
3030
3131In version 4, the list of variants was reworked to have more modern defaults and to reduce the download size of the package.
3232See the [ migration guide] [ migrating ] for more information.
@@ -57,6 +57,45 @@ import "web-streams-polyfill/polyfill";
5757const readable = new ReadableStream ();
5858```
5959
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+
6099## Compatibility
61100
62101The ` polyfill` and ` ponyfill` variants work in any ES2015-compatible environment.
@@ -80,7 +119,7 @@ When using TypeScript, make sure your [`moduleResolution`](https://www.typescrip
80119
81120## Compliance
82121
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.
84123
85124The polyfill is tested against the same [web platform tests][wpt] that are used by browsers to test their native implementations.
86125The 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
104143
105144[spec]: https://streams.spec.whatwg.org
106145[ref-impl]: https://github.com/whatwg/streams
146+ [mdn-browser-compatibility]: https://developer.mozilla.org/en-US/docs/Web/API/Streams_API#browser_compatibility
107147[ponyfill]: https://github.com/sindresorhus/ponyfill
108148[migrating]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/master/MIGRATING.md
109149[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
112152[ws-controller-signal]: https://streams.spec.whatwg.org/#ws-default-controller-signal
113153[abortcontroller-polyfill]: https://www.npmjs.com/package/abortcontroller-polyfill
114154[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
118158[stub-async-iterator-prototype]: https://github.com/MattiasBuelens/web-streams-polyfill/blob/v4.0.0/src/lib/readable-stream/async-iterator.ts#L143-L147
119159[creatorrr-polyfill]: https://github.com/creatorrr/web-streams-polyfill
0 commit comments