Browser limitations

This library uses the Service Worker API to intercept requests in the browser. Any limitations that browsers may have when implementing or executing the said API automatically become the limitations of the Mock Service Worker library. We cannot address this behaviors as they are present in the browser and cannot be circumvented by JavaScript.

Firefox does not emit “fetch” event on XMLHttpRequest

Firefox does not notify the worker when an XMLHttpRequest happens on the page. This means that the worker and, as the result, this library, do not know when such requests occur. Even if you have a matching request handler for the request, it won’t be matched and the mocked response won’t be sent if it’s an XMLHttpRequest.

Mock Service Worker positions itself as a development tool, which means we cannot guarantee 100% compatibility with all modern browsers. In the end, each browser may have its discrepancies in how the Service Worker API is implemented, for which we also cannot account for.

Node.js limitations

Parallel runs

This technical limitation manifests as an issue when using runtime handlers in parallel (concurrent) test suites.

// global.test.setup.js
  http.get('/user/firstName', () => {
    return new Response('John')
// test/one.test.js
it('fetches the first name of the user', () => {
// test/two.test.js
it('handles server errors', () => {
    http.get('/user', () => {
      return new Response(null, { status: 500 })

The example above overrides the GET /user handler only for the two.test.js test to respond with a 500 Internal Server Error response. Once these two tests are run in parallel, the runtime handler of the second test may affect the first test, resulting in false negative test runs.

We currently recommend disabling test paralleliaztion when using Mock Service Worker to prevent unexpected behaviors. We are also tracking this issue on GitHub.