javascriptnode.jspuppeteerheadless

ghost-cursor Error : elem.remoteObject is not a function in puppeteer


whenever I run the script in the Local system the cursor properly worked and when I run inside docker that time I fetch an Error so anybody guid me what is wrong or whether this issue is package side or not.?

when I run in Locally that time I headless: false and Run inside docker that time headless: true but I tried inside docker headless: false but it can't work

here is code

const puppeteer = require('puppeteer');
const {path,createCursor} = require("ghost-cursor");
const url = process.argv[2];

async function run() {
    browser = await puppeteer.launch({
        args: ['--disable-gpu', '--no-first-run', '--no-sandbox', '--no-zygote'],
        "dumpio": true,
        "devtools": false,
        "ignoreHTTPSErrors": true,
    });

    const page = await browser.newPage();
    const cursor = createCursor(page);
    await cursor.move(selector)
    await page.goto(url);
    await page.screenshot({ path: 'screenshot.png' });
    browser.close();
}
run();

Here is Error Message 

    TypeError: elem.remoteObject is not a function
    at Object.<anonymous> (/usr/app/node_modules/ghost-cursor/lib/spoof.js:458:61)
    at step (/usr/app/node_modules/ghost-cursor/lib/spoof.js:44:23)
    at Object.next (/usr/app/node_modules/ghost-cursor/lib/spoof.js:25:53)
    at fulfilled (/usr/app/node_modules/ghost-cursor/lib/spoof.js:16:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Solution

  • selector is undefined

    You need to grab an element from the UI to move to like so

    import { createCursor } from "ghost-cursor"
    import puppeteer from "puppeteer"
    
    const run = async (url) => {
      const selector = "#sign-up button"
      const browser = await puppeteer.launch({ headless: false });
      const page = await browser.newPage()
      const cursor = createCursor(page)
      await page.goto(url)
      await page.waitForSelector(selector)
      await cursor.click(selector)
    }