Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to scrape a website that receives instructions on what to render through a WebSocket connected with the backend. So on every WebSocket frame received, i will get the content of the page run it through a function that builds an object with the necessary data, and compare it with the object from the previous frame received. I always get true, meaning that the objects are identical. I have logged the two objects and it seems like currentQueue and previousQueue are both identical but changes on the next frame to again be identical, meaning that the object building function is correctly working. I really cannot figure out what I have done wrong, and suspect that there is a problem with the syntax.

const puppeteer = require('puppeteer');
const getQueue = require('./queue');

var page;
var previousQueue = null;

async function processData(res) {
    // get current queue
    const pageContent = await page.content();
    const currentQueue = await getQueue(pageContent);

    // convert queues to Json
    const currentQueueJson = await JSON.stringify(currentQueue);
    const previousQueueJson = await JSON.stringify(previousQueue);

    // comapre queues
    console.log(currentQueueJson == previousQueueJson);
    
    // console.log(previousQueueJson);
    // console.log(currentQueueJson);
    // console.log('\n\n');

    // set previous queue = current queue;
    previousQueue = currentQueue;

    return;
}

async function main() {
    // get page
    const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true });
    page = await browser.newPage();
    await page.goto('https://example.com');

    // listen for websocket
    const cdp = await page.target().createCDPSession();
    await cdp.send('Network.enable');
    await cdp.send('Page.enable');

    cdp.on('Network.webSocketFrameReceived', processData);
}

main()


What I have tried:

I have tried to log previousQueue and currentQueue and they seems to be identical even though tgey should not be.
Posted
Updated 7-Aug-22 9:26am
v2

1 solution

Shouldn't you be comparing using the strict equality operator === and not equality operator ==
 
Share this answer
 
v2
Comments
Abdalla Roda 7-Aug-22 15:32pm    
I tried it, still not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900