Xetera / ghost-cursor

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

Actions like click, move failed in Playwright #99

Closed icesmartjuan closed 1 year ago

icesmartjuan commented 1 year ago

Hi expert,

It's great to have such lib, would like to know how to use this lib to perform human-like actions in playwright? Or is there any samples? Thanks It will throw following error in playwright,

navi done
wait done
path/node_modules/ghost-cursor/lib/spoof.js:475
      objectId = elem.remoteObject().objectId;
     ^

TypeError: elem.remoteObject is not a function
    at Object.<anonymous> (path/node_modules/ghost-cursor/lib/spoof.js:475:61)
    at step (path/node_modules/ghost-cursor/lib/spoof.js:44:23)
    at Object.next (path/node_modules/ghost-cursor/lib/spoof.js:25:53)
    at fulfilled (/path/node_modules/ghost-cursor/lib/spoof.js:16:58)

Test code as below:

const { chromium } = require('playwright');
const { createCursor } = require('ghost-cursor');

(async () => {
    const browser = await chromium.launch({headless:false});
    const context = await browser.newContext();
    const page = await context.newPage();
    const selector ="#selector"
    const cursor = createCursor(page)
    await page.goto(url)
    console.log("navi done")
    await page.waitForSelector(selector)
    console.log("wait done")
    await cursor.click(selector)
    console.log("click done")
    await cursor.move(selector)
    console.log("move done")
    await cursor.click()
    console.log("reclick done")
})();
Niek commented 1 year ago

Currently only puppeteer is supported. See https://www.npmjs.com/package/@extra/humanize for anther implementation that supports Playwright.