How MSW intercepts requests
mainMSW intercepts requests at the network level rather than stubbing high-level APIs like fetch or axios.
- In the Browser: It uses the Service Worker API to intercept requests after they have left your application code. This allows you to see mocked responses directly in the browser's 'Network' tab.
- In Node.js: It implements a low-level interception algorithm that allows the same request handlers used in the browser to work in Node.js environments.
Because interception happens at the network level, your application code remains 'deviation-free'—it runs exactly as it would in production, unaware that the responses are being provided by MSW.