SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.
Contents
Explanation
|
|
Encountering a security error related to WebSocket connections. This error typically occurs when a WebSocket connection is attempted over an insecure protocol (HTTP) from a page that is loaded over a secure protocol (HTTPS).
This happened when developing React App using cloud machine and forward the
localhost
like Github Codespace or Heroku.
How to fix it
@Pratap Sharma: add this line
protocol: window.location.protocol === 'https:' ? 'wss' : 'ws'
1
In NextJS you need to go to @next-devtools/core
in packages/core/src/provider/frame.tsx
and adjust the line 15. You can use the below code.
|
|
I’ve also contributed the solution (source code) to the repo for @next-devtools
. You can check out here.