0

I'm attempting to use puppeteer to detect certain socket.io events emitted by the game, such as these:

socket.on("setStartTime", socket_onSetStartTime);
socket.on("nextTurn", socket_onNextTurn);
socket.on("livesLost", socket_onLivesLost);
socket.on("bonusAlphabetCompleted", socket_onBonusAlphabetCompleted);
socket.on("setPlayerWord", socket_onSetPlayerWord);
socket.on("failWord", socket_onFailWord);
socket.on("correctWord", socket_onCorrectWord);
socket.on("happyBirthday", socket_onHappyBirthday);

Is there a way to do this with puppeteer or something else in node?

iris87
  • 103
  • 1
  • 2
  • 11
  • 1
    Did you try [How to use puppeteer to dump WebSocket data](https://stackoverflow.com/questions/48375700/how-to-use-puppeteer-to-dump-websocket-data)? – ggorlen Oct 07 '22 at 14:01

1 Answers1

0

Solution was to create a CDP session, as listed here.

Example:

const cdp = await page.target().createCDPSession();
await cdp.send("Network.enable");
await cdp.send("Page.enable");

cdp.on("Network.webSocketFrameReceived", handleResponse); // Fired when WebSocket message is received.
cdp.on("Network.webSocketFrameSent", handleResponse); // Fired when WebSocket message is sent.

function handleResponse(packet) {
    //do stuff with packet
}
iris87
  • 103
  • 1
  • 2
  • 11