There is currently no automatic way to do this. There is a third (undocumented) parameter for the WebSocket constructor to pass custom HTTP headers to the connection request.
WebSocket(url, '', {Cookie: 'key=value'});
This works on iOS, I have not tested it on Android, but the WebSocket implementation looks the same as there.
If you just need to pass a session identifier or an authentication token, it might be easier to pass it as a GET parameter to the URL. Drawing on undocumented behavior in a rapidly changing structure can be dangerous.
source share