Skip to content
Guide

DrissionPage Not Passing Cloudflare in 2026: Turnstile, cf_clearance and Headless Fixes

NSLSolver TeamPublished Updated 9 min read

DrissionPage usually fails on Cloudflare for four reasons: it runs headless (Chrome announces HeadlessChrome), the Turnstile checkbox sits in a closed shadow root and a cross-origin iframe that ordinary locators cannot reach, the IP has a poor reputation, or the cf_clearance cookie is reused with a different User-Agent or IP. Run headed, reach the checkbox with .sr and a ChromiumFrame, wait for cf_clearance before acting, and replay it from the same IP and UA. If the challenge still loops, get a Turnstile token or a clearance cookie from a solver API.

DrissionPage (g1879/DrissionPage) is a Python library that launches Chrome itself and drives it over the DevTools Protocol through a debugging port, with no chromedriver involved. That removes the classic WebDriver tells, which is why it is so popular for scraping, especially among Chinese developers. It does not make the browser invisible to Cloudflare, and the way it finds elements has blind spots exactly where Turnstile hides. This guide uses the stable 4.1 API (4.1.1.4 on PyPI; 5.0 is still in beta).

Quick answer: match your DrissionPage problem to the fix

DrissionPage prints its errors in Chinese or English depending on your settings; both mean the same thing. Find your message or symptom below.

Browser connect failed, check whether the port 9222 is a browser and "--remote-debugging-port=9222" startup item is added.
Port 9222 is taken by something that is not a debuggable browser. DrissionPage connects to 127.0.0.1:9222 by default. Call co.auto_port() for a fresh browser on a free port, or set_local_port() to another one.
The browser executable file path cannot be found. Please configure it manually.
No Chrome or Chromium found. Install Chrome or point co.set_browser_path() at the executable. On Linux servers also add co.set_argument("--no-sandbox") when running as root.
Stuck on "Just a moment..." / the challenge page never clears
Cloudflare did not accept the session. Run headed, wait for cf_clearance before acting, and test from a cleaner IP. Headless mode and datacenter IPs are the usual causes.
tab.ele("tag:iframe") finds nothing / ElementNotFoundError on the Turnstile checkbox
The widget lives in a closed shadow root and a cross-origin iframe. Locate the shadow host, use .sr to enter the shadow root, then .ele("tag:iframe") to get a ChromiumFrame. A page-level search cannot see inside either.
Checkbox clicked, then "Verify you are human" again (loop)
The click landed but the score is too low. Change one thing at a time: headed instead of headless, a residential IP, a slower flow with waits. If it keeps looping, get a token from a solver API.
Works normally, blocked as soon as co.headless() is on
Headless Chrome identifies itself. co.headless() starts Chrome with --headless=new, and DrissionPage does not rewrite the HeadlessChrome user agent. Run headed (Xvfb on servers).
You seem to be setting up a proxy that uses the account password, which is not supported...
set_proxy() cannot authenticate. Per the docs, set_proxy() is fixed at launch and does not support accounts (SOCKS also prints a warning). Use an IP-whitelisted proxy, a local forwarder, or an extension.
cf_clearance obtained, but requests or SessionPage still gets 403
The cookie was replayed out of context. Send the same User-Agent (tab.user_agent) from the same exit IP. A Python HTTP client also has a different TLS fingerprint from Chrome.

Why DrissionPage gets blocked by Cloudflare

A real browser runs Cloudflare's challenge script, so the question is never whether JavaScript executes. It is how the session is scored and whether your code can reach the widget at all.

  • Headless mode. co.headless() adds --headless=new. DrissionPage contains no code that rewrites the user agent, so Chrome's own HeadlessChrome token is sent. Other headless traits remain too, such as the 800x600 virtual screen that the zendriver project documents as a common headless tell.
  • Closed shadow root plus cross-origin iframe. Turnstile renders its iframe (from challenges.cloudflare.com) inside a closed shadow root. DrissionPage's docs say shadow roots cannot be searched across levels, and that a cross-origin iframe must first be obtained as a ChromiumFrame object; tab.ele() on the page sees neither.
  • IP reputation. Datacenter IPs and overused proxy pools keep looping on the challenge no matter how clean the browser is.
  • Proxy limits. set_proxy() is fixed when the browser starts and, per the docs, does not support proxies with a username and password, which pushes people towards whatever unauthenticated proxy they can find.
  • Taking over the wrong browser. With default options DrissionPage connects to 127.0.0.1:9222, and if a browser is already listening there it takes it over, including its profile and history, which makes results inconsistent between runs.

