Solving Cloudflare Turnstile with Playwright

Solving Cloudflare Turnstile with Playwright

Posted on 2026-09-18 | 2 min read | Category: Playwright | By DeathByCaptcha Engineering Team

Playwright


Cloudflare Turnstile replaced the traditional CAPTCHA checkbox with an invisible challenge. It runs JavaScript fingerprints and browser attestation in the background. When automation is detected, Turnstile blocks the request. DeathByCaptcha solves Turnstile challenges automatically.

How Turnstile Works

  1. Cloudflare loads a Turnstile widget on the page.
  2. The widget collects browser fingerprints (canvas, WebGL, fonts).
  3. It generates a cf-turnstile-response token.
  4. If the token is valid, the form submits. If not, a challenge appears.

Detecting Turnstile in Playwright

# Check for Turnstile widget
turnstile_frame = page.query_selector("iframe[src*=challenges.cloudflare.com]")
if turnstile_frame:
    print("Turnstile detected")

Solving with DeathByCaptcha

Turnstile uses type=6 in the DeathByCaptcha API:

import json
from playwright.sync_api import sync_playwright
import deathbycaptcha

client = deathbycaptcha.SocketClient(username, password)

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto("https://example.com/login")

    sitekey = page.get_attribute("[name=cf-turnstile-response]", "data-sitekey")

    result = client.decode(type=6, token_params=json.dumps({
        "sitekey": sitekey,
        "pageurl": "https://example.com/login"
    }))
    print("Solution:", result["text"])

    page.evaluate("document.querySelector('[name=cf-turnstile-response]').value='%s'" % result["text"])
    page.click("button[type=submit]")

    browser.close()

Key Differences from reCAPTCHA

  • Type parameter: Use type=6 for Turnstile, not type=4 (reCAPTCHA v2).
  • Token field: Look for cf-turnstile-response instead of g-recaptcha-response.
  • Widget detection: Turnstile uses an iframe from challenges.cloudflare.com.
  • Invisible by default: Turnstile is always invisible. No checkbox to click.

Troubleshooting

  • Token expired: Turnstile tokens expire in 300 seconds. Solve and inject immediately.
  • Detection: Some Turnstile implementations check for headless browsers. Use headed mode if blocked.
  • Enterprise: Cloudflare Enterprise Turnstile may require additional attestation tokens.

For API documentation, see the API reference and client libraries.

Common pitfalls

  • Using a CAPTCHA solving service for illegitimate purposes instead of legitimate automation and testing.
  • Hard-coding credentials or API keys in client-side code that users can inspect.
  • Sending the wrong CAPTCHA type parameter, which returns incorrect or empty responses.
  • Failing to poll for the solution status and not handling timeouts gracefully.
  • Scaling automation without monitoring error rates, response times, and CAPTCHA type coverage.
DBC
Written by DeathByCaptcha Engineering Team
DeathByCaptcha engineers build and operate the CAPTCHA solving technology behind this site. Articles are written by our technical team and checked for accuracy before publishing.
Reviewed by DeathByCaptcha Editorial Team

Get your API key — start solving

Free to try · No credit card · Python, Node.js, Java, C# SDKs

Get your API key


Status: OK

Servers are fully operational with faster than average response time.
  • Average solving time
  • 4 seconds - Normal CAPTCHAs (1 min. ago)
  • 17 seconds - reCAPTCHA V2, V3 (1 min. ago)
  • 7 seconds - others (1 min. ago)
Chrome and Firefox logos
Browser extensions available

Updates

  1. May 13: Crypto payments got better! You can now purchase your CAPTCHAs using cryptocurrency through the Hekelet payment processor at https://deathbycaptcha.com/user-pay and receive an extra 20% FREE CAPTCHA credit with every package purchased this way.
  2. Apr 15: GitHub Updates: We’ve upgraded our libraries, expanded sample code, enhanced documentation, and added support for C++ and Go, making integration smoother than ever. Explore what’s new at github.com/deathbycaptcha!
  3. Jan 27: RESOLVED - If your email to one of our official addresses ([email protected], [email protected], or [email protected]) has bounced or you haven’t received a response, please try resending it or reach out via our Live Chat Support at https://deathbycaptcha.com/es/contact.

  4. Previous updates…

Support

Our system is designed to be completely user-friendly and easy-to-use. Should you have any trouble with it, simply email us at DBC technical support emailcom, and a support agent will get back to you as soon as possible.

Live Support

Available Monday to Friday (10am to 4pm EST) Live support image. Link to live support page