Crawlee Captcha Handling: reCAPTCHA and Turnstile
Crawlee does not flag reCAPTCHA or Turnstile widgets. Our Crawlee 4.0 tests show what it detects, how retries re-buy tokens, and the code to fix both.
Crawlee captcha handling starts with something most guides leave out. Crawlee does not notice a reCAPTCHA or Turnstile widget on a page. In our runs on Crawlee 4.0.0, a form behind either widget loaded with status 200, and the requestHandler ran as if the page were fine. Crawlee does react to blocked status codes and to a few challenge interstitials, by retiring the session and retrying. A widget is different: you detect it yourself, get a token, inject it, and stop retries from re-buying tokens. This guide covers each step, with our test results. If you already use plain Playwright, the same pieces are in our Playwright integration guide.
What we ran, and what we didn't
Everything below comes from runs on 2026-12-03 (UTC). We used Crawlee 4.0.0, released on npm the same day, and Crawlee 3.16.0 for comparison, with Playwright 1.65.2, headless Chromium and Node.js 26.
- A local test server with four pages: a form with a reCAPTCHA v2 widget (Google's test sitekey), a form with a Turnstile widget (Cloudflare's test sitekey), a plain 403, and a 403 page carrying Cloudflare's challenge iframe markup.
- A
PlaywrightCrawlervisit to Google's public reCAPTCHA demo, to check detection on a real page. - A full detect, inject, callback and submit flow. The server verified tokens with Cloudflare's published test secrets.
We ran no live solves. There was no test API key for this run, so the solver in our tests is a stub that returns Cloudflare's placeholder token and counts its calls. The Crawlee behaviour, the retry counts and the siteverify answers are real. The solver code is the same request shape our other tutorials use.
What Crawlee detects on its own
Crawlee checks the HTTP status and a short list of CSS selectors. A widget embedded in a normal page passes both checks. By default, a response with status 401, 403 or 429 throws a session error. Crawlee then retires that session and retries the request with a new one. With retryOnBlocked: true, Crawlee 4 also looks for specific markup: Cloudflare's challenge iframe inside #turnstile-wrapper, AWS WAF challenge containers, Google's "sorry" page and Imperva's iframe. If it finds a Cloudflare challenge on a 403, it waits 5 seconds to see whether the challenge clears on its own. We read these rules in the 4.0.0 source and then confirmed them with the test pages.

