Custom Host e.g. localhost.enterprise.com (HTTPS)
See original GitHub issueI’m using msw 0.15.7 with create-react-app using a custom HOST (via an environment variable), e.g. HOST=localhost.myenterprise.com. This causes the issue below. If I remove the host environment variable and just go with plain old localhost:3000, everything works fine. Can using a custom host be supported?
Unhandled Rejection (TypeError): Cannot read property 'addEventListener' of undefined:
(anonymous function)
<omitted>/node_modules/msw/lib/esm/index.js:1791
(anonymous function)
<omitted>/node_modules/msw/lib/esm/index.js:51
__awaiter
<omitted>/node_modules/msw/lib/esm/index.js:31
start
<omitted>/node_modules/msw/lib/esm/index.js:1789
Module../src/mocks.js
> 26 | start();
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top Results From Across the Web
How to Edit Your Hosts File in Windows 10 - Liquid Web
The hosts file is usually the first process in the domain name resolution procedure. Here is an example of a hosts file entry....
Read more >Configure Virtual Host with XAMPP Running on Windows 10
This tutorial provides an overview of Windows 10 with XAMPP virtual host configuration and how it plays an important role in the modern ......
Read more >Enabling SSL on your web server—Installation Guides (10.3 ...
In order to use SSL, you need to obtain an SSL certificate and bind it to the website that hosts the Web Adaptor....
Read more >Connect a custom domain | Firebase Hosting - Google
@; The apex domain name (for example, example .com ); Leaving the Host field blank. Subdomain.
Read more >Chapter 1. Setting up the Apache HTTP web server
Configuring Apache name-based virtual hosts; 1.8. ... HTTP cache using, for example, memcache backend; mod_md - an ACME protocol SSL/TLS certificate service.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Glad to help. I’ll use this ticket as an opportunity to provide a better error message when this situation happens. A guidance like “Service Workers are not supported, or you are using a custom hostname” may be helpful for the user.
I’ve tried to reproduce this issue and was successful. The first thing I’ve noticed, is that when running under a custom hostname, the
navigator.serviceWorker
isundefined
. This is the technical reason behind the exception you’ve attached.However, the actual reason for the issue is that Service Workers can only be run over a secure connection (
localhost
is whitelisted).Solutions
(Option 1) Use HTTPS for development
Recommended. If you establish your local server using HTTPS, it will be considered secure by the browser, allowing you to register Service Workers.
(Option 2) Whitelist insecure host
Be cautious with this option. It implies whitelisting your custom host so that browser considers it secure. Do not whitelist hosts you don’t know.
http://localhost.myenterprise.com:3000
) in the textarea below.There is nothing I can do on to handle this on the library’s side, as this issue comes from the Service Worker’s behavior per specification.
Please let me know which option you’ve chosen, and whether it helped. Thanks.