I copy the websocket request from the chrome network tab and try to use it as fetch and clearly is not working because fetch only support HTTP(S).
Is there a way I can connect to WhatsApp websocket connection by either Python or JavaScript?
You need to use the flask-socketio and for javascript socket library. The steps are to connect and then send data to the function mentioned. You need to read the documentation as it is pretty simple.
Get websocket connection to WhatsApp using Python or JavaScript?