Three results matter for planning:
- Widgets are invisible to Crawlee. Both forms returned 200 and reached
requestHandlerin every configuration we tried, includingretryOnBlocked. - Blocked retries count as ordinary retries in Crawlee 4. With
maxRequestRetries: 3, the plain 403 got 4 attempts on 4 different sessions and then went tofailedRequestHandler. On 3.16.0 withretryOnBlocked, the same page got 11 attempts on 11 sessions. - Waiting costs time. With
retryOnBlocked, the run took 21.6 s on Crawlee 4.0.0 and 58.3 s on 3.16.0, compared with 3.0 s and 1.9 s without it. Most of that is the 5-second wait before each Cloudflare retry.
The defaults (blockedStatusCodes of 401, 403 and 429, session retirement and the reuse strategies) are described in Crawlee's session management guide.
A blocked page and a captcha page need different fixes
A fresh session can fix a blocked page. Only a valid token fixes a captcha widget. Retiring the session works when the block is about your IP, cookies or fingerprint, because the next attempt arrives looking different. A reCAPTCHA or Turnstile widget on a login or search form will usually appear again on the next attempt, so retrying only repeats the visit. A 403 or Cloudflare error 1020 is a firewall decision, and a solver cannot help with it. We explain how to tell them apart in our Cloudflare 403 and 1020 guide. The rule of thumb for Crawlee:
| What the page shows | What Crawlee does by default | What to do |
|---|---|---|
| 401, 403 or 429 with no widget | Retires the session and retries | Better proxies, slower pace, fewer requests per session |
| Cloudflare "Just a moment" challenge (403) | Retires and retries; waits 5 s first with retryOnBlocked | Try handleCloudflareChallengeHook, then a Turnstile solve for the challenge page |
| reCAPTCHA v2 or v3 on a 200 page | Nothing | Detect, solve, inject, then submit |
| Turnstile widget on a 200 page | Nothing | Detect, solve, inject, fire the callback, then submit |
Step 1: Detect the widget in the request handler
Look for the widget's markup and sitekey before you scrape or submit anything. Because Crawlee runs requestHandler on every 200 page, the check belongs there, or in a postNavigationHooks function if several routes share it:
async function detectCaptcha(page) {
return page.evaluate(() => {
const ts = document.querySelector('.cf-turnstile[data-sitekey]');
if (ts) return { type: 'turnstile', sitekey: ts.dataset.sitekey,
action: ts.dataset.action, cdata: ts.dataset.cdata, callback: ts.dataset.callback };
const rc = document.querySelector('.g-recaptcha[data-sitekey]');
if (rc) return { type: 'recaptcha_v2', sitekey: rc.dataset.sitekey, callback: rc.dataset.callback };
const anchor = document.querySelector('iframe[src*="/recaptcha/api2/anchor"]');
if (anchor) return { type: 'recaptcha_v2', sitekey: new URL(anchor.src).searchParams.get('k') };
return null;
});
}
On Google's demo, our PlaywrightCrawler got status 200 with no retry. It found one widget with sitekey 6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ- and callback onSuccess, the same key in the anchor iframe, and one g-recaptcha-response textarea. Explicitly rendered widgets have no data-sitekey; for those, read the key from the anchor iframe as above. We cover the other places a key can hide in our sitekey guide. reCAPTCHA v3 has no widget at all. You need the action name the page passes to execute, and our Playwright reCAPTCHA tutorial shows an init script that captures it.
Step 2: Request a token with the crawler's user agent
Send the page URL and sitekey to the solving API. Also send the user agent that the Crawlee page reports, not one you typed in. Crawlee injects browser fingerprints by default. On our macOS machine, the Chromium page reported a Windows Chrome 156 user agent, so a hard-coded string would not have matched it.
async function solve(task) {
const headers = { Authorization: `Bearer ${process.env.CAPTCHANO_API_KEY}`,
'Content-Type': 'application/json' };
let res = await fetch('https://api.captchano.com/v1/solve?wait=60',
{ method: 'POST', headers, body: JSON.stringify(task) });
let out = await res.json();
while (res.status === 202 || out.status === 'solving' || out.status === 'queued') {
await new Promise((r) => setTimeout(r, 5000));
res = await fetch(`https://api.captchano.com/v1/task/${out.id}`, { headers });
out = await res.json();
}
if (out.status !== 'ready') throw new Error(`not solved: ${out.error?.code ?? res.status}`);
return out.solution.token;
}
// inside requestHandler
const found = await detectCaptcha(page);
const userAgent = await page.evaluate(() => navigator.userAgent);
const token = found && await solve({ type: found.type, url: request.url,
sitekey: found.sitekey, action: found.action, cData: found.cdata, userAgent });
If the site checks that the solve and the submit come from the same network, add the proxy your crawler uses for that session. The request fields are listed in the API docs and on the Turnstile solver page. The reCAPTCHA fields, including the invisible flag, are on the reCAPTCHA v2 solver page.
Step 3: Inject the token, fire the callback, submit
Write the token into the hidden response field, call the widget's callback, and then submit. On our Turnstile form, the Send button stayed disabled until the callback ran, which is a common pattern. After the callback it was enabled, and the server received both email and cf-turnstile-response.
await page.evaluate(({ t, cb }) => {
document.querySelectorAll('[name="cf-turnstile-response"], [name="g-recaptcha-response"]')
.forEach((el) => { el.value = t; });
if (cb && typeof window[cb] === 'function') window[cb](t);
}, { t: token, cb: found.callback });
await page.click('#send');
Do this straight after the solve. Google's verify documentation says a reCAPTCHA token can be used once and expires after two minutes. Cloudflare's server-side validation docs give a Turnstile token 300 seconds. Neither token survives a trip back through the request queue, so never store one in userData for a retry. When a site rejects a token you injected correctly, the cause is usually a mismatched session, IP or action, not the solve. We go through those causes in why valid tokens get rejected.
Step 4: Give every request a solve budget
Each retry runs your handler again, and that includes the solve. In our run, the form whose token always failed verification produced 4 solver calls from one URL: the first attempt plus 3 retries. A counter in request.userData stopped it at 2:
request.userData.solves = (request.userData.solves ?? 0) + 1;
if (request.userData.solves > 2) {
request.noRetry = true; // stop the queue from trying again
throw new Error('solve budget spent');
}

