I'm trying to make a simple web application (html+css+js) to monitor the status of servers of other applications that use zrok.
My servers that use zrok support connection upgrade to websocket. So the idea is that the monitor maintains the websocket connection to show the servers that are active or not. As in the image below.
I'm having problems connecting to the websocket using the zrok url when the websocket client has a different origin than the zrok url. When the client is in the same request origin, the connection works perfectly.
Initially I thought it was some browser restriction or CORS of my application on the server. But then I did a test using:
wss://echo.websocket.org and I was able to connect perfectly even with the client in a different origin, which seems to eliminate a browser restriction.
I also did another test using CURL with zrok's url but specifying some headers:
curl --include --no-buffer --header "Connection: Upgrade" --header "Upgrade: websocket" --header "Host: wfwljbgpjt5n.share.zrok.io" --header "Origin: https://wfwljbgpjt5n.share.zrok.io" --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" --header "Sec-WebSocket-Version: 13" https://wfwljbgpjt5n.share.zrok.io/
And it also seems to have worked, as I had the following return:
HTTP/1.1 101 Switching Protocols
Date: Tue, 10 Jun 2025 12:42:29 GMT
Connection: upgrade
Sec-Websocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk=
Server: Pca 2.5.2.1
Upgrade: websocketWarning: Binary output can mess up your terminal. Use "--output -" to tell curl to output it to your terminal anyway,
Warning: or consider "--output " to save to a file.
So the problem seems to be when you try to use javascript on a page with a different origin like:
const ws = new WebSocket(wss://wfwljbgpjt5n.share.zrok.io);
I also tried using the --insecure option on the "zrok share" command but had the same problem.
I'll also leave here the code I'm using to test:
Monitor.zip (2.0 KB)
Thanks!