Puppeteer Cloudflare: Challenge, Block or Turnstile?
Puppeteer blocked by Cloudflare? Read cf-mitigated from page.goto(), find the Turnstile frame selectors miss, and submit a token that siteverify accepts.
Puppeteer Cloudflare trouble comes in three shapes: a full-page challenge ("Just a moment..."), a Turnstile widget inside the site's own form, or a hard block such as error 1020. Puppeteer is better placed than most tools to tell them apart, because page.goto() hands you the response headers and page.frames() sees the Turnstile frame that page JavaScript cannot. This guide shows both, what the headless modes leak, and how to get a token into the form so the server accepts it. If you already know you face a Turnstile widget and just want the code, our complete Puppeteer Turnstile script is the shorter read.
What we ran, and what we didn't
Everything below was measured on 26 November 2026 with Puppeteer 25.19.0 and Chrome 158 on macOS, against a local test page and Cloudflare's own Turnstile test keys. We did not run any solves against a live third-party site, and we make no claim about pass rates on real Cloudflare challenges: test keys behave the same way whatever browser you use.
- Five launch modes (
headless: true,headless: 'shell'and headed, with and without theAutomationControlledflag), checking what page JavaScript sees. - Response headers from
page.goto()on our own Cloudflare-fronted home page, plus two locally simulated responses: one carryingcf-mitigated: challenge, one plain 403. - All three Turnstile test sitekeys, how Puppeteer's selectors and frame APIs see the widget, a click on the interactive one, request interception switched on, and an injected token posted to a server that called Cloudflare's
siteverifyendpoint with the pass and fail test secrets.
Why Cloudflare stops Puppeteer
Cloudflare stops Puppeteer because stock Puppeteer tells every page it is automated. The clearest signal is navigator.webdriver, which Chrome sets to true when it is launched with --enable-automation (one of Puppeteer's default arguments), and which any script can read. The default headless mode adds a second one: its user agent says HeadlessChrome.
Our run showed which signals the usual flags remove. headless: true (the new headless mode, a full Chrome build) reported webdriver: true and HeadlessChrome/158. Adding --disable-blink-features=AutomationControlled flipped webdriver to false, but the headless user agent stayed. headless: 'shell', which runs the separate chrome-headless-shell binary, leaked the most: HeadlessChrome appeared in the user agent, in browser.version() and as a brand in navigator.userAgentData. Only headed Chrome with the flag showed neither signal.

page.goto() returned for a challenge, a block and a normal page.The Puppeteer headless modes guide describes the shell mode as the lighter option for scripts that don't need full Chrome behaviour; on Cloudflare-fronted sites that trade-off goes the wrong way. These are only the signals you can see. Cloudflare does not publish its full list, and a clean user agent from a datacenter IP at a request rate no person could produce will still be challenged.
Step 1: Tell a challenge from a block with page.goto()
Read the cf-mitigated header from the response page.goto() returns. Cloudflare documents that Challenge Page responses carry cf-mitigated: challenge, whatever the challenge type, so the header separates a challenge from a block where the status code cannot. Both come back as 403.
const res = await page.goto(url, { waitUntil: 'domcontentloaded' });
const status = res.status();
const mitigated = res.headers()['cf-mitigated']; // header names are lower-case
if (mitigated === 'challenge') {
// full-page challenge: pass it once, then keep the same browser, proxy and UA
} else if (status === 403 || status === 429) {
// a block or rate limit: no token will change this
} else if (await page.$('.cf-turnstile, [name="cf-turnstile-response"]')) {
// Turnstile inside the site's form
}
This is the one place Puppeteer is simpler than Selenium, which exposes no response object and has to dig the header out of Chrome's performance log (our Selenium version of this guide shows how). In our run the simulated challenge returned 403 with the header and the title "Just a moment...", the simulated 1020 block returned 403 without it, and our own home page returned 200 with server: cloudflare and no cf-mitigated. Matching on the page title instead breaks as soon as the page is translated or restyled.
| What page.goto() returns | What it is | What fixes it |
|---|---|---|
cf-mitigated: challenge | Full-page challenge in front of the site | Pass the challenge, then keep the clearance cookie with the same browser identity |
200, page contains .cf-turnstile | Turnstile embedded in a form | A Turnstile token submitted with the form |
| 403 without the header (1006, 1010, 1020) | A block: IP ban or firewall rule | Nothing in the browser; change what the rule matched or ask the site owner |
| 429 or error 1015 | Rate limiting | Slow down; no token helps |
If you keep landing in the third row, our guide to Cloudflare 403 and error 1020 explains what each block code means and who can lift it.
Step 2: Find the Turnstile frame Puppeteer can see
Use page.frames(), not a selector, to find the Turnstile widget. The widget's iframe sits inside a closed shadow root, so every DOM query comes back empty, but Puppeteer tracks frames through the DevTools protocol and sees it anyway.
With all three test keys, document.querySelectorAll('iframe'), page.$$('pierce/iframe') and page.$$('>>> iframe') each returned zero: Puppeteer's piercing selectors only walk open shadow roots. page.frames() listed the challenges.cloudflare.com frame 0.4 to 3.1 seconds after navigation, and frame.frameElement() returned a handle with a usable bounding box (300 by 65 pixels).
async function turnstileFrame(page, timeoutMs = 15000) {
const end = Date.now() + timeoutMs;
while (Date.now() < end) {
const f = page.frames().find((fr) => fr.url().includes('challenges.cloudflare.com'));
if (f) return f;
await new Promise((r) => setTimeout(r, 250));
}
return null;
}
const frame = await turnstileFrame(page);
const box = frame && (await (await frame.frameElement()).boundingBox());
That is as far as it goes. Inside the frame, frame.evaluate() found an empty body with no inputs, and frame.waitForSelector('input[type=checkbox]') timed out: the checkbox lives in another closed root. A mouse click at the box's coordinates did tick the force-interactive test widget, and the dummy token appeared 0.26 seconds later.

Don't read too much into the click. Test keys skip the checks a real widget runs, so a click that works on 3x00000000000000000000FF says nothing about a production sitekey. What the frame handle is good for: knowing the widget has loaded, where it is, and when to stop waiting for it.
Step 3: Read the widget's parameters
Collect the sitekey, action, cData and callback name before you ask for a token. A token issued without the widget's action or cData is rejected by the site's backend even though it looks valid.
const params = await page.evaluate(() => {
const el = document.querySelector('.cf-turnstile, [data-sitekey]');
if (!el) return null;
return {
sitekey: el.dataset.sitekey,
action: el.dataset.action || null,
cData: el.dataset.cdata || null,
callback: el.dataset.callback || null,
};
});
Widgets rendered with turnstile.render() carry no data-sitekey. Puppeteer's frame list helps here too: the sitekey is part of the challenge frame's URL path, so frame.url() from Step 2 shows it. For the action and callback, wrap turnstile.render with page.evaluateOnNewDocument before the page's scripts run; the Playwright guide covers the render hook that works and the one that breaks the widget, and the same code runs in Puppeteer.
Step 4: Request a Turnstile token
Send the sitekey, page URL, action and cData in one request, through the same proxy your Puppeteer browser uses. With CaptchaNo that is one blocking call that returns the token and the user agent it was produced with:
async function solveTurnstile({ sitekey, action, cData }, url, proxy) {
const res = await fetch('https://api.captchano.com/v1/solve?wait=60', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CAPTCHANO_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
type: 'turnstile',
url,
sitekey,
...(action && { action }),
...(cData && { cData }),
proxy,
}),
});
const data = await res.json();
if (data.status !== 'ready') throw new Error(JSON.stringify(data.error ?? data));
return data.solution; // { token, userAgent }
}
Set await page.setUserAgent(solution.userAgent) before you submit, so the browser and the token agree. Field names, error codes and the challenge-page variant are in the CaptchaNo API reference. Solve as late as you can: Cloudflare's server-side validation docs say a token is valid for 300 seconds and can be redeemed once.
Step 5: Inject the token, fire the callback, submit
Write the token into the cf-turnstile-response field, call the page's callback if it has one, then submit the way a person would. Pass the token as an argument to page.evaluate rather than building it into a code string:
await page.evaluate((token, cb) => {
let input = document.querySelector('[name="cf-turnstile-response"]');
if (!input) {
input = Object.assign(document.createElement('input'), { type: 'hidden', name: 'cf-turnstile-response' });
document.querySelector('form').appendChild(input);
}
input.value = token;
if (cb && typeof window[cb] === 'function') window[cb](token);
}, solution.token, params.callback);
await Promise.all([page.waitForNavigation(), page.click('button[type=submit]')]);
We checked this path end to end with test keys. The widget used the always-block key, so it never produced a token on its own; the script created the field, wrote a dummy token into it, fired the callback once and clicked Submit. Our server received the 21-character token and sent it to siteverify. With the always-pass test secret the answer was "success": true; with the always-fail secret it was "success": false and invalid-input-response. Same token, same browser, opposite results: the server's check decides, not anything the page shows.

