WebSocket with options object

There is currently no way of passing options except url and protocols to a WebSocket during instanciation. Setting up a binaryType requires a second line:

const socket = new WebSocket(`ws://example.com`);
socket.binaryType = "arraybuffer";

I think it would be nice to be able to pass options as an object during instanciation:

const socket = new WebSocket(`ws://example.com`, {  binaryType: "arraybuffer" });

If one wants to pass protocols, it is easily possible with an object

const socket = new WebSocket(`ws://example.com`, {  protocols: […] });

Or is there a compelling reason why this isn't a thing?

@timreichen, WebSocket is not part of JavaScript core.
I think, the question should be opened at GitHub - whatwg/html: HTML Standard .

2 Likes

@Yaffle opened an issue there weeks ago. No answer till now :/

Consider reaching out to https://discourse.wicg.io instead - you might get better traction.