From nodejs v22
now you can pass a WebSocketInit
as the second parameter. Example:
var ws = new WebSocket(url, {
protocols: ...
headers: {
'User-Agent': 'xxx',
...
},
})
Though this is not been written in MDN Docs, but nodejs chose undici as WHATWG implementation, like fetch/WebSocket
.