puppeteer-extra: [Bug] Sites with hard challenges of CloudFlare do not work with `browser.newPage()` and call `browser.pages()` Disrupted them tabs!

The site ‍‍‍‍https://www.000webhost.com/cpanel-login has a hard challenge for Cloudflare and does not open normal. So I used the puppeteer-extra-plugin-stealth plugin.

This site will not be opened with the browser.newPage(). (The tick we hit again the same challenge page) But in the first default tab, which is always open, this site opens! (We tick and the site opens.) This is strange so far, but it gets strange.

So I tried to use the same tab without newPage(). I tried to get the pages first: var pages = await browser.pages(); Then open the site in the first tab with pages[0].goto. But this time the site didn’t open! (I mean fails to dissolve challenge Cloudflare)

It looks like it doesn’t open when I call ‍newPage(). And also when the pages() method is called, all tabs for this site are disrupted. (Even the first tab that can normally open this site)

I was confused and I think there’s a bug here.

Sample code:

import puppeteerExtra from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';

var puppeteer = puppeteerExtra.use(StealthPlugin());

var browser = await puppeteer.launch({ headless: false });
// const page = await browser.newPage();

var pages = await browser.pages();
pages[0].goto('https://www.000webhost.com/cpanel-login');

Versions:

node v19.7.0
puppeteer@21.1.1
puppeteer-extra@3.3.6
puppeteer-extra-plugin-stealth@2.11.2
Chrome Version 116.0.5845.141

Video:

https://github.com/berstend/puppeteer-extra/assets/246721/f527b517-5fb5-4941-8c81-1bd37d9b1046

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 63

Most upvoted comments

you guys can back to puppeteer version 5.5.0, all the problems will be solved, however, it quite old

@mowatermelon Thanks for your answer.

It wasn’t bad as a temporary trick. But it has problems and of course the bug still exists.

By setting userDataDir, we can maintain the previous status and after solving the challenge manually, the next time Chrome opens, we can open the site without the challenge page.

But when the CloudFlare cookie session expires, everything goes back to the way it was before. If we use, for example, newPage(), the challenge will not be solved. Or if we reach the first tab with the help of pages()[0], everything is broken there and the site’s challenge is not solved in any way.

Unless we repeat the trick again, i.e. temporarily remove the call to pages() and run Chrome once to pass the challenge. Then return that function to our code.

In general, it did not cure much pain!

“puppeteer”: “5.5.0”, you should change to this version, I will share the detail problems later.

Why that version specifically?

I can confirm that it works also on version “puppeteer”: “^9.1.1”. Anything higher than that does not work for me

Remove --single-process arg, cloudflare detects it.

In the example you provided https://nopecha.com/demo/cloudflare

The captcha is permanent. Regardless your setup. You need to solve it to bypass. We saw it before on other sites.

However, if human can’t pass it, then they detect you

I modified the code and now pass it by click

        const stealth = StealthPlugin()
        stealth.enabledEvasions.delete('iframe.contentWindow')
        stealth.enabledEvasions.delete('media.codecs')
        puppeteer.use(stealth);
        (async () => {

            const browser = await puppeteer.launch({
                headless: false,
                // @ts-ignore
                targetFilter: target => !!target.url()
            })
            var page = await browser.pages()
            // @ts-ignore
            page = page[0]
            // @ts-ignore
            await page.goto('https://nopecha.com/demo/cloudflare')
        })()

has anyone found solutions to this? I can’t bypass captcha on cloudflare anymore

Unfortunately, this problem was very serious and acute. And I had to use the service FlareSolverr. This is a proxy to bypass cloudflare and they use selenium. I just send my first page to it and return only the cf_clearance cookie, set it to my puppeteer and continue…

I have a method that partially solves my problem. It involves running two browsers: one that I use locally to pass the Cloudflare check, and a second identical browser (with the same version) running remotely. This remote browser is proxied and uses my user data that I pass to it. This method works, but it is extremely inconvenient.

A browser initiated with Puppeteer always triggers an endless Cloudflare verification loop, whereas a manually launched browser does not have this issue. Clearly, Cloudflare detects the use of Puppeteer. Out of curiosity, I compared all properties of the window object in a headless browser and a regular browser. I did not notice any significant differences except for one that serves as an indicator of Puppeteer usage for websites. This is the document.createElement function. For some reason, Puppeteer uses a proxy version of this function instead of the standard one, which can be easily detected with the following code:

