A lightweight library to intercept and modify fetch requests and responses in the browser. Current stable version is 1.1.0. It provides hooks for before request, on response success, and on response failure. Key differentiator is its simplicity and zero dependencies, unlike more complex alternatives like Mock Service Worker or Polly.js. The library is actively maintained with a small API surface, making it easy to integrate into any project that uses the Fetch API. It is released on npm and supports CommonJS and ES modules via module field.
npm install fetch-interceptorNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
This shows how to import fetch-interceptor, register interceptor hooks, make a fetch request, and unregister the interceptor.
Call register() before any fetch you want to intercept.
Ensure the interceptor is registered in the same context as the fetch calls.
Use a single interceptor or chain hooks manually within the callbacks.
Check the documentation for the current controller API and avoid relying on undocumented behaviors.
Use `import fetchInterceptor from 'fetch-interceptor'` or `const FetchInterceptor = require('fetch-interceptor');`Use `import fetchInterceptor from 'fetch-interceptor';` instead of require.
Ensure you call unregister only on the object returned by register().
Use a polyfill like node-fetch or upgrade Node to 18+.
No dependency data recorded yet.