Websocket extension ignores sub-protocol header in HTML5 build (SOLVED)


Describe the bug
Websocket extension ignores sub-protocol header in HTML5 build. The Sec-WebSocket-Protocol gets set to binary for the HTML5 build no matter what is passed in the params. This causes an inconvenience on Firefox and completely blocks communication on Chrome.

To Reproduce
Build a HTML5 target with Sec-WebSocket-Protocol being set to anything other than binary

Expected behaviour
The Sec-WebSocket-Protocol header to be populated with the value passed in the params.

Defold version:

  • Defold version: 1.2.174
  • Websocket extension version: 1.4.0


  • Platforms: HTML5

Minimal repro case project:
Websocket.zip (2.9 KB)

Setting your websocket server to accept the binary sub-protocol and setting the Sec-WebSocket-Protocol to binary for consistency across all build targets allows the game to function and communicate with the server.




Looking closer at the Emscripten docs, there’s an option to set the Module["websocket"]["subprotocol"] = "chat"; at runtime.

I’ve already confirmed the headers are affected by this, now I just need to make a good implementation out of it :slight_smile:

1 Like


Reported in the repo: https://github.com/defold/extension-websocket/issues/16

1 Like


Solved in extension-websocket 1.5.0.

You can now define the protocol parameter. E.g.:

local params = {
    timeout = 3000,
    protocol = "chat",
    headers = "Origin: mydomain.com\r\n"

I’m curious though, to how you got this working with the old extension (defold-websocket), since by the looks of it, it had the exact problem?