Failed to construct 'WebSocket'

Hi! I got the following error when trying to deploy my React project: SecurityError: “Failed to construct ‘WebSocket’: An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.”. Here is the project: https://mavludin-portfolio-page.glitch.me/
Is there anybody who solved it already? Thank you guys in advance.

Hi @Mavludin,

We had a site outage earlier today that may have this. When you have a moment, please refresh your project. If you continue to receive the error after doing this, let us know!

1 Like

Hi @tasha, I refreshed it, but the issue is remaining.

When connecting to the WebSocket you need to use the WSS protocol not WS

e.g wss://project.glitch.me/coolwebsocket

1 Like

@xXProGamerXx How could I enable it?

Do you pass a websocket URL at any point in your site?

1 Like

@xXProGamerXx I think I don’t because I just discovered about WebSocket when I got this problem. My project is about some simple html+css.

It appears to be an issue with the library you are using.

1 Like

@xXProGamerXx I’m using React JS. It seems the issue is there. I’ll dig in there right away. Thank you.

1 Like

The file, where the issue is spotted, is ignored by git and can’t move to my project here on Glitch. I think the problem is from Glitch, because all the necessary modules are plugged in from here. Correct me if I’m wrong.

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!

1 Like

I had this exact same problem, and I think I finally figured it out! Looks like it’s an issue with Create React App, which they’ve fixed for 3.3.1 but haven’t released yet. Reverting react-scripts to version 3.2.0 seems to fix the problem! https://mavludin-portfolio-page-fix.glitch.me