I'm trying to build a chat website that uses vue.js
as the frontend and django
as the backend. It works fine in Firefox
but in MS edge
and Google Chrome
, Websocket is failing. I get this message in the browser console.
WebSocket connection to 'ws://127.0.0.1:8000/inbox/' failed
I use django-channels
so in the python console it prints
WebSocket CONNECT /inbox/ [127.0.0.1:4965]
WebSocket DISCONNECT /inbox/ [127.0.0.1:4965]
When I print out the error code I get 1006
Close Code 1006 is a special code that means the connection was closed abnormally (locally) by the browser implementation.
My WebSocket code
new WebSocket(url, authToken) // I use sec-websocket-protocol to transfer the authentication token
What am I doing wrong or is it a problem with the browser?
-- Updated
new WebSocket("ws://127.0.0.1:8000/inbox/", "authtoken");
So, I'm sending the authentication token in the second Websocket protocol and authenticating the user in the backend using middleware. When I remove that protocol and accept unauthenticated users in the backend ->
new WebSocket("ws://127.0.0.1:8000/inbox/");
-> the WebSocket connects just fine. The problem is when sending the second Websocket protocol.