Fix 1: launch errors and ChromiumOptions that help

Start every Cloudflare run from an explicit ChromiumOptions object. auto_port() picks a free port and a fresh user folder, so you never attach to your everyday Chrome; the docs note it supports multithreading but not multiprocessing. Add --no-sandbox for Linux or Docker as root, set_browser_path() if Chrome is not found, and leave headless off. On a server without a desktop, run the headed browser inside Xvfb (for example with xvfb-run).

Then let the challenge finish on its own. In a headed browser the non-interactive check often clears within a few seconds, and polling tab.cookies().as_dict() for cf_clearance tells you when it has. Do not click, scroll or navigate during that window.

launch_drissionpage.py
from DrissionPage import Chromium, ChromiumOptions

co = ChromiumOptions()
co.auto_port()                      # fresh browser on a free port, never your daily Chrome on 9222
co.set_argument("--no-sandbox")     # Linux / Docker as root
# co.set_browser_path("/usr/bin/google-chrome")  # if the executable is not found
co.set_proxy("http://1.2.3.4:8080")  # no user:pass here, see the proxy section
# co.headless()                     # avoid on Cloudflare: Chrome then reports HeadlessChrome

browser = Chromium(co)
tab = browser.latest_tab
tab.get("https://example.com/")

# Wait for the challenge to clear on its own before touching anything
for _ in range(30):
    if "cf_clearance" in tab.cookies().as_dict():
        break
    tab.wait(1)

print(tab.title, tab.user_agent)

Fix 2: reaching the Turnstile checkbox inside the shadow root

This is the problem most DrissionPage users hit. You can see the checkbox, but tab.ele("tag:iframe") and every XPath return nothing. The chain that works follows DrissionPage's own rules: find the shadow host element, use its .sr property (short for shadow_root) to get a ShadowRoot object, search that for tag:iframe to get a ChromiumFrame, and act on it. DrissionPage reads shadow roots through the DevTools Protocol (DOM.describeNode), so .sr also works on Turnstile's closed root, which page JavaScript cannot open.

Clicking by position is more robust than reaching into the iframe's own markup, which Cloudflare changes without notice. The zendriver project's verify_cf() does the same: it clicks 15% into the iframe's width at its vertical centre. Find the host once in DevTools (it is the element showing #shadow-root (closed)) and replace the placeholder selector.

turnstile_shadow_root.py
# Placeholder: the element that DevTools shows with "#shadow-root (closed)" under it.
HOST = "css:#turnstile-container > div"


def click_turnstile(tab, host=HOST):
    """Click the Turnstile checkbox by position, through the shadow root and cross-origin iframe."""
    frame = tab.ele(host, timeout=15).sr.ele("tag:iframe", timeout=10)  # a ChromiumFrame
    box = frame.frame_ele                     # the <iframe> element itself
    w, h = box.rect.size
    box.click.at(int(w * 0.15), int(h / 2))   # checkbox: left side, vertically centred


def wait_for_token(tab, timeout=20):
    """Return the cf-turnstile-response value once the widget has produced one."""
    for _ in range(timeout):
        token = tab.run_js(
            "const el = document.querySelector('[name=cf-turnstile-response]');"
            "return el ? el.value : '';"
        )
        if token:
            return token
        tab.wait(1)
    return ""

Fix 3: cf_clearance missing or rejected

If cf_clearance never appears in tab.cookies().as_dict(), the challenge did not pass: go back to headless and IP. If it appears but your requests code or DrissionPage's SessionPage still gets a 403 or a fresh challenge, the replay is wrong.

  • User-Agent: read tab.user_agent from the tab that passed and send exactly that string.
  • IP: send the follow-up requests through the same exit IP as the browser.
  • TLS: requests does not have Chrome's TLS fingerprint. Making the follow-up requests in the same tab avoids that mismatch.
  • Lifetime: the cookie expires according to the site's Challenge Passage setting, so refresh it instead of hard-coding it. Our cf_clearance guide covers the details.

When to switch to a managed solver

DrissionPage is a good fit when you need a real browser, want to reuse a logged-in profile, or scrape a handful of pages headed. It gets expensive when Cloudflare only lets you through on residential IPs with a visible browser, when each Turnstile markup change breaks your click helper, or when you are running many browsers just to collect tokens or cookies.

Then replace only that step: a solver returns a valid Turnstile token or a cf_clearance cookie over HTTP, and DrissionPage keeps doing navigation and data extraction. Only automate sites you own or are explicitly authorised to access, and respect their terms and rate limits.

