Xetera / ghost-cursor

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

Protocol error (DOM.scrollIntoViewIfNeeded): Cannot find context with specified id #57

Open dzcpy opened 2 years ago

dzcpy commented 2 years ago

Hi, Thanks for making this awesome module. I was using it to click an object inside of an iframe. Here is the code:

"ghost-cursor": "^1.1.11",
"puppeteer": "^14.3.0",
"puppeteer-extra": "^3.2.3",
"puppeteer-extra-plugin-stealth": "^2.9.0",
"user-agents": "^1.0.1017"
import { setTimeout as sleep } from 'timers/promises';
import UserAgent from 'user-agents';
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import { createCursor } from 'ghost-cursor';

const userAgent = new UserAgent({ deviceCategory: 'desktop' }).toString();

const browser = await puppeteer.use(StealthPlugin()).launch({
  headless: false,
  ignoreHTTPSErrors: true,
  args: [
    '--disable-gpu',
    '--disable-extensions',
    '--disable-dev-shm-usage',
    '--no-sandbox',
    '--disable-setuid-sandbox',
    '--no-first-run',
    '--no-zygote',
    '--single-process',
    '--disable-infobars',
    '--window-position=0,0',
    '--ignore-certifcate-errors',
    '--ignore-certifcate-errors-spki-list',
  ],
});
let page = await browser.newPage();
const cursor = createCursor(page);

await page.setUserAgent(userAgent);

await page.goto('https://www.hermes.cn');
const iFrame = await page.waitForSelector('iframe[src^="https://geo.captcha-delivery.com"]');
const frame = await iFrame.contentFrame();
const clickHandle = await frame.waitForSelector('.geetest_radar_tip');
await cursor.click(clickHandle);

await sleep(30000);

However there's an error:

Falling back to JS scroll method ProtocolError: Protocol error (DOM.scrollIntoViewIfNeeded): Cannot find context with specified id
    at /var/www/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:230:24
    at new Promise (<anonymous>)
    at CDPSession.send (/var/www/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:226:16)
    at next (/var/www/node_modules/puppeteer-extra-plugin-stealth/evasions/sourceurl/index.js:32:41)
    at CDPSession.send (/var/www/node_modules/node_modules/puppeteer-extra-plugin-stealth/evasions/sourceurl/index.js:57:18)
    at Object.<anonymous> (/var/www/node_modules/node_modules/ghost-cursor/lib/spoof.js:426:53)
    at step (/var/www/node_modules/node_modules/ghost-cursor/lib/spoof.js:44:23)
    at Object.next (/var/www/node_modules/node_modules/ghost-cursor/lib/spoof.js:25:53)
    at /var/www/node_modules/node_modules/ghost-cursor/lib/spoof.js:19:71
    at new Promise (<anonymous>) {
  originalMessage: 'Cannot find context with specified id'
}

Actually the click event is triggered, but it seems that there's something wrong with the scroll. Is there any way to fix it?

Niek commented 2 years ago

ghost-cursor expects the element to reside in the main frame, not in a subframe. This can probably be fixed though.

dzcpy commented 2 years ago

ghost-cursor expects the element to reside in the main frame, not in a subframe. This can probably be fixed though.

Thanks for your help! Is there any workaround?

GamiDPC commented 2 years ago

I'm also waiting for this bug to be fixed.

MoKhajavi75 commented 2 years ago

Any updates?

dzcpy commented 2 years ago

Any updates?

No

jsomeara commented 1 year ago

This would be nice, especially for captchas, which often reside in an