Xetera / ghost-cursor

🖱️ Generate human-like mouse movements with puppeteer or on any 2D plane
MIT License
1.09k stars 118 forks source link

Ghost Cursor with puppeteer-cluster #23

Closed amunim closed 3 years ago

amunim commented 3 years ago

I'm trying to use ghost cursor with cluster and it is having trouble moving the mouse.

My code:

await cluster.task(async ({ page, data: { url } }) => 
    {
        //Randomize viewport size
        await page.setViewport({
            width: 1920 + Math.floor(Math.random() * 100),
            height: 1080 + Math.floor(Math.random() * 100),
            deviceScaleFactor: 1,
            hasTouch: false,
            isLandscape: false,
            isMobile: false,
        });

        //Skip images/styles/fonts loading for performance
        await page.setRequestInterception(true);
        page.on('request', (req) =>
        {
            if (/*req.resourceType() == 'stylesheet' ||*/ req.resourceType() == 'font' || req.resourceType() == 'image')
            {
                req.abort();
            } else
            {
                req.continue();
            }
        });
        await page.goto(url, { timeout: 0 });

        const cursor = createCursor(page);

        await page.waitForXPath(config.selectors.email);
        let el = await page.$x(config.selectors.email);
        await cursor.click(el[0]);

        //more irrelevant code
}

thrown errors:

Warning: could not move mouse, error message: Error: Protocol error (Input.dispatchMouseEvent): Target closed (spoof.js: 238)
Warning: could not move mouse, error message: Error: Protocol error (Input.dispatchMouseEvent): Session closed. Most likely the page has been closed (spoof.js: 238)

Warning: could not click mouse, error message: Error: Protocol error (Input.dispatchMouseEvent): Session closed. Most likely the page has been closed. (spoof:320)

The same code works fine with vanilla puppeteer or puppeteer-extra

amunim commented 3 years ago

wait for the element you want to click then create the cursor