{"id":479,"date":"2024-06-07T05:41:19","date_gmt":"2024-06-07T05:41:19","guid":{"rendered":"https:\/\/www.scrapingbypass.com\/blog\/?p=479"},"modified":"2026-03-23T08:14:54","modified_gmt":"2026-03-23T08:14:54","slug":"how-to-bypass-cloudflare-with-puppeteer","status":"publish","type":"post","link":"https:\/\/www.scrapingbypass.com\/blog\/479.html","title":{"rendered":"How to bypass Cloudflare with Puppeteer?\u00a0"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Are you tired of encountering the dreaded Cloudflare captcha or being blocked from accessing a website altogether? If so, you&#8217;re not alone. Many web scrapers and automation tools have faced the same challenge when trying to <a href=\"https:\/\/www.scrapingbypass.com\/\" data-type=\"link\" data-id=\"https:\/\/www.scrapingbypass.com\/\">bypass Cloudflare&#8217;s<\/a> WAF (Web Application Firewall) protection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Fortunately, there is a solution. In this article, we&#8217;ll show you how to bypass Cloudflare with Puppeteer, a popular Node.js library for web scraping and automation. We&#8217;ll also introduce you to a powerful tool called &#8220;Scrapingbypass API&#8221; that can help you achieve your goals more easily and efficiently.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"345\" src=\"https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-1024x345.png\" alt=\"bypass cloudflare shield\" class=\"wp-image-14\" srcset=\"https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-1024x345.png 1024w, https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-300x101.png 300w, https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-768x259.png 768w, https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-1536x517.png 1536w, https:\/\/www.scrapingbypass.com\/blog\/wp-content\/uploads\/2023\/07\/Cloudflare-shield-bypass-2048x690.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>What is Cloudflare?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before we dive into the specifics of bypassing Cloudflare with Puppeteer, let&#8217;s first take a moment to understand what Cloudflare is and why it can be such a headache for web scrapers and automation tools.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Cloudflare is a cloud-based security service that provides WAF protection, DDoS mitigation, and content delivery network (CDN) services to websites and web applications. It&#8217;s used by millions of websites worldwide, including some of the most popular and heavily trafficked sites on the internet.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When a user attempts to access a website that&#8217;s protected by Cloudflare, their request is first routed through Cloudflare&#8217;s servers. Cloudflare then performs a series of checks to determine whether the request is legitimate or not. If the request is deemed to be suspicious or malicious, Cloudflare will block it or present the user with a captcha to verify that they&#8217;re human.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Why is Cloudflare a Challenge for Web Scrapers and Automation Tools?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Web scrapers and automation tools can trigger Cloudflare&#8217;s WAF protection in a number of ways. For example, they may send too many requests in a short period of time, use an outdated or unsupported browser, or lack certain browser features or headers that Cloudflare expects to see.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When Cloudflare&#8217;s WAF protection is triggered, it can be very difficult to bypass. The captcha, in particular, is notoriously hard to solve programmatically, and many web scrapers and automation tools simply give up at this point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Bypassing Cloudflare with Puppeteer<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Puppeteer is a Node.js library that provides a high-level API for controlling headless or headful Chrome or Chromium browsers. It&#8217;s commonly used for web scraping, automation, and testing.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One of the advantages of using Puppeteer for web scraping and automation is that it can emulate a real user&#8217;s browser very closely. This can help to avoid triggering Cloudflare&#8217;s WAF protection in the first place.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here are some tips for bypassing Cloudflare with Puppeteer:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use a Realistic User-Agent<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Cloudflare checks the User-Agent header of incoming requests to determine whether they&#8217;re likely to be legitimate or not. Using a realistic User-Agent that matches the browser you&#8217;re emulating with Puppeteer can help to avoid triggering Cloudflare&#8217;s WAF protection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to set the User-Agent in Puppeteer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\n\n(async () =&gt; {\n  const browser = await puppeteer.launch();\n  const page = await browser.newPage();\n\n  await page.setUserAgent('Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/89.0.4389.90 Safari\/537.36');\n\n  await page.goto('https:\/\/example.com');\n\n  \/\/ ...\n\n  await browser.close();\n})();<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Enable Browser Features and Headers<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Cloudflare expects to see certain browser features and headers in incoming requests. Enabling these features and headers in Puppeteer can help to avoid triggering Cloudflare&#8217;s WAF protection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to enable browser features and headers in Puppeteer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\n\n(async () =&gt; {\n  const browser = await puppeteer.launch({\n    args: &#91;\n      '--enable-features=NetworkService,NetworkServiceInProcess',\n    ],\n  });\n  const page = await browser.newPage();\n\n  await page.setExtraHTTPHeaders({\n    'Accept-Language': 'en-US,en;q=0.9',\n  });\n\n  await page.goto('https:\/\/example.com');\n\n  \/\/ ...\n\n  await browser.close();\n})();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re enabling the NetworkService and NetworkServiceInProcess features in Chrome, and setting the Accept-Language header to a realistic value.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Slow Down Your Requests<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Sending too many requests in a short period of time can trigger Cloudflare&#8217;s WAF protection. Slowing down your requests can help to avoid this.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to slow down your requests in Puppeteer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\n\n(async () =&gt; {\n  const browser = await puppeteer.launch();\n  const page = await browser.newPage();\n\n  await page.goto('https:\/\/example.com', {\n    waitUntil: 'networkidle2',\n    timeout: 0,\n  });\n\n  await page.evaluate(() =&gt; {\n    \/\/ ...\n  });\n\n  await new Promise(resolve =&gt; setTimeout(resolve, 1000));\n\n  \/\/ ...\n\n  await browser.close();\n})();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re using the <code class=\"\">waitUntil<\/code> and <code class=\"\">timeout<\/code> options of the <code class=\"\">page.goto()<\/code> method to wait for the page to fully load, and we&#8217;re using <code class=\"\">setTimeout()<\/code> to introduce a delay between requests.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Use a Proxy or IP Pool<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Using a proxy or IP pool can help to avoid triggering Cloudflare&#8217;s WAF protection by distributing your requests across multiple IP addresses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to use a proxy in Puppeteer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\n\n(async () =&gt; {\n  const browser = await puppeteer.launch({\n    args: &#91;\n      `--proxy-server=${process.env.PROXY_URL}`,\n    ],\n  });\n  const page = await browser.newPage();\n\n  await page.goto('https:\/\/example.com');\n\n  \/\/ ...\n\n  await browser.close();\n})();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re using the <code class=\"\">--proxy-server<\/code> command-line option to set the proxy URL.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Introducing Scrapingbypass API<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While the tips we&#8217;ve provided can help to bypass Cloudflare with Puppeteer, they may not be sufficient in all cases. Cloudflare&#8217;s WAF protection is constantly evolving, and what works today may not work tomorrow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s where Scrapingbypass API comes in. Scrapingbypass API is a powerful tool that can help you bypass Cloudflare&#8217;s WAF protection, Turnstile CAPTCHA, and 5-second shield with ease. It provides an HTTP API and a one-stop global dynamic data center\/residential IP proxy service, including interface addresses, request parameters, and return processing. It also supports setting Referer, browser UA, and headless status, among other browser fingerprint device features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of how to use Scrapingbypass API with Puppeteer:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const puppeteer = require('puppeteer');\nconst axios = require('axios');\n\n(async () =&gt; {\n  const browser = await puppeteer.launch({\n    args: &#91;\n      '--enable-features=NetworkService,NetworkServiceInProcess',\n      '--disable-features=IsolateOrigins,site-per-process',\n    ],\n  });\n  const page = await browser.newPage();\n\n  const url = 'https:\/\/example.com';\n  const apiKey = process.env.THROUGH_CLOUD_API_KEY;\n  const apiUrl = `https:\/\/api.throughcloud.com\/v1\/http\/get?url=${encodeURIComponent(\n    url\n  )}&amp;api_key=${apiKey}`;\n\n  const response = await axios.get(apiUrl);\n  const content = response.data.content;\n\n  await page.setContent(content);\n\n  \/\/ ...\n\n  await browser.close();\n})();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we&#8217;re using the Scrapingbypass API HTTP API to fetch the content of a web page that&#8217;s protected by Cloudflare. We&#8217;re then using Puppeteer&#8217;s <code class=\"\">page.setContent()<\/code> method to set the content of the page.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bypassing Cloudflare&#8217;s WAF protection, Turnstile CAPTCHA, and 5-second shield can be a challenge for web scrapers and automation tools. However, by using Puppeteer to emulate a real user&#8217;s browser closely and following the tips we&#8217;ve provided, you can improve your chances of success.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For even better results, consider using Scrapingbypass API, a powerful tool that can help you bypass Cloudflare&#8217;s defenses with ease. With Scrapingbypass API, you can focus on your web scraping or automation tasks, without worrying about being blocked or slowed down by Cloudflare.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Are you tired of encountering the dreaded Cloudflare captcha or being blocked from accessing a website altogether? If so, you&#8217;re not alone. Many web scrapers and automation tools have faced the same challenge when trying to bypass Cloudflare&#8217;s WAF (Web Application Firewall) protection. Fortunately, there is a solution. In this article, we&#8217;ll show you how [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-479","post","type-post","status-publish","format-standard","hentry","category-bypass-cloudflare"],"_links":{"self":[{"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/posts\/479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/comments?post=479"}],"version-history":[{"count":2,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions"}],"predecessor-version":[{"id":705,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/posts\/479\/revisions\/705"}],"wp:attachment":[{"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/media?parent=479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/categories?post=479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.scrapingbypass.com\/blog\/wp-json\/wp\/v2\/tags?post=479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}