websockets
websockets copied to clipboard
Allow dictionary as second param in WebSocket constructor
This would allow server environments (specifically talking about nodejs/undici) that implement WebSocket some flexibility, for example, to add custom headers, etc. While we could change it on our side, it would be incompatible with other implementations. Similarly, it'll cause type issues with people who use typescript in cross-env packages (ie. https://github.com/nodejs/undici/issues/1943).
Proposed change:
dictionary WebSocketInit {
protocols: DOMString or sequence<DOMString>
}
interface WebSocket : EventTarget {
constructor(USVString url, optional (DOMString or sequence<DOMString> or WebSocketInit) options = []);
It's a sensible extension point and as far as I know compatible with existing practice. But it's hard to motivate it from a browser implementation point of view.
In other words, I'm not opposed, but I don't know how I'd justify the work.
understandable, I was hoping it would be minor enough for browser implementers to not mind lol
Bun also allows a dictionary as second parameter for setting custom headers, example here.
it was also suggested in https://github.com/whatwg/websockets/issues/16#issuecomment-881547333 which I didn't know about