Two more habits help. First, run cheap checks such as the URL, login state and selectors before the solve, so a handler that fails for an unrelated reason doesn't pay for a token first. Second, log the siteverify-style error your target returns, if it returns one. A timeout-or-duplicate means the token arrived too late or was used twice. An invalid-input-response on every attempt means something about the setup is wrong, and spending more will not fix it.
Cloudflare challenge pages in Crawlee
For the full-page "Just a moment" challenge, try Crawlee's own helper first. handleCloudflareChallengeHook from @crawlee/playwright goes in postNavigationHooks. It detects the challenge, clicks the checkbox, waits and reloads. According to the 4.0.0 type definitions, a passed challenge replaces the 403 response before the blocked-status check runs, so you don't need to remove 403 from blockedStatusCodes. Crawlee's documentation says the hook may not always pass and works best with Camoufox. When it fails, the request is retried on a new session. That's the point where a Turnstile solve for the challenge page, with the page data from that same session, can be the next step. Our Playwright Cloudflare guide walks through that variant.
Test the flow before you point it at a real site
Build the flow against test keys first. Cloudflare publishes sitekeys that always pass, always fail or force an interactive challenge, plus secrets that always pass or always fail. Their test sitekeys issue the placeholder token XXXX.DUMMY.TOKEN.XXXX. Google publishes a reCAPTCHA v2 test key pair too. That setup gave us both siteverify results above without spending anything. Our test keys guide lists every pair.
How CaptchaNo fits into a Crawlee crawler
CaptchaNo solves reCAPTCHA v2 (checkbox and invisible), reCAPTCHA v3 and Cloudflare Turnstile, along with the other types on the pricing page, on our own solving infrastructure. A request returns a token in one blocking call with ?wait=60, plus the user agent used for Turnstile. Failed solves are never billed, and credit never expires, which suits crawls that run in bursts. Every token that comes back is a paid solve, though, so the budget in Step 4 is how you stop retries from re-buying tokens. If you get stuck, replies to support@captchano.com come from the engineers who run the service. CaptchaNo publishes this blog, so weigh our product notes with that in mind. The Crawlee findings above don't depend on which solver you use.
Frequently Asked Questions
Does Crawlee solve captchas on its own?
No. Crawlee reduces how often captchas appear by injecting browser fingerprints and rotating sessions, and it can try to pass Cloudflare's challenge page with its click-based helper. It has no built-in solver for reCAPTCHA or Turnstile widgets. In our Crawlee 4.0.0 runs, pages with either widget returned 200 and reached the request handler without being flagged, so detection has to be your own code.
Does retryOnBlocked handle reCAPTCHA in Crawlee?
No. The option looks for Cloudflare's challenge iframe, AWS WAF containers, Google's rate-limit page and Imperva's iframe, and it retries those on a new session. A reCAPTCHA widget inside a normal page does not match any of them. In our test, the reCAPTCHA form was handled as a normal page with and without the option, on both Crawlee 4.0.0 and 3.16.0.
Why does my Crawlee crawler retry the same blocked URL several times?
A blocked status code throws a session error, and Crawlee answers it by retiring the session and putting the request back in the queue. In Crawlee 4.0.0 those retries count against maxRequestRetries, so the default of 3 gives four attempts in total. On 3.16.0 with retryOnBlocked enabled, our blocked page was attempted eleven times before it failed.
Can I reuse a captcha token across Crawlee retries?
No. Google says a reCAPTCHA token is single-use and expires after two minutes, and Cloudflare gives a Turnstile token 300 seconds and rejects a second use with timeout-or-duplicate. A request that waits in the queue for a retry will usually outlive the token. Solve again on each attempt, and cap attempts with a per-request budget so a page that keeps rejecting tokens stops early.
Which user agent should I send with the solve request?
Send the one the Crawlee page reports through navigator.userAgent at solve time. Crawlee injects fingerprints by default, so the browser can report a different operating system and version from the machine it runs on. Our macOS run reported a Windows Chrome 156 user agent. Matching it matters most for Turnstile, which ties tokens to the browser that earned them.
Add captcha solving to your Crawlee project
Copy the detection helper, wire the solve into your request handler, and set a solve budget before your first real crawl. Create a CaptchaNo account to get an API key, and test against your own pages with the free trial first.