Failed to deploy my react app to Heroku due to "Failed to construct WebSocket"

SecurityError: Failed to construct ‘WebSocket’: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

Can anyone help me with this? Should I deploy it with production version? If so, what should I do with it?

Are you trying to do this from the glitch console or how does this relate to glitch?

Hey Mike!

Try with wss:// , indicates you want a secure web-socket connection. The browser will prevent you from creating insecure connections from secure pages, because it understands that since you requested the page with https:// , there is a transport security requirement.

If you have your WebSocket server running with yout web server, it will probably use the same security certificate and you do not need to do anything. If it does not work, please check your WebSocket server documentation about how to add certificates and enabling wss:// .

Thanks & Happy Glitching!

I ran into this problem in a React project, so in case you’re using react-scripts as well, it looks like there’s an issue with Create React App that they’ve fixed for 3.3.1 but haven’t released yet. Reverting react-scripts to version 3.2.0 fixed it for me!

1 Like