ZFC-Digital / puppeteer-real-browser

This package is designed to bypass puppeteer's bot-detecting captchas such as Cloudflare. It acts like a real browser and can be managed with puppeteer.
https://www.npmjs.com/package/puppeteer-real-browser
MIT License
756 stars 91 forks source link

Context connection errors #162

Closed bernatvadell closed 2 months ago

bernatvadell commented 2 months ago

Hi,

I'm trying out the library, and I've found some "random" but fairly frequent errors.

file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:429
                .then(({ executionContextId }) => {
                         ^

TypeError: Cannot destructure property 'executionContextId' of 'undefined' as it is undefined.
    at file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:429:26
    at async Promise.all (index 0)
    at async #createIsolatedWorld (file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:415:9)
    at async Promise.all (index 4)
    at async FrameManager.initialize (file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:170:13)
Page.createIsolatedWorld timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.
net::ERR_ABORTED at https://xxxx.yyy
net::ERR_INSUFFICIENT_RESOURCES at https://xxxx.yyy
Navigation timeout of 30000 ms exceeded

any ideas?

thucvu97 commented 2 months ago

hi @bernatvadell What is the code you are using that causes the above error?

bernatvadell commented 2 months ago

Hi!

This is my code (although errors are generated randomly):

const response = await context.page.goto(instruction.params.url, {
          waitUntil: "load",
        });

produces:
file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:429
                .then(({ executionContextId }) => {
                         ^

TypeError: Cannot destructure property 'executionContextId' of 'undefined' as it is undefined.
    at file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:429:26
    at async Promise.all (index 0)
    at async #createIsolatedWorld (file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:415:9)
    at async Promise.all (index 4)
    at async FrameManager.initialize (file:///app/node_modules/.pnpm/puppeteer-core-patch@1.0.1/node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:170:13)

or

TimeoutError: Navigation timeout of 30000 ms exceeded

This code retrieves elements given a selector and generates a list of elements with the element's metadata. It also causes protocol issues at times.

const elements = instruction.params.selector
          ? (await context.page.$$(instruction.params.selector)) ?? []
          : instruction.params.xpath
          ? (await context.page.$$(instruction.params.xpath)) ?? []
          : [];

        return {
          ok: true,
          result: await Promise.all(
            elements.map(async (node) => {
              const result = await node.evaluateHandle((node) => {
                if (node.nodeType !== Node.ELEMENT_NODE) {
                } else {
                  const element = node as HTMLElement;
                  const attrs: Record<string, string> = {};
                  for (let i = 0; i < element.attributes.length; i++) {
                    const attr = element.attributes.item(i);
                    if (!attr) continue;
                    attrs[attr.name] = attr.value;
                  }
                  return {
                    tagName: element.tagName,
                    attrs,
                    innerText: element.innerText,
                    innerHtml: element.innerHTML,
                  };
                }
              });
              return await result.jsonValue();
            })
          ),
        };
vootsman commented 2 months ago

I also started getting the same error (didn't occur with the previous version)

file://...../node_modules/puppeteer-core-patch/lib/esm/puppeteer/cdp/FrameManager.js:429 .then(({ executionContextId }) => { ^

TypeError: Cannot destructure property 'executionContextId' of 'undefined' as it is undefined.

thucvu97 commented 2 months ago

@vootsman Because the new version has updated the ppt patch, many errors occur. Please share the code where the above error occurs to make it easier to check.

Zvih commented 2 months ago

@bernatvadell I've already created issue ticket with it but @zfcsoftware has no plan to fix it, as i understood https://github.com/zfcsoftware/puppeteer-real-browser/issues/133

mdervisaygan commented 2 months ago

@bernatvadell I've already created issue ticket with it but @zfcsoftware has no plan to fix it, as i understood #133

Hello, currently only headless false is supported. I can update it to pass through Cloudflare with a headless shell, but Cloudflare and other systems will likely fix the issue soon. All libraries, including mine, are being monitored. Even for a simple Captcha click, countless updates had to be made. It's very hard to keep up with these changes. Since this is an open-source project, I can't dedicate a lot of time to it. However, if you're encountering this issue while using headless false and can share the reproduction code, I'd be happy to help as much as I can.

Zvih commented 2 months ago

@zfcsoftware I encountered this issue with headless: false, and it's a bit random when you move with goTo to other page. That's why I removed the library from the project for now. However, you did great job. The other value for the headless parameter (true, new etc.) was mentioned to quickly reproduce the issue

bernatvadell commented 2 months ago

yes, we are using headless to false

petar-ps commented 2 months ago

I get this error on Docker if try to use defaultViewportor page.setViewport. On windows everything is fine.

Btw turnstile bypass does not work on Docker but it works on Windows i dont know why.

bernatvadell commented 2 months ago

I have reviewed a few things that could affect resource consumption:

vootsman commented 2 months ago

@vootsman Because the new version has updated the ppt patch, many errors occur. Please share the code where the above error occurs to make it easier to check.

I use the connect method to create a page, but I actually do the actual using of the browser by hand, so it sometimes works for hours, other times it crashes sooner (with the above error)

mdervisaygan commented 2 months ago

Can you try again with the latest version?

vootsman commented 2 months ago

Can you try again with the latest version?

I've been using for ~30 minutes with no crashes, so I'll call it success for now

Zvih commented 2 months ago

It seems issue gone, at least for now. Great work