Websocket subprotocol

Hi. I have a websocket to which I would like to connect with a subpotocol. In js is something like this new WebSocket(url, protocol). I have tried with both the built in and the experimental ws versions things like sending paramaters like this:

 const response = ws.connect(url, {
        headers: {
            'Sec-WebSocket-Protocol': protocol
        }
    }, function (socket) { ...

or

 const response = ws.connect(url, {
       protocol: protocol 
    }, function (socket) { ...

but it does not work. I’ll appriciate any help to know how to start a websocket connection with a subprotocol.

Hi @forsevielleicht1, welcome to the community forum!

I don’t think anyone has ever requested this before and it did need some changes in the experimental websockets. (I don’t think we will be backporting this to k6/ws).

This should now align with the actual specification.

Can you please build a k6 binary with xk6 and test that this works for your usecase?

xk6 build v0.51.0 --with github.com/grafana/xk6-websockets@399b5f0829b1f6f49718f99e294339bef51ec2a3

Some setup is required that is defined in the xk6 repo