When a real token comes back rejected, the usual causes are a user agent or IP that differs from the solve, a missing action or cData, or a token used twice. Our checklist of why valid tokens get rejected walks through each one.
Request interception and Turnstile
Request interception on its own did not break Turnstile in our run. With page.setRequestInterception(true) and a handler that called continue() on everything, the always-pass test widget produced its token in 2.0 seconds, against 1.9 seconds with interception off.
A second run logged every request the handler received: the page itself, two Turnstile loader scripts from challenges.cloudflare.com, the challenge frame's own document and a favicon. Nothing the challenge loaded after its document came through the handler. So the risk is in your filter, not in interception: a rule that aborts scripts or sub-documents from unknown hosts will catch the loader or the frame and the widget never renders. Allow challenges.cloudflare.com explicitly before you block anything.
Full-page challenges and the cf_clearance cookie
A full-page challenge is passed once per session, not once per form. Passing it sets a cf_clearance cookie that lets later requests through, and that cookie is tied to the browser and IP it was issued to.
In Puppeteer that means keeping the same browser context, proxy and user agent after the challenge. Don't copy the cookie into fetch or a second browser with a different fingerprint, and keep the userDataDir if you restart. Expect it to expire: when cf-mitigated: challenge comes back on a later page.goto(), treat it as a new challenge. Our Turnstile solver covers both the embedded widget and the standalone challenge page. If the challenge never clears even in a normal browser, the loop is on the network side, and our explainer on the "Verifying you are human" loop sorts out which kind you are in.
Stealth plugins and patched browsers
Stealth plugins reduce the automation signals; they do not answer a challenge that has already been served. Most pages ranking for "puppeteer cloudflare bypass" lead with puppeteer-extra-plugin-stealth or a wrapper such as puppeteer-real-browser.
Check their status before you build on them. When we looked on 27 November 2026, the npm registry listed puppeteer-extra-plugin-stealth at version 2.11.2, published 1 March 2023, with no release since; its repository is not archived but had its last push in July 2024. puppeteer-real-browser's latest npm version is 1.4.4 from September 2025, and its README now says the project will no longer receive updates. Several ranking tutorials built on them also still call page.waitForTimeout, which current Puppeteer no longer has.
A patched browser is worth trying when Cloudflare challenges you on every page load. It does nothing for a Turnstile widget the site shows to every visitor, and nothing against a 1020 rule or a banned IP. None of the ranking guides we read published a repeatable pass-rate test, so measure on your own target. A practical split: a cleaner browser and residential IP to be challenged less often, and a token for the widgets you are shown anyway.
Testing your own site? Use test keys
If the Cloudflare-protected form is yours, don't solve anything in CI. Cloudflare publishes sitekeys that always pass (1x00000000000000000000AA), always block (2x00000000000000000000AB) and force an interactive challenge (3x00000000000000000000FF), plus matching secrets for the server. In our run the always-pass key produced its dummy token in 1.9 to 3.1 seconds in headless Puppeteer with no help; the always-block key never did. Our guide to testing reCAPTCHA and Turnstile with test keys has the full list and the Google equivalents.
What does not fix Puppeteer on Cloudflare
Several common fixes do nothing or make the session less consistent:
- Only calling
page.setUserAgent(). It hidesHeadlessChromefrom the header, butnavigator.webdriverand, in shell mode, the userAgentData brands still give the browser away. - Solving on a 403 without
cf-mitigated. A block has no challenge to answer. - Waiting on
page.$('iframe')for the widget. It never appears; usepage.frames(). - Reusing a token, or solving through one IP and browsing through another.
- Automating sites you have no right to automate. Our acceptable use policy sets out where that line is.
How CaptchaNo fits a Puppeteer stack
CaptchaNo solves Turnstile, reCAPTCHA v2, v3 and checkbox Enterprise keys, DataDome, GeeTest and image captchas on our own solving infrastructure, through the request shape in Step 4. It does not solve hCaptcha, and it cannot turn a Cloudflare block into a pass.
- Billing on success only. Failed solves are never charged, and credit never expires.
- Support from the people who run it. Questions to support@captchano.com go to the engineers who operate the service.
- Node.js tooling. An official Node.js/TypeScript SDK, an MCP server for agents, and a Puppeteer integration page with copy-paste examples.
- The user agent comes back with the token, so matching the browser to the solve is one
setUserAgentcall.
Frequently Asked Questions
Can Puppeteer bypass Cloudflare on its own?
Not reliably. Cloudflare's supported-browsers reference names Puppeteer as unsupported for solving production challenges, and stock Puppeteer reports navigator.webdriver as true. Puppeteer can load pages Cloudflare serves normally and can submit a Turnstile token obtained elsewhere, but it cannot be counted on to pass interactive challenges by itself on sites that challenge it, and nothing in the browser lifts a 1020 firewall block.
Does Cloudflare detect headless Puppeteer?
The default headless modes are easy to spot. In our November 2026 run, headless: true sent HeadlessChrome in the user agent and reported navigator.webdriver as true, and headless: 'shell' also exposed HeadlessChrome as a userAgentData brand. Only headed Chrome with the AutomationControlled flag disabled showed neither. Cloudflare does not publish its full signal list, so these are examples, not the whole picture.
How do I know if Cloudflare challenged or blocked my Puppeteer request?
Check the response that page.goto() returns. A challenge carries the cf-mitigated header set to challenge, which Cloudflare documents for every Challenge Page type. A 403 without that header is a block, such as error 1020 or an IP ban, and no captcha token will fix it. A 429 or error 1015 means you are being rate limited and need to slow down.
Why can't Puppeteer find the Turnstile iframe?
The iframe is attached inside a closed shadow root, so querySelector and Puppeteer's pierce and deep selectors all return nothing; they only walk open shadow roots. Puppeteer still tracks the frame through the DevTools protocol, so look for a frame whose URL contains challenges.cloudflare.com in page.frames(). Its frameElement() gives you the widget's position, though the checkbox itself stays out of reach.
How long is a Cloudflare Turnstile token valid?
Cloudflare's server-side validation documentation says a Turnstile token is valid for 300 seconds and can be redeemed only once. After that the site's siteverify call fails with timeout-or-duplicate. Request the token immediately before you submit the form, not at the start of a long Puppeteer script, and never send the same token twice.
Add Turnstile solving to your Puppeteer scripts
Read cf-mitigated first, solve only when there is a challenge or a widget, and keep one browser identity from solve to submit. Create a CaptchaNo account to get an API key, drop the Step 4 function into your script, and pay only for solves that succeed.