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

**URL:** <https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712>\
**Category:** Bugs\
**Created:** [October 30, 2020, 6:42pm UTC](https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712 "2020-10-30T18:42:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alesis](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/alesis/32/22526_2.png) [@Alesis](https://forum.defold.com/u/Alesis)\
**Post date:** [October 30, 2020, 6:42pm UTC](https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712/1 "2020-10-30T18:42:30Z")

</div>

**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:**

- Platforms: HTML5

**Minimal repro case project:**  
[Websocket.zip](https://forum-defold-uploads.b-cdn.net/original/3X/2/c/2c549498cfdba8639b369bcc8d5a99b9da68ff05.zip) (2.9 KB)

**Workaround:**  
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.

**Screenshots:**

 ![Screenshot](https://forum-defold-uploads.b-cdn.net/original/3X/9/7/976e58fc2a99a7726e4118e4898d53703ca33bc5.png)

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [October 30, 2020, 10:26pm UTC](https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712/2 "2020-10-30T22:26:10Z")

</div>

Looking closer at the [Emscripten docs](https://emscripten.org/docs/porting/networking.html#emulated-posix-tcp-sockets-over-websockets), 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 🙂

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [October 31, 2020, 8:59am UTC](https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712/3 "2020-10-31T08:59:29Z")

</div>

Reported in the repo: [Add protocol connection parameters · Issue #16 · defold/extension-websocket · GitHub](https://github.com/defold/extension-websocket/issues/16)

---

<div class="post-metadata">

**Author:** ![Mathias\_Westerdahl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/mathias_westerdahl/32/228_2.png) [@Mathias\_Westerdahl](https://forum.defold.com/u/Mathias_Westerdahl)\
**Post date:** [October 31, 2020, 2:58pm UTC](https://forum.defold.com/t/websocket-extension-ignores-sub-protocol-header-in-html5-build-solved/66712/4 "2020-10-31T14:58:54Z")

</div>

Solved in [extension-websocket 1.5.0](https://github.com/defold/extension-websocket/releases/tag/1.5.0).

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

```lua
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?
