TurnstileTask | Cloudflare Challenge
All Turnstile subtypes are automatically supported: manual, non-interactive, and invisible. Therefore, there is no need to specify a subtype for a regular captcha.
Check out all three options of captcha recognition and choose the most convenient one for you.
Option 1 (Turnstile)
You are required to solve a regular turnstile captcha, as here. Note that the CAPTCHA on CloudFlare pages may look identical. Learn more about how to distinguish between a regular Turnstile and a Cloudflare Challenge at the end of the article.
Request parameters
type
<string>requiredTurnstileTaskProxyless
websiteURL
<string>requiredThe page address, where the captcha is solved
websiteKey
<string>requiredTurnstile key
pageAction
<string>optionalThe action
field that can be found in the callback function to load the captcha
Option 2 (CloudFlare)
You are working through a browser and you need to get a token to pass CloudFlare.
Request parameters
type
<string>requiredTurnstileTaskProxyless
websiteURL
<string>requiredThe page address, where the captcha is solved
websiteKey
<string>requiredTurnstile key
cloudflareTaskType
<string>requiredtoken
pageAction
<string>requiredThe action
field can be found in the callback function to load the captcha. If cloudflareTaskType is used, the action
is usually "managed" or "non-interactive".
userAgent
<string>requiredBrowser User-Agent.
Pass only the actual UA from Windows OS. Now this is: userAgentPlaceholder
data
<string>requiredThe value of the data field can be taken from the cData
parameter.
pageData
<string>requiredThe value of the pageData field can be taken from the chlPageData
parameter.
It is not necessary to pass a proxy to get the token.
These parameters are in the object that is passed during captcha creation to the function window.turnstile.render(el, paramsObj)
. You can get them, for example, by executing JavaScript before loading other scripts:
(function () {
const obj = {
render: function () {
const { action, cData, chlPageData } = arguments[1];
const params = [
["action", action],
["data", cData],
["pageData", chlPageData],
];
console.table(params)
}
};
Object.defineProperty(window, "turnstile", {
get: () => {
return obj;
},
});
})();
When calling window.turnstile.render(el, paramsObj)
the captcha on the page is loaded, and if successful, a callback
function is called to pass information about the solution.
window.turnstile.render(el, paramsObj):
el
: The DOM element to insert the captcha into.
paramsObj
: A params object containing information about the captcha and instructions for solving it. This object usually contains fields such as
sitekey, action, cData, chlPageData, callback.
callback
– is a callback function after the captcha is successfully passed.
Option 3 (CloudFlare)
You are working using queries, and you need cf_clearance cookies. It is required that you need your proxies.
Request parameters
type
<string>requiredTurnstileTask
websiteURL
<string>requiredThe page address, where the captcha is solved
websiteKey
<string>requiredTurnstile key (you can pass any string)
cloudflareTaskType
<string>optionalcf_clearance
htmlPageBase64
<string>requiredBase64 encoded html page "Just a moment" which is given with code 403 when accessing a site with this protection.
Example of obtaining a string htmlPageBase64:
var htmlContent = document.documentElement.outerHTML;
var htmlBase64 = btoa(unescape(encodeURIComponent(htmlContent)));
console.log(htmlBase64);
userAgent
<string>requiredBrowser User-Agent.
Pass only the actual UA from Windows OS. Now this is: userAgentPlaceholder
proxyType
<string>requiredhttp - regular http/https proxy;
https - try this option only if "http" doesn't work (required for some custom proxies);
socks4 - socks4 proxy;
socks5 - socks5 proxy.
proxyAddress
<string>requiredIPv4/IPv6 proxy IP address. Not allowed:
- using of hostnames;
- using transparent proxies (where you can see the client's IP);
- using proxies on local machines.
proxyPort
<integer>requiredProxy port.
proxyLogin
<string>requiredProxy-server login.
proxyPassword
<string>requiredProxy-server password.
Examples of requests
Option 1: Normal Turnstile
https://api.capmonster.cloud/createTask
Request
{
"clientKey":"API_KEY",
"task":
{
"type":"TurnstileTaskProxyless",
"websiteURL":"http://tsmanaged.zlsupport.com",
"websiteKey":"0x4AAAAAAABUYP0XeMJF0xoy"
}
}
Response
{
"errorId":0,
"taskId":407533072
}
Option 2. CloudFlare (token)
https://api.capmonster.cloud/createTask
Request
{
"clientKey": "API_KEY",
"task": {
"type": "TurnstileTask",
"websiteURL": "https://site.com",
"websiteKey": "0x4AAAAAAADnPIDROrmt1Wwj",
"cloudflareTaskType": "token",
"userAgent":"userAgentPlaceholder",
"pageAction": "managed",
"pageData": "HUHDWUHuhuwfiweh32..uh2uhuhyugYUG=",
"data": "874291f4retD1366"
}
}
Response
{
"errorId":0,
"taskId":407533072
}
Option 3. CloudFlare(cookie)
https://api.capmonster.cloud/createTask
Request
{
"clientKey":"API_KEY",
"task": {
"type":"TurnstileTask",
"websiteURL":"https://nowsecure.nl",
"websiteKey":"xxxxxxxxxx",
"cloudflareTaskType": "cf_clearance",
"htmlPageBase64": "PCFET0NUWVBFIGh0...vYm9keT48L2h0bWw+",
"userAgent": "userAgentPlaceholder",
"proxyType":"http",
"proxyAddress":"8.8.8.8",
"proxyPort":8080,
"proxyLogin":"proxyLoginHere",
"proxyPassword":"proxyPasswordHere"
}
}
Response
{
"errorId":0,
"taskId":407533072
}
GetTaskResult method
Use the getTaskResult method to get the Turnstile solution. Depending on the system load, you will get a response after a time in the range of 5 to 20s.
Property | Type | Description |
---|---|---|
cf_clearance | String | A special Cloudflare cookie that you can substitute into your browser |
token | String | Use a token when calling a callback function |
How to distinguish between a regular Turnstile and a Cloudflare Challenge
A Cloudflare challenge can look different.
Normal variant:
Stylized variants:
To be finally convinced of the presence of Cloudflare, you can open the developer tools, look at the traffic, examine the page code, and see the characteristic signs:
- The first request to the site returns a 403 code:
- The form with the id challenge-form has an action attribute (not to be confused with the action from the parameters for turnstile captcha) containing the
__cf_chl_f_tk=
parameter:
- The page contains two similar
<script>
tags that create a new value in thewindow
object:
Example of solution implementation using Selenium on Node.js
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
(async function example() {
const options = new chrome.Options();
options.addArguments('--auto-open-devtools-for-tabs')
const driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
try {
driver.executeScript(`
window.turnstile = new Proxy(window.turnstile, {
get(target, prop) {
if (prop === 'render') {
return function(a, b) {
let p = {
type: "TurnstileTaskProxyless",
websiteKey: b.sitekey,
websiteURL: window.location.href,
data: b.cData,
pagedata: b.chlPageData,
action: b.action,
userAgent: navigator.userAgent
}
console.log(JSON.stringify(p))
window.params = p;
window.turnstileCallback = b.callback;
return target.render.apply(this, arguments);
}
}
return target[prop];
}
});
`)
driver.get('SITE WITH CAPTCHA');
const params = await driver.executeScript(`
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(window.params)
}, 2000)
})
`);
if (params) {
const data = {
clientKey: 'API KEY',
task: {
type: 'TurnstileTaskProxyless',
websiteURL: params.websiteURL,
websiteKey: params.websiteKey,
data: params.data,
action: params.action
}
}
const createResult = await fetch('https://api.capmonster.cloud/createTask', {
method: 'post',
body: JSON.stringify(data)
});
const createTaskResult = await createResult.json()
if (createTaskResult.taskId) {
const asyncDelay = (timeout) =>
new Promise(resolve => {
setTimeout(() => {
resolve();
}, timeout);
});
const getTaskResult = async (taskId) => {
const taskResult = await fetch('https://api.capmonster.cloud/getTaskResult', {
method: 'post',
body: JSON.stringify({
"clientKey":"API KEY",
"taskId": createTaskResult.taskId
})
});
const taskResponse = await taskResult.json();
if (taskResponse.status === 'processing') {
await asyncDelay(5000);
return await getTaskResult(taskId)
}
return taskResponse;
}
const taskRes = await getTaskResult(createTaskResult.taskId)
if (taskRes.solution) {
await driver.executeScript(`
window.turnstileCallback(${taskRes.solution.token});
`);
}
}
}
//DO SOMETHING
} finally {
await driver.quit();
}
})();
Use SDK Library
- JavaScript
- Python
- C#
// https://github.com/ZennoLab/capmonstercloud-client-js
import { CapMonsterCloudClientFactory, ClientOptions, TurnstileRequest } from '@zennolab_com/capmonstercloud-client';
document.addEventListener('DOMContentLoaded', async () => {
const cmcClient = CapMonsterCloudClientFactory.Create(new ClientOptions({ clientKey: '<your capmonster.cloud API key>' }));
console.log(await cmcClient.getBalance());
const turnstileRequest = new TurnstileRequest({
websiteURL: 'https://tsinvisble.zlsupport.com',
websiteKey: '0x4AAAAAAABUY0VLtOUMAHxE',
cloudflareTaskType: 'cf_clearance',
proxyType: 'http',
proxyAddress: '8.8.8.8',
proxyPort: 8080,
proxyLogin: 'proxyLoginHere',
proxyPassword: 'proxyPasswordHere',
pageData: 'pageDataHere',
data: 'dataHere',
htmlPageBase64: 'htmlPageBase64Here',
userAgent: 'userAgentHere',
});
console.log(await cmcClient.Solve(turnstileRequest));
});
# https://github.com/ZennoLab/capmonstercloud-client-python
# Cloudflare Turnstile:
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import TurnstileRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonsterCloud API key
cap_monster_client = CapMonsterClient(options=client_options)
turnstile_request = TurnstileRequest(
websiteURL="http://tsmanaged.zlsupport.com", # Replace with the URL of the page with the captcha
websiteKey="0x4AAAAAAABUYP0XeMJF0xoy" # Replace with the website key for the captcha
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(turnstile_request)
responses = asyncio.run(solve_captcha())
print(responses)
# Cloudflare Challenge (token)
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import TurnstileProxylessRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonsterCloud API key
cap_monster_client = CapMonsterClient(options=client_options)
turnstile_request = TurnstileProxylessRequest(
websiteURL="https://example.com", # Replace with the URL of the page with the captcha
websiteKey="0x4AAAAAAABUYP0XeMJF0xoy", # Replace with the website key for the captcha
data="YOUR_DATA_HERE",
pageAction="managed",
cloudflareTaskType="token",
pageData="YOUR_PAGE_DATA_HERE",
userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" # Use the current userAgent
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(turnstile_request)
responses = asyncio.run(solve_captcha())
print(responses)
# Cloudflare Challenge (cookie cf_clearance)
import asyncio
from capmonstercloudclient import CapMonsterClient, ClientOptions
from capmonstercloudclient.requests import TurnstileRequest
client_options = ClientOptions(api_key="your_api_key") # Replace with your CapMonsterCloud API key
cap_monster_client = CapMonsterClient(options=client_options)
turnstile_request = TurnstileRequest(
websiteURL="https://example.com", # Replace with the URL of the page with the captcha
websiteKey="0x4AAAAAAABUYP0XeMJF0xoy", # Replace with the website key for the captcha
cloudflareTaskType="cf_clearance",
userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36", # Use the current userAgent
htmlPageBase64="htmlPageBase64Here",
proxyType="http", # Type of proxy (http, https, socks4, socks5)
proxyAddress="8.8.8.8",
proxyPort=8000,
proxyLogin="proxyLoginHere",
proxyPassword="proxyPasswordHere"
)
async def solve_captcha():
return await cap_monster_client.solve_captcha(turnstile_request)
responses = asyncio.run(solve_captcha())
print(responses)
// https://github.com/ZennoLab/capmonstercloud-client-dotnet
// Cloudflare Turnstile:
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task Main(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var turnstileRequest = new TurnstileProxylessRequest
{
WebsiteUrl = "http://tsmanaged.zlsupport.com", // Replace with the URL of the page with the captcha
WebsiteKey = "0x4AAAAAAABUYP0XeMJF0xoy" // Replace with the website key for the captcha
};
var turnstileResult = await cmCloudClient.SolveAsync(turnstileRequest);
Console.WriteLine("Captcha Solution: " + turnstileResult.Solution.Value);
}
}
// Cloudflare Challenge (token):
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task Main(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var turnstileRequest = new TurnstileProxylessRequest
{
WebsiteUrl = "https://example.com", // Replace with the URL of the page with the captcha
WebsiteKey = "0x4AAAAAAABUYP0XeMJF0xoy", // Replace with the website key for the captcha
Data = "data_here",
PageAction = "managed",
CloudflareTaskType = "token",
PageData = "pagedata_here",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" // Use the current UserAgent
};
var turnstileResult = await cmCloudClient.SolveAsync(turnstileRequest);
Console.WriteLine("Captcha Solution: " + turnstileResult.Solution.Value);
}
}
// Cloudflare Challenge (cookie cf_clearance):
using Zennolab.CapMonsterCloud.Requests;
using Zennolab.CapMonsterCloud;
class Program
{
static async Task Main(string[] args)
{
var clientOptions = new ClientOptions
{
ClientKey = "your_api_key" // Replace with your CapMonster Cloud API key
};
var cmCloudClient = CapMonsterCloudClientFactory.Create(clientOptions);
var turnstileRequest = new TurnstileRequest
{
WebsiteUrl = "https://example.com", // URL with Turnstile challenge
WebsiteKey = "0x4AAAAAAADnPIDROrmt1Wwj", // Replace with the correct website key
CloudflareTaskType = "cf_clearance",
ProxyType = ProxyType.Http, // Replace with the required type
ProxyAddress = "8.8.8.8",
ProxyPort = 8000,
ProxyLogin = "proxyLoginHere",
ProxyPassword = "proxyPasswordHere",
PageData = "pageDataHere",
Data = "pageDataHere",
HtmlPageBase64 = "htmlPageBase64Here",
UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36" // Use an up-to-date userAgent
};
var turnstileResult = await cmCloudClient.SolveAsync(turnstileRequest);
Console.WriteLine("Captcha Solved. cf_clearance cookie: " + turnstileResult.Solution.Clearance);
}
}