Skip to content
Programmatic guide

Cloudflare Turnstile solver for Playwright Python

Cloudflare Turnstile blocks most headless traffic by default. Use a Sonic-issued token from Playwright Python — pages submit cleanly without triggering the WAF managed-challenge fallback.

Python · Playwright

Runnable example

from playwright.async_api import async_playwright
from captchasonic import CaptchaSonic

async with async_playwright() as p:
    browser = await p.chromium.launch()
    page = await browser.new_page()
    await page.goto('https://target.example.com/login')

    sonic = CaptchaSonic('YOUR_API_KEY')
    result = sonic.solve(
        type='TurnstileTaskProxyless',
        website_url=page.url,
        website_key='0x4AAAAAAA...',
    )

    await page.evaluate(
        "(t) => document.querySelector('[name=cf-turnstile-response]').value = t",
        result.token,
    )
    await page.click('form button[type=submit]')

Replace YOUR_API_KEY with a real key from your dashboard. The token is good for one form submission.

FAQ

Does Turnstile detect Playwright by default?
Cloudflare Turnstile scores based on TLS fingerprint, JS-execution timing, and a handful of browser entropy signals. A bare Playwright session triggers the managed-challenge fallback on protected paths; the Sonic token sidesteps the scoring step.
Where does the cf-turnstile-response field live?
Turnstile injects a hidden input with name="cf-turnstile-response" into the form. If you embed Turnstile via the JS render API instead of declarative HTML, you set the value via the callback parameter on render().
What if the site uses the WAF challenge page (not Turnstile widget)?
The same token type covers both — TurnstileTaskProxyless handles the standard widget, the WAF managed challenge page, and the silent JS-only challenge. Pass the action URL and we route to the right solver internally.

How CaptchaSonic compares for this captcha

Feature-by-feature against the four most-mentioned alternatives. Independently benchmarked; numbers refresh quarterly.

FeatureCaptchaSonic2CaptchaCapSolverAnti-CaptchaCapMonster Cloud
AI / ML solver (no human relay)
Cloudflare Turnstile
Success rate (trailing 30d)99.9%~95%~98%~95%~97%
Price per 1k — Turnstile$0.50$1.99$0.80$1.50$0.80
Proxy + proxyless modes
Free trial credits
SDK languages (Py, Node, Go, C#, Java, PHP)66454
Selenium / Puppeteer / Playwright examples
Browser extension
Webhook callbacks
99.9% uptime SLA

Yes / No / Partial reflect publicly documented support. Pricing and solve-time figures snapshot the published rate at the time this page was last updated.

Related guides