How to get past Cloudflare protection when using headless Puppeteer

I need help with accessing a website that uses Cloudflare protection. When I try to visit the site using Puppeteer in headless mode, I get stuck on the “Checking your browser” screen and it never loads the actual page.

The weird thing is that when I set headless to false, everything works fine and I get redirected to the main site after a few seconds. But when I switch to headless mode, the script just hangs on the Cloudflare check page until it times out.

I already tried using the stealth plugin for puppeteer-extra but that didn’t work either. Also looked into some other scraping tools but they seem outdated.

It looks like Cloudflare can somehow detect that I’m running in headless mode. Has anyone found a way to make Puppeteer work with Cloudflare protection while keeping it headless?

Had this same problem a few months ago. What worked for me was adjusting viewport and device settings - Cloudflare’s gotten really good at detecting more than just the headless flag. Set your viewport to something normal like 1366x768 and match the device pixel ratio to a typical desktop. Also try different Chrome versions - older stable releases sometimes slip past their detection. Don’t try to hide everything, just make your browser fingerprint look completely ordinary.

Been fighting this for months. Rotating residential proxies + session management is the only thing that actually works consistently. Cloudflare doesn’t just check browser fingerprints - they’re tracking IP reputation, request patterns, timing, all of it. You can spoof chrome flags and fix window dimensions to beat headless detection, but you’ll still get blocked on the IP side. I switched to a service with clean residential IPs and keep sessions alive across multiple requests instead of starting fresh every time. Takes more setup work but it’s way more reliable than trying to fake a perfect browser.

cloudflare is tough but u might wanna try using playwright instead of puppeteer. i had better results with it. also, make sure ur user agent is legit and add some random delays between actions to mimic human behavior. helps a lot!