NSLSolver example: a Turnstile token inside DrissionPage

Read the widget's data-sitekey, POST it with the page url to NSLSolver as type turnstile, and write the returned token into cf-turnstile-response with tab.run_js() before submitting. Tokens come back in about 250 ms on average and cost $0.80 per 1,000; only successful solves are billed, and sign-ups with Google, Gmail or Proton get free credit with no card. Submit within 300 seconds and only once. If the widget sets data-action or data-cdata, pass them as action and cdata; if the site reads the token from a callback, call it with the token.

For a full-page "Just a moment..." challenge, use type challenge with url, site_key and proxy instead: it returns cookies including cf_clearance and the user_agent to replay through the same proxy ($1.00 per 1,000, about 3.3 s). The clearance is issued for an iPhone Safari User-Agent, so replay it from an HTTP client with that UA. NSLSolver does not solve reCAPTCHA v2, hCaptcha, GeeTest or image CAPTCHAs.

drissionpage_nslsolver.py
import requests
from DrissionPage import Chromium

API_KEY = "nsl_YOUR_API_KEY"
URL = "https://target-site.com/login"

tab = Chromium().latest_tab
tab.get(URL)
site_key = tab.ele("css:.cf-turnstile").attr("data-sitekey")

# 1) Ask NSLSolver for a fresh Turnstile token (no checkbox click needed)
resp = requests.post(
    "https://api.nslsolver.com/solve",
    headers={"X-API-Key": API_KEY},
    json={"type": "turnstile", "site_key": site_key, "url": URL},
    timeout=120,
)
resp.raise_for_status()
token = resp.json()["token"]

# 2) Write it into the hidden field and submit (single use, within 300 seconds)
tab.run_js(
    "document.querySelectorAll('[name=cf-turnstile-response]')"
    ".forEach(el => el.value = arguments[0]);",
    token,
)
tab.ele("css:button[type=submit]").click()

Full /solve API reference

Related: the Cloudflare Turnstile solver API for integration details, pay-per-success pricing, undetected-chromedriver not working for the Selenium-based route, the cf_clearance cookie guide for replay rules, and solving Turnstile in Python for a requests-only flow.

Frequently asked questions

Why can't DrissionPage get past Cloudflare?

DrissionPage runs a real Chrome, so the challenge script executes, but Cloudflare still scores headless mode, the IP and behaviour. Most failures come from co.headless(), a datacenter IP, a Turnstile checkbox the code cannot reach inside its shadow root, or a cf_clearance cookie replayed with another User-Agent or IP.

How do I click the Turnstile checkbox in DrissionPage?

Find the shadow host element, use .sr to get its ShadowRoot, then .ele("tag:iframe") to get the cross-origin frame as a ChromiumFrame. Click the iframe element (frame.frame_ele) by position, near its left side and vertical centre. A page-level ele() or XPath cannot see inside the shadow root.

Does DrissionPage work headless on Cloudflare?

Rarely. co.headless() starts Chrome with --headless=new and DrissionPage does not hide the HeadlessChrome user agent, so it is easy to flag. Run headed, and on a Linux server give the browser a virtual display with Xvfb.

How do I get cf_clearance from DrissionPage?

Wait until tab.cookies().as_dict() contains cf_clearance, then read tab.user_agent. Reuse both together from the same exit IP; a different UA or IP gets challenged again.

Why does set_proxy() not accept user:pass?

DrissionPage's documentation says set_proxy() is set once at launch and does not support proxies with an account; it prints a warning for authenticated and SOCKS proxies. Use an IP-whitelisted proxy, a local forwarding proxy, or a browser extension.

What does "Browser connect failed, check whether the port 9222 is a browser" mean?

DrissionPage tried its default address 127.0.0.1:9222 and found the port in use by something that is not a debuggable browser. Use co.auto_port() to launch a fresh browser on a free port, or choose another port with set_local_port().

Can NSLSolver replace the Turnstile click in DrissionPage?

Yes. POST the widget's site_key and the page url to /solve with type turnstile, then write the token into cf-turnstile-response with tab.run_js() and submit within 300 seconds. For a full-page challenge, type challenge returns cf_clearance and the matching user_agent.

Stop hunting the checkbox in shadow roots

Get a valid Turnstile token in about 250 ms and keep the rest of your DrissionPage script. Free credit with Google, Gmail or Proton sign-up, no card, pay only for successful solves.