puppeteer-extra icon indicating copy to clipboard operation
puppeteer-extra copied to clipboard

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

Open NabiKAZ opened this issue 2 years ago • 63 comments
trafficstars

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
[email protected]
[email protected]
[email protected]
Chrome Version 116.0.5845.141

Video:

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

NabiKAZ avatar Sep 03 '23 09:09 NabiKAZ

You can give it a try. Await puppeteer.launch ({userDataDir: path.join (os.homedir (), '.aaa-data'),} add a unified cache folder, then all tab pages that jump to the same address can share a cache.

mowatermelon avatar Sep 04 '23 14:09 mowatermelon

@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!

NabiKAZ avatar Sep 05 '23 00:09 NabiKAZ

same problem :(

NoeelGz avatar Sep 11 '23 01:09 NoeelGz

I'm experiencing the same thing on other sites. What seems to be happening from my analysis, is the initial tab is "untouched" by puppeteer. So I can do whatever I want in the initial tab and I'm not detected. If I have puppeteer open it's own tab, and I manually take all actions in that tab, then I get detected as a bot. Alternatively, if I have puppeteer make the initial tab active then I take manual action, I'm detected as a bot.

So it seems any tab that gets "touched" by Puppeteer, gets detected somehow. When I look at Browser Fingerprinting, this seems to be the case. I'm not sure what they're using to detect Puppeteer even with stealth enabled.

wlc108 avatar Sep 16 '23 19:09 wlc108

creepjs (https://abrahamjuliot.github.io/creepjs/) is detecting puppeteer when you use any tab besides the start-up tab.

image

Take note that 205 lies are being detected, here's a sample: image

I'm launching with the latest version of Google Chrome(Version 117.0.5938.92 (Official Build) (64-bit)) on Windows10 and am using the latest Puppeteer Node.js version alongside the stealth plugin with all evasions active.

Another creepjs image: image

NodePuppeteer avatar Sep 26 '23 13:09 NodePuppeteer

Any ideas about how Cloudflare is detecting Puppeteer?

I don't know the ins and outs of Puppeteer but I know they use the chrome dev tools protocol, the same as chrome dev tools.

However if I open https://nowsecure.nl/ with chrome dev tools open I can get through fine?

joeledwardson avatar Sep 30 '23 11:09 joeledwardson

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...

NabiKAZ avatar Oct 01 '23 04:10 NabiKAZ

Puppeteer can be detected by https://abrahamjuliot.github.io/creepjs/ if that helps. It's not just that it detects a bot, it detects PUPPETEER. pup

wlc108 avatar Oct 02 '23 18:10 wlc108

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...

For now this is a solution with no alternatives. Puppeteer or playwright + any anti-detection methods cannot solve problems with cloudflare.

I'll make a clarification. If your ip or proxy is not on the list of suspicious ones, then there is an option to get challenge v1, which can be completed without a click and with the launch command await puppeteer.launch({ targetFilter: (target) => !!target.url() }); But if your ip is suspicious, then targetFilter: (target) => !!target.url() blocks work with the iframe and the possibility of manipulating the challenge checkbox disappears.

ergcode avatar Oct 04 '23 23:10 ergcode

How is it that FlareSolverr works? Surely if Puppeteer is detected by Cloudflare then so would Selenium

joeledwardson avatar Oct 07 '23 20:10 joeledwardson

How is it that FlareSolverr works? Surely if Puppeteer is detected by Cloudflare then so would Selenium

FlareSolverr uses undetected-chromedriver. UC uses completely different detection bypass methods, which are still difficult to replicate in puppeteer and puppeteer-extra.

ergcode avatar Oct 07 '23 20:10 ergcode

Hello, https://www.npmjs.com/package/cloudflare-scraper With this bookshelf you can scrape and get cookies.

mdervisaygan avatar Oct 13 '23 16:10 mdervisaygan

Hello, https://www.npmjs.com/package/cloudflare-scraper With this bookshelf you can scrape and get cookies.

Unfortunately, they have not yet implemented proxies. But this project can be copied and a proxy can be added.

ergcode avatar Oct 13 '23 16:10 ergcode

Any updates on this? Does anyone understand how creepjs detects Puppeteer and what could be done to avoid detection from the Puppeteer source itself?

joeledwardson avatar Nov 01 '23 12:11 joeledwardson

Any update?

fabian-rohr avatar Nov 29 '23 13:11 fabian-rohr

@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.

mdervisaygan avatar Dec 22 '23 22:12 mdervisaygan

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

joeledwardson avatar Dec 23 '23 12:12 joeledwardson

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.

mdervisaygan avatar Dec 23 '23 13:12 mdervisaygan

Unfortunately, this won't work for my use case as I launch chrome on android via ADB, forward the chrome dev tools port and then connect, so no launching is involved.

Hence why I am not sure this has fixed the issue, the only change I can see from the code in connecting is setting the user agent. If it works this is good news though

joeledwardson avatar Dec 24 '23 19:12 joeledwardson

Unfortunately, this won't work for my use case as I launch chrome on android via ADB, forward the chrome dev tools port and then connect, so no launching is involved.

Hence why I am not sure this has fixed the issue, the only change I can see from the code in connecting is setting the user agent. If it works this is good news though

The important part to make it work is the cdp session which starts chrome on a port. We start a real browser on a port on the computer and connect with puppeteer's connect feature. The user agent is set to be the same as the created browser's agent. Here are some examples of it working: https://www.youtube.com/watch?v=OgQOaVNTPa4 https://www.youtube.com/watch?v=vfzEHsoJpuw https://www.youtube.com/watch?v=iTSVrtf8xXI

I will add linux support soon. If there is a site you want me to try, I can try it. In your case, after switching to cloudflare, the cookie can be taken and used with adb.

mdervisaygan avatar Dec 24 '23 20:12 mdervisaygan

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

nhhoang avatar Jan 10 '24 00:01 nhhoang

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

Can I have your example package.json?

ergcode avatar Jan 10 '24 00:01 ergcode

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

nhhoang avatar Jan 10 '24 01:01 nhhoang

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

Why that version specifically?

bn-l avatar Jan 11 '24 03:01 bn-l

@nhhoang Can you provide more information and tutorial on how you made it work? Thank you!

steinerx avatar Jan 18 '24 19:01 steinerx

"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

steinerx avatar Jan 19 '24 07:01 steinerx

"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

Does not work for me. Did you downgrade anything else too, like the stealth package or the puppeteer-core package?

smillwith61 avatar Jan 28 '24 22:01 smillwith61

@smillwith61 After downgrading to "puppeteer": "^9.1.1", Do not use puppeteer-stealth package. Use the first tab to do your stuff.

let pages = await browser.pages();
let page = pages[0]

steinerx avatar Jan 29 '24 07:01 steinerx

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

Mohamed3on avatar Feb 10 '24 13:02 Mohamed3on

joeledwardson

Unfortunately, this won't work for my use case as I launch chrome on android via ADB, forward the chrome dev tools port and then connect, so no launching is involved. Hence why I am not sure this has fixed the issue, the only change I can see from the code in connecting is setting the user agent. If it works this is good news though

The important part to make it work is the cdp session which starts chrome on a port. We start a real browser on a port on the computer and connect with puppeteer's connect feature. The user agent is set to be the same as the created browser's agent. Here are some examples of it working: https://www.youtube.com/watch?v=OgQOaVNTPa4 https://www.youtube.com/watch?v=vfzEHsoJpuw https://www.youtube.com/watch?v=iTSVrtf8xXI

I will add linux support soon. If there is a site you want me to try, I can try it. In your case, after switching to cloudflare, the cookie can be taken and used with adb.

My case is that I am detected as bot when I run the command via puppeteer "await browser.pages() ;", i.e. whenever puppeteer starts touching the page. I have already used puppeteer-extra-plugin-stealth but still nothing changed.

It seems that your puppeteer-real-browser is not solving issue like mine?

Kiaala6 avatar Feb 13 '24 16:02 Kiaala6