- Introduction
- Getting started
- Philosophy
- Comparison
- Limitations
- Debugging runbook
- FAQ
- Basics
- Concepts
- Network behavior
- Integrations
- API
- CLI
- Best practices
- Recipes
- Cookies
- Query parameters
- Response patching
- Polling
- Streaming
- Network errors
- File uploads
- Responding with binary
- Custom worker script location
- Global response delay
- GraphQL query batching
- Higher-order resolver
- Keeping mocks in sync
- Merging Service Workers
- Mock GraphQL schema
- Remote Request Interception
- Using CDN
- Using custom "homepage" property
- Using local HTTPS
stop()
Stop the request interception for the current client.
Call signature
The worker.stop()
function does not accept any arguments and doesn’t return anything.
worker.stop()
Although it’s a logical opposite to worker.start()
, the worker.stop()
method does not unregister the worker. Instead, it instructs the worker to disable API mocking for the current client (page). This way you can have multiple open clients with the different state of the request interception.
This method is designed to be called on runtime to control the request interception flow. You do so by exposing the worker
reference globally and calling window.worker.stop()
in any time in the browser.
// mocks/browser.js
import { setupWorker } from 'msw/browser'
import { handlers } from './handlers'
export const worker = setupWorker(...handlers)
// Expose the worker instance globally.
window.worker = worker
When stopping the worker on runtime, the stopped state will not persist across page reloads.