{"schemaVersion":"1.0","record":{"label":"Mock Service Worker","description":"MIT-licensed API mocking library that intercepts application requests in browser and Node.js environments using reusable handlers.","aliases":["MSW","mswjs"],"kind":"software","website":"https://mswjs.io","overview":"Mock Service Worker, commonly called MSW, is an open-source library for controlling application network behavior during development and testing. Developers define request handlers that can be reused in browser and Node.js integrations. This can exercise a frontend's loading, success and error paths without waiting for a real backend, but the mocks are an authored model of that backend rather than proof of its behavior.","license":"MIT","lifecycle":"active","example":false,"features":[{"name":"Reusable API handlers","status":"supported","detail":"Handler definitions can serve development and tests with browser or Node integration.","useCase":"Controlled API responses for frontend development and automated tests","platforms":["Browsers with compatible Service Worker support","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://mswjs.io/docs/","locator":"Browser/Node interception and reusable API mocks","retrievedAt":"2026-10-07T23:02:36Z","kind":"vendor"},{"url":"https://mswjs.io/docs/quick-start","locator":"Handlers, setupServer/setupWorker and lifecycle reset","retrievedAt":"2026-10-07T23:03:38Z","kind":"vendor"}]},{"name":"Standalone listening mock server","status":"unsupported","detail":"setupServer configures interception inside the current process; it does not create a network server.","useCase":"Controlled API responses for frontend development and automated tests","platforms":["Browsers with compatible Service Worker support","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://mswjs.io/api/setup-server","locator":"Process-local interception; no listening server; browser-specific handler APIs","retrievedAt":"2026-10-07T23:04:01Z","kind":"vendor"}]},{"name":"Automatic isolation from real HTTP services","status":"unsupported","detail":"Unhandled HTTP traffic can pass through; current listen options default to warning while continuing the frame.","useCase":"Controlled API responses for frontend development and automated tests","platforms":["Browsers with compatible Service Worker support","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://mswjs.io/docs/defaults","locator":"HTTP passthrough, WebSocket difference and handler order","retrievedAt":"2026-10-07T23:02:48Z","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server/listen","locator":"onUnhandledFrame warn/error/bypass behavior","retrievedAt":"2026-10-07T23:05:27Z","kind":"vendor"}]},{"name":"Cross-browser and direct-socket interception","status":"limited","detail":"Documented Service Worker/XHR caveats and direct net connection limits prevent blanket coverage.","useCase":"Controlled API responses for frontend development and automated tests","platforms":["Browsers with compatible Service Worker support","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://mswjs.io/docs/limitations","locator":"Service Worker/XHR progress/Firefox and direct Node socket limitations","retrievedAt":"2026-10-07T23:02:48Z","kind":"vendor"}]}],"alternatives":[],"slug":"mock-service-worker","draftAlternatives":[{"targetSlug":"mockoon","status":"limited","detail":"Can replace a separate Mockoon endpoint for code-controlled browser/Node application tests by intercepting the application's requests. It does not replace a shared listening server for arbitrary external clients, and fixtures must be rewritten as handlers.","useCase":"Controlled API responses for frontend development and automated tests","platforms":["Browsers with compatible Service Worker support","Node.js"],"region":"Version, build and integration requirements apply","evidence":[{"url":"https://mswjs.io/docs/","locator":"Browser/Node interception and reusable API mocks","retrievedAt":"2026-10-07T23:02:36Z","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server","locator":"Process-local interception; no listening server; browser-specific handler APIs","retrievedAt":"2026-10-07T23:04:01Z","kind":"vendor"},{"url":"https://github.com/mockoon/mockoon/blob/main/README.md","locator":"Desktop-authored servers and headless CLI","retrievedAt":"2026-10-07T23:03:50Z","kind":"vendor"}]}],"evidence":[{"url":"https://github.com/mswjs/msw/blob/main/LICENSE.md","locator":"MIT conditions","retrievedAt":"2026-10-07T23:03:17Z","kind":"vendor"},{"url":"https://mswjs.io/docs/","locator":"Browser/Node interception and reusable API mocks","retrievedAt":"2026-10-07T23:02:36Z","kind":"vendor"},{"url":"https://mswjs.io/docs/quick-start","locator":"Handlers, setupServer/setupWorker and lifecycle reset","retrievedAt":"2026-10-07T23:03:38Z","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server","locator":"Process-local interception; no listening server; browser-specific handler APIs","retrievedAt":"2026-10-07T23:04:01Z","kind":"vendor"},{"url":"https://mswjs.io/docs/defaults","locator":"HTTP passthrough, WebSocket difference and handler order","retrievedAt":"2026-10-07T23:02:48Z","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server/listen","locator":"onUnhandledFrame warn/error/bypass behavior","retrievedAt":"2026-10-07T23:05:27Z","kind":"vendor"},{"url":"https://mswjs.io/docs/limitations","locator":"Service Worker/XHR progress/Firefox and direct Node socket limitations","retrievedAt":"2026-10-07T23:02:48Z","kind":"vendor"},{"url":"https://github.com/mswjs/msw/blob/main/package.json","locator":"Inspected version 3.0.2 and protocol-specific exports","retrievedAt":"2026-10-07T23:05:27Z","kind":"vendor"},{"url":"https://github.com/mockoon/mockoon/blob/main/README.md","locator":"Desktop-authored servers and headless CLI","retrievedAt":"2026-10-07T23:03:50Z","kind":"vendor"}],"document":{"version":1,"references":[{"url":"https://github.com/mswjs/msw/blob/main/LICENSE.md","locator":"MIT conditions","retrievedAt":"2026-10-07T23:03:17Z","id":"license","title":"MSW license","kind":"vendor"},{"url":"https://mswjs.io/docs/","locator":"Browser/Node interception and reusable API mocks","retrievedAt":"2026-10-07T23:02:36Z","id":"intro","title":"MSW introduction","kind":"vendor"},{"url":"https://mswjs.io/docs/quick-start","locator":"Handlers, setupServer/setupWorker and lifecycle reset","retrievedAt":"2026-10-07T23:03:38Z","id":"quick","title":"MSW quick start","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server","locator":"Process-local interception; no listening server; browser-specific handler APIs","retrievedAt":"2026-10-07T23:04:01Z","id":"server","title":"MSW setupServer","kind":"vendor"},{"url":"https://mswjs.io/docs/defaults","locator":"HTTP passthrough, WebSocket difference and handler order","retrievedAt":"2026-10-07T23:02:48Z","id":"defaults","title":"MSW default behaviors","kind":"vendor"},{"url":"https://mswjs.io/api/setup-server/listen","locator":"onUnhandledFrame warn/error/bypass behavior","retrievedAt":"2026-10-07T23:05:27Z","id":"listen","title":"MSW listen options","kind":"vendor"},{"url":"https://mswjs.io/docs/limitations","locator":"Service Worker/XHR progress/Firefox and direct Node socket limitations","retrievedAt":"2026-10-07T23:02:48Z","id":"limits","title":"MSW limitations","kind":"vendor"},{"url":"https://github.com/mswjs/msw/blob/main/package.json","locator":"Inspected version 3.0.2 and protocol-specific exports","retrievedAt":"2026-10-07T23:05:27Z","id":"package","title":"MSW package manifest","kind":"vendor"},{"url":"https://github.com/mockoon/mockoon/blob/main/README.md","locator":"Desktop-authored servers and headless CLI","retrievedAt":"2026-10-07T23:03:50Z","id":"mockoon","title":"Mockoon repository","kind":"vendor"}],"overviewCitations":["intro","quick"],"licenseCitations":["license"],"sections":[{"id":"handlers","heading":"A shared mock layer","paragraphs":[{"id":"handlers-detail","content":[{"text":"MSW separates API behavior from the request client used by application code. Handlers can describe controlled responses and be reused across development, integration tests and demonstrations. The documented approach keeps those mocks outside individual fetch replacements, making the same behavior available to multiple tools. As an assessment, fixtures should still represent meaningful backend contracts: a frontend working against a fabricated response does not establish that the real service returns it."}],"citations":["intro"]}]},{"id":"integration","heading":"Browser and Node integration","paragraphs":[{"id":"integration-detail","content":[{"text":"Handlers alone do not activate interception. The browser and Node integrations use different setup entry points, and test setup must enable and later close interception. The quick start resets runtime handler changes after each test. In Node, setupServer is an interception layer inside the process, despite its name; another program cannot simply connect to it as a listening HTTP server. Shared handlers must also avoid unprovided browser-only globals when used in Node."}],"citations":["quick","server"]}]},{"id":"network","heading":"Unmatched requests may reach real services","paragraphs":[{"id":"network-detail","content":[{"text":"The default HTTP model is passthrough unless handlers supply another behavior. Handler order is significant, and an override can take precedence over an earlier fixture. The defaults guide describes WebSocket interception differently as mock-first. Current listen documentation uses onUnhandledFrame, with warning-and-continuing as the default and an error strategy that halts unhandled frames. Consequently, installing MSW alone should not be treated as a guarantee that tests cannot contact real services."}],"citations":["defaults","listen"]}]},{"id":"limits","heading":"Interception boundaries","paragraphs":[{"id":"limits-detail","content":[{"text":"Browser interception inherits Service Worker limitations. The limitations guide identifies missing XMLHttpRequest progress events and a Firefox XMLHttpRequest interception caveat. It also says direct Node net connections are outside the intercepted request path. These are reasons to verify the actual client and runtime, rather than assume a mock covers all traffic merely because a handler matches the intended URL. This article does not extrapolate the socket limitation to every use of native fetch."}],"citations":["limits"]}]},{"id":"versions","heading":"Version matching","paragraphs":[{"id":"versions-detail","content":[{"text":"The inspected repository manifest identifies version 3.0.2 and separate protocol exports, while the current API documentation uses network-frame terminology. Existing projects should match examples to their installed major version rather than splice current setup options into an older tutorial. This qualification is especially useful for generated test scaffolding, where a plausible import or option name can belong to another release."}],"citations":["package","listen"]}]},{"id":"license","heading":"Licensing","paragraphs":[{"id":"license-detail","content":[{"text":"MSW's covered source is MIT-licensed, including its notice-preservation conditions. The documentation separately offers paid educational material, but the source license does not require purchasing that material to use the library. Third-party services contacted by passthrough traffic keep their own access terms and costs."}],"citations":["license","intro","defaults"]}]},{"id":"replacement","heading":"Substitution considerations","paragraphs":[{"id":"replacement-detail","content":[{"text":"MSW can replace "},{"text":"Mockoon","targetSlug":"mockoon"},{"text":" for application-owned HTTP fixtures when code-level interception is preferable to running a separate endpoint. Mockoon's desktop and CLI server model remains different: it can serve clients outside one instrumented process. Moving between them involves changing fixture format and integration, not simply switching a URL. No installation, browser compatibility test or live API validation was performed."}],"citations":["mockoon","server","intro"]}]}]},"id":"Q989","revision":1037,"updatedAt":"2026-10-13T18:03:49Z","sourceUrl":"https://substitutefor.net/entities/Q989?revision=1037"}}