WebSocket not working in railway
samueltuoyo15
FREEOP

3 months ago

I'm currently working on a full-stack application that uses WebSocket. I deployed the backend on Railway. Since then the client-side(chrome extension) has been failing to connect to the WebSocket endpoint, and yes my http server and WebSocket server are listening on same port, no hardcoded ports. Still it's still failing, i was debugging and debugging and reading several discussions related to this, and with what i can see it's like Railway doesn't support WebSocket properly. Because in the client-side this is what happens when i try to establish a connection to my server.

However if i try to establish same connection again using WSCAT it works.

It also works perfectly fine on Postman. But not just working on the client side. Please i need assistance.

Solved$10 Bounty

Pinned Solution

samueltuoyo15
FREEOP

3 months ago

This did not work at first, had to add "chrome-extension" to my allowed origins. But it's working now, at least it's connecting to my WebSocket server for now.

3 Replies

Status changed to Awaiting Railway Response Railway 3 months ago


diogoribeirodev
FREE

3 months ago

Do you have cors enabled?


diogoribeirodev

Do you have cors enabled?

samueltuoyo15
FREEOP

3 months ago

Yes, CORS is enabled on my backend. I think I may have found the issue already. I was establishing the WebSocket connection inside the offscreen document, which is sandboxed and was causing handshake failures in Chrome extension context. I am moving the WebSocket client logic to the background service worker, which should resolve it.


samueltuoyo15

Yes, CORS is enabled on my backend. I think I may have found the issue already. I was establishing the WebSocket connection inside the offscreen document, which is sandboxed and was causing handshake failures in Chrome extension context. I am moving the WebSocket client logic to the background service worker, which should resolve it.

samueltuoyo15
FREEOP

3 months ago

This did not work at first, had to add "chrome-extension" to my allowed origins. But it's working now, at least it's connecting to my WebSocket server for now.


Status changed to Solved brody 3 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...