function isPuppeteer(){
return Object.getOwnPropertyNames(document).includes('createElement')
}

This needs to be fixed to make Puppeteer less detectable. Please help me reach out to the developers and comment on the discussion I opened: #https://github.com/puppeteer/puppeteer/issues/12589, so this problem does not go unnoticed.

puppeteer-real-browser didn’t help, it works exactly the same as regular puppeteer, not worth bothering with it. The solution with targetFilter is not a solution to the main problem at all, this method just skips loading pages that have redirects. That’s what I was hoping for, but I misunderstood the users’ posts above

Установите

docker run -d --log-driver json-file --log-opt max-size=10m --log-opt max-file=3 --name=cfclearance  -p 3000:3000 -e PORT=3000 -e browserLimit=20 -e timeOut=30000 --restart unless-stopped zfcsoftware/cf-clearance-scraper

docker run -d --log-driver json-file --log-opt max-size=10m --log-opt max-file=3 --name=flaresolverr -p 8191:8191 -e LOG_LEVEL=info --restart unless-stopped ghcr.io/flaresolverr/flaresolverr:latest

Отправьте запрос на cf-clearance-scraper с помощью got или request,

curl -L -X POST 'http://localhost:3000/cf-clearance-scraper' \
-H 'Content-Type: application/json' \
--data-raw '{
  "url": "https://www.domain.com/minecraft/",
	"proxy": {
		"host": "101.102.103.104",
		"port": "1234",
		"username": "login",
		"password": "password"
	}
}'

если он не решит, то шлите на flaresolverr

curl -L -X POST 'http://localhost:8191/v1' \
-H 'Content-Type: application/json' \
--data-raw '{
  "cmd": "request.get",
  "url": "https://www.domain.com/",
  "maxTimeout": 30000,
	"returnOnlyCookies": true,
	"proxy": {
		"url": "http://101.102.103.104:1234",
		"username": "login",
		"password": "password"
	}
}'

Полученные куки устанавливаете уже в свой браузер

const result = {
	"status": "ok",
	"message": "Challenge not detected!",
	"solution": {
		"url": "https://www.domain.com/",
		"status": 200,
		"cookies": [
			{
				"domain": ".domain.com",
				"expiry": 1752087165,
				"httpOnly": false,
				"name": "name1",
				"path": "/",
				"sameSite": "Lax",
				"secure": false,
				"value": "value1"
			},
			{
				"domain": ".domain.com",
				"expiry": 1718477565,
				"httpOnly": false,
				"name": "name2",
				"path": "/",
				"sameSite": "Lax",
				"secure": false,
				"value": "value2"
			}
		],
		"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
	},
	"startTimestamp": 1718391160826,
	"endTimestamp": 1718391167716,
	"version": "3.3.19"
}

await page.setCookie(...cookies);

Проект cf-clearance-scraper построен на основе проекта puppeteer-real-browser. Так что есть смысл посмотреть как сделан обход CF.

Cloudflare was debofuscated, a solution was found, but you will need to change many things in your code.

Temporary use targetFilter, it disables Cloudflare check, but does not solve the root cause.

        let flags = {
            headless,
            userDataDir,
           targetFilter: target => !!target.url()
        }

If cloudflare patches this, then will share a solution.

This doesn’t make sense to me, I am using puppeteer to connect to chrome on android just connecting through the dev tools port, and even pages not created by puppeteer, as soon as they are “touched” cannot get past cloudflare

I have tried the constant page refresh problem when trying to switch to Cloudflare on the aforementioned sites. I have been repeatedly signing up on a different site for about 10 hours and they use cloudflare premium captcha. It passed all of them without any problem without needing to touch it. I don’t see any problem in the package right now except fingerprint. Could you please try the package? I tried it on many sites like 000webhost openai etc. It was successful on all of them.

@Hillcow @joeledwardson @ergcode @NabiKAZ @wlc108 @mowatermelon

https://www.npmjs.com/package/puppeteer-real-browser

I had this problem too, so I had to find a solution and publish it. I found a way to make the browser look real. I connected to the browser with Puppeteer. I exported the browser and page created with Puppeteer. You can use all the functions you use with Puppeteer here. Proxy supported.