A partial archive of discourse.wicg.io as of Saturday February 24, 2024.

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?