A lightweight polyfill for the Fetch API, implementing a subset of the standard Fetch specification to replace XMLHttpRequest in web applications. Current stable version is 3.6.20, released on 2023-12-14. This package is the de facto standard for adding fetch support in older browsers; it is actively maintained by the GitHub community and has minimal dependencies. Note that it only works in browser environments, not Node.js, and for very old browsers a separate Promise polyfill is required.
npm install whatwg-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to polyfill fetch via import and make a basic JSON request with error handling.
Use node-fetch, undici, or built-in global fetch (Node 18+).
Always check response.ok or response.status after a fetch.
Update to v3 or later and switch to side-effect import 'import "whatwg-fetch"'. For legacy projects, stick with <3.0.
Test in older browsers (e.g., IE11) to verify polyfill behavior. For development, consider using browser dev tools to emulate older engines.
Use the new repository URL: https://github.com/github/fetch
Do not use this package in Node.js; use 'node-fetch' or the native 'fetch' (Node 18+).
Ensure the server responds with appropriate CORS headers (Access-Control-Allow-Origin).
Always call a body method on response: response.json(), response.text(), response.blob(), etc.