- 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
Using local HTTPS
Due to security considerations, Service Workers can only be registered over a secure connection (exception being the local development on localhost
). In some project setups, you may require to run your local application over HTTPS and will shortly encouter the following error when starting MSW’s worker:
SecurityError: Failed to register a ServiceWorker:
An SSL certificate error occurred when fetching the script.
This error occurs because your browser will not trust your self-signed certificate. As a result of it, the browser will block the Service Worker registration attempt and MSW will not work.
To use the library with a local HTTPS setup you must make your browser trust your self-signed certificate. This can be achieve in multiple ways described below.
Trust certificate on system level
You can add your self-signed certificate to the system’s trusted certificates. Please refer to the respective resources online on how to do so based on your operating system.
Trust certificate on browser level
Chrome / Brave
- Open
chrome://flags
(orbrave://flags
if using Brave); - Search for
unsafely-treat-insecure-origin-as-secure
flag in the list; - Select the “Enabled” option next to the flag.
- Enter your local host into the field.
If encountering certificate fetching/validation issues, set the
ignore-certificate-errors
flag to “Enabled”.
Firefox
- Open your local application served by HTTPS;
- On the “Connection is not secure” screen click the “Advanced” button;
- In the section below, click the “Add Exception” button.
- Specify your application’s URL as the “Location” input value;
- Click the “Confirm Security Exception” button.
Safari
We are not aware of any settings to make Safari trust self-seigned certificates. Consider enabling System-wide trust on MacOS instead.