Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dzcpy opened this issue Jun 9, 2022 · 7 comments

Comments

@dzcpy
Copy link

dzcpy commented Jun 9, 2022

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
Copy link
Collaborator

Niek commented Jun 9, 2022

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

@dzcpy
Copy link
Author

dzcpy commented Jun 9, 2022

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
Copy link

GamiDPC commented Jun 19, 2022

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

@MoKhajavi75
Copy link

Any updates?

@dzcpy
Copy link
Author

dzcpy commented Sep 7, 2022

Any updates?

No

@Niek Niek changed the title Falling back to JS scroll method ProtocolError: Protocol error (DOM.scrollIntoViewIfNeeded): Cannot find context with specified id Protocol error (DOM.scrollIntoViewIfNeeded): Cannot find context with specified id Oct 11, 2022
@jsomeara
Copy link

This would be nice, especially for captchas, which often reside in an <iframe>.

@jsomeara
Copy link

Found a workaround 😀. If you don't need scrolling capabilities, simply comment on the line in node_modules\ghost-cursor\lib\spoof.js which is causing the issue.

Before:

return [4, getCDPClient(page).send('DOM.scrollIntoViewIfNeeded', {
                                                    objectId: objectId
                                                })];

After:

// return [4, getCDPClient(page).send('DOM.scrollIntoViewIfNeeded', {
//                                                     objectId: objectId
//                                                })];

I suggest you use CTRL + F to find this line.

Note that this is really just a workaround, and usually, modifying your node_modules folder isn't a great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants