
Rajinder Singh
Deep Learning Researcher

I feel that the more automated tasks that are available nowadays, the more they are valued, so the challenges become more apparent and difficult. For example, Cloudflare currently provides strong security measures to protect websites from all forms of automation tools.
But navigating these security features can be challenging for developers and organizations working on automation projects such as web scraping, data extraction, or testing. However, with the right tools and strategies, you can effectively address these challenges while remaining compliant with legal and ethical standards.
In this tutorial, then, I'll explore how to effectively solve Cloudflare like Turnstile by using Puppeteer and Node.js and the help from Captcha solver
Redeem Your CapSolver Bonus Code
Boost your automation budget instantly!
Use bonus code CAPN when topping up your CapSolver account to get an extra 5% bonus on every recharge — with no limits.
Redeem it now in your CapSolver Dashboard
.
Cloudflare's Turnstile is a sophisticated security feature designed to challenge users attempting to access protected sites. It employs a combination of techniques, including JavaScript challenges, CAPTCHAs, and behavior analysis, to assess whether the user is a legitimate human or an automated bot. For developers, this means that bypassing Turnstile requires more than just traditional web scraping techniques.
Before diving into the implementation, ensure you have the following tools and resources:
CapSolver is a powerful tool designed to assist with solving CAPTCHAs and other automated challenges. As websites increasingly deploy complex security mechanisms to deter bots and scrapers, CapSolver provides a reliable solution for overcoming these obstacles.
Comprehensive CAPTCHA Solutions: CapSolver supports various types of CAPTCHAs, including reCAPTCHA, Cloudflare, ImageToText and more, enabling seamless challenge resolution.
High Accuracy: Leveraging advanced algorithms and machine learning models, CapSolver ensures high accuracy in solving CAPTCHAs, reducing failure rates and improving efficiency.
Easy Integration: CapSolver offers a user-friendly API that integrates easily with your existing automation tools, including Puppeteer. This enables you to automate CAPTCHA solving as part of your web scraping or testing workflows.
24/7 Support: CapSolver provides robust customer support to help resolve any issues or questions, ensuring smooth operation and timely assistance.
Here’s a more detailed and enriched version of your explanation, along with a concluding section for the article:
Using Puppeteer and JavaScript to Call the CapSolver API and Access the Website
Retrieving the SiteKey for Turnstile
Using JavaScript to Call the CapSolver API and Obtain a Token
// npm install axios puppeteer-core
const axios = require('axios');
const puppeteer = require("puppeteer-core");
const api_key = "YOUR_API_KEY";
const site_key = "0xxxxxx";
const site_url = "https://xxx.xxx.xxx/xxx";
const proxy = "http://xxx:xxx@x.x.x.x:x"
async function capsolver() {
const payload = {
clientKey: api_key,
task: {
type: 'AntiTurnstileTaskProxyLess',
websiteKey: site_key,
websiteURL: site_url,
metadata: {
action: '', // optional,
type: "turnstile"
},
// proxy: proxy
}
};
try {
const res = await axios.post("https://api.capsolver.com/createTask", payload);
const task_id = res.data.taskId;
if (!task_id) {
console.log("Failed to create task:", res.data);
return;
}
console.log("Got taskId:", task_id);
while (true) {
await new Promise(resolve => setTimeout(resolve, 1000)); // Delay for 1 second
const getResultPayload = {clientKey: api_key, taskId: task_id};
const resp = await axios.post("https://api.capsolver.com/getTaskResult", getResultPayload);
const status = resp.data.status;
if (status === "ready") {
return resp.data.solution.token;
}
if (status === "failed" || resp.data.errorId) {
console.log("Solve failed! response:", resp.data);
return;
}
}
} catch (error) {
console.error("Error:", error);
}
}
const wait = (ms) => new Promise(resolve => setTimeout(resolve, ms));
async function reqSite(){
let coockie;
await capsolver().then(token => {
console.log(token);
coockie = token;
});
const browser = await puppeteer.launch({
headless: false,
executablePath: "Browser Path"
});
const page = await browser.newPage();
await wait(500);
await page.setCookie({
name: "cf_clearance",
value: coockie,
domain: "xx.xx.xx"
});
await wait(500);
await page.goto(site_url);
// TODO
await page.close();
await browser.disconnect();
}
reqSite().then();
In this tutorial, we explored how to effectively navigate Cloudflare's Turnstile security using Puppeteer and the CapSolver API. By understanding the intricacies of Cloudflare's protective measures and leveraging powerful tools like CapSolver, developers can successfully automate tasks such as web scraping, data extraction, and testing without compromising compliance with legal standards.
Automation continues to grow in importance across various industries, and with it, the challenges posed by advanced security systems like Turnstile. By staying informed and utilizing the right strategies, you can ensure that your automation projects run smoothly and efficiently.
If you're working on similar projects, don’t hesitate to explore CapSolver for robust CAPTCHA-solving solutions. For more insights, be sure to check out related topics such as web scraping best practices and Puppeteer usage tips.
CapSolver is a legitimate tool, and its legality depends on how it is used.
As long as automation, testing, or scraping is done with proper authorization and in compliance with local laws and website policies, it is acceptable.
Avoid using such tools for unauthorized scraping or malicious activities, as that may violate terms of service or laws.
Cloudflare Turnstile validates much more than a CAPTCHA. It also checks:
Pure HTTP requests cannot accurately simulate a real browser environment.
Puppeteer provides a full browser context, making it more reliable when bypassing Cloudflare's layered security checks.
Possible reasons include:
Troubleshooting steps:
websiteURL used when creating the task.Learn how to fix the "failed to verify cloudflare turnstile token" error. This guide covers causes, troubleshooting steps, and how to defeat cloudflare turnstile with CapSolver.

Discover the best cloudflare challenge solver tools, compare API vs. manual automation, and find optimal solutions for your web scraping and automation needs. Learn why CapSolver is a top choice.
