Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dictionary as second param in WebSocket constructor #42

Open
KhafraDev opened this issue Feb 24, 2023 · 4 comments · May be fixed by #59
Open

Allow dictionary as second param in WebSocket constructor #42

KhafraDev opened this issue Feb 24, 2023 · 4 comments · May be fixed by #59

Comments

@KhafraDev
Copy link

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. nodejs/undici#1943).

Proposed change:

dictionary WebSocketInit {
  protocols: DOMString or sequence<DOMString>
}

interface WebSocket : EventTarget {
  constructor(USVString url, optional (DOMString or sequence<DOMString> or WebSocketInit) options = []);
@ricea
Copy link
Collaborator

ricea commented Feb 27, 2023

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.

@KhafraDev
Copy link
Author

understandable, I was hoping it would be minor enough for browser implementers to not mind lol

@KhafraDev
Copy link
Author

Bun also allows a dictionary as second parameter for setting custom headers, example here.

@KhafraDev
Copy link
Author

it was also suggested in #16 (comment) which I didn't know about

KhafraDev added a commit to KhafraDev/websockets that referenced this issue May 20, 2024
This commit adds an option bag to the WebSocket constructor that allows
settings the protocols. This will bring interop between browsers and
server environments that already implement this (Bun and Node).

Closes: whatwg#42
KhafraDev added a commit to KhafraDev/websockets that referenced this issue May 20, 2024
This commit adds an option bag to the WebSocket constructor that allows
settings the protocols. This will bring interop between browsers and
server environments that already implement this (Bun and Node).

Closes: whatwg#42
@KhafraDev KhafraDev linked a pull request May 20, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants