Connecting to "cometd" websocket

Sort:
iSubaru

Hi, i am trying to connect to "cometd" websocket in NodeJS that is opening on https://www.chess.com/play/online "games/watch" tab, but it is protected with some data i can't reach :/ 

Does anyone know how to reproduce connection in node?

acity609

Connection to a live game?

Martin_Stahl

The API doesn't allow attaching to things like that. Anything not documented through the API is not supported, may not work, and potentially could be against the TOS.

iSubaru
acity609 wrote:

Connection to a live game?

Connection to websocket that allow to observe live games. I think it is the only way to get recently finished game and it's ID. With that id we can use api and get pgn, fens etc.

 

paradox109

To successfully connect to chess.com cometd WebSockets you must include 'PHPSESSID' inside the cookie header. So you either forgot to include it or you are sending the wrong handshake data. 

Try to use BurpSuite, it def helps.

paradox109

You get PHPSESSID by logging in to chess.com, it does refresh from time to time(every 24h maybe,not sure) so you need to update it or make sure that it's always fresh when you try to connect to ws. 

iSubaru

For all that need solution it should like this:

const cometd = new WebSocket("wss://live3.chess.com/cometd", {
  headers: {
    Cookie: "PHPSESSID=xxxxxxxxxxxxxxxxxxxxx",
  },
});