Patchright usually stops working for one of four reasons: the browser it needs is not installed for your exact version, you run it headless, your launch options add fingerprints it was designed to avoid (a custom user agent, extra headers, extensions), or Cloudflare scores your environment and IP rather than the automation protocol. Fix the install, use the README's best-practice launch (real Chrome, headed, persistent context, nothing injected), upgrade past known regressions and test from a clean IP. If a widget still loops, inject a Turnstile token from a solver API.
Patchright (Kaliiiiiiiiii-Vinyzu/patchright, Apache-2.0, about 5,300 stars) is a patched drop-in replacement for Playwright that removes protocol-level leaks playwright-stealth cannot touch; our [playwright-stealth guide](/blog/playwright-stealth-not-working) covers that library. This guide goes deeper: patchright's exact errors, the GitHub issues behind them, and what its maintainers call out of scope.
Quick answer: match your patchright error to the fix
Most patchright problems are one of these messages or symptoms. Find yours, then read the matching section below for code.
- Executable doesn't exist at … Looks like Playwright was just installed or updated.
- The browser build this patchright version expects is not installed. Run patchright install chromium (or npx patchright install chromium) after every upgrade. The Node message suggests npx playwright install, which is Playwright's CLI, not patchright's.
- Chromium distribution 'chrome' is not found at …
- You passed channel="chrome" but Google Chrome is not installed. Run patchright install chrome. On Linux arm64 that script prints "ERROR: not supported on Linux Arm64" (open issue patchright-python #121), so drop channel there and use the bundled Chromium.
- Passes headed, blocked or looping with headless=True
- Headless Chrome is detectable, and patchright does not hide it. Maintainers say headless cannot be undetected without a custom Chromium, and the user agent still says HeadlessChrome (#82, #227). Run headed, with Xvfb on servers.
- Turnstile keeps looping on "Verifying..." after the click
- Something in your setup contradicts the real browser. Remove custom user_agent, headers and extensions; in issue #73 a hardcoded Chrome 134 user agent caused the loop. Use the best-practice launch and a cleaner IP.
- Works on my machine, fails in Docker or GitHub Actions
- Environment and network fingerprinting, which patchright does not cover. Issue #224 was closed as a duplicate of #37, where a maintainer wrote that fingerprinting "is currently not covered by patchright". Test from a desktop and a residential IP first.
- frame.locator().click() on the Turnstile checkbox does nothing
- A known regression in 1.60.0 to 1.61.1 (issue #203). The maintainer's answer was to upgrade to 1.61.2 or later. Today that means 1.64.4 on PyPI or 1.64.3 on npm.
- page.evaluate returns undefined for page globals / console events never fire
- Both are by design. evaluate runs in an isolated world by default: pass isolated_context=False (isolatedContext: false in Node) to read window variables. The Console API is disabled to close the Console.enable leak.
- ERR_TUNNEL_CONNECTION_FAILED, or load never fires behind a proxy
- Proxy plus init-script or authenticated-proxy bugs, already fixed. Issue #166 (1.57.0, proxy plus add_init_script) and #259 (1.64.1, authenticated proxy, closed 2026-11-02) are fixed. Upgrade and reinstall the browsers.
Error strings are quoted from the patchright-core 1.64.3 package and the issues cited; behaviour from the patchright READMEs, all checked on 2026-12-01.
How patchright works, and what it does not patch
Patchright is three repositories: the patcher that rewrites Playwright's driver (patchright), and the Python (patchright-python, about 1,600 stars) and Node.js (patchright-nodejs, about 800 stars) packages, all Apache-2.0. You change the import (from patchright.sync_api import sync_playwright, or require('patchright')) and keep the rest of your Playwright code. It patches Chromium-based browsers only; Firefox and WebKit are not supported.
Its README lists the patches: it avoids Runtime.enable by running JavaScript in isolated execution contexts, disables the Console API to close the Console.enable leak, changes default flags (adds --disable-blink-features=AutomationControlled, removes --enable-automation, --disable-extensions and others), and lets normal locators reach into closed shadow roots. Init scripts are injected through Playwright routes, which the README admits timing attacks could detect.
What it does not do matters as much. In issue #37 a maintainer wrote that "patchright currently does not intend to cover fingerprinting", and on headless mode the lead maintainer's position (issues #82 and #113) is that it cannot be undetected without a custom-compiled Chromium. The README lists Cloudflare among the protections it passes "with the right setup", and most failures come from leaving that setup.
Why patchright gets blocked or breaks
- Headless mode. headless=True keeps "HeadlessChrome" in the user agent, and patchright will not rewrite it because, in the maintainer's words, changing the user agent "introduces other leaks".
- Added fingerprints. Hardcoded user agents, custom headers, extensions and rotating proxies were the first things maintainers pointed at in #37; a wrong Chrome version in the user agent caused the loop in #73.
- Environment. Docker, CI runners and Linux aarch64 look unlike a desktop (a maintainer called aarch64 "probably a red flag for antibots"), and datacenter IPs hurt whatever the browser does.
- Version churn. New versions are deployed automatically after each Playwright release, and the README warns that bugs from Playwright changes "might take a few days" to fix. Real examples: 1.57.x shipped the vanilla Playwright driver (patchright-python #95), Turnstile clicks broke in 1.60.0 (#203), and authenticated proxies hung on 1.64.1 (#259).
- Wrong browser files. Each Playwright-based version needs its own browser build, and patchright trails upstream (1.64.4 on PyPI, Playwright 1.65), so browsers from the official Playwright CLI may not be the ones it looks for.
Fix 1: install the browser for your exact version
"Executable doesn't exist at …" and "Chromium distribution 'chrome' is not found" are install problems, not detection. Reinstall the browsers with the patchright CLI after each upgrade and pin the package. The patchright-python GitHub releases page stops at v1.62.0 (17 August 2026), so check PyPI for the current version.
On Linux arm64, Google Chrome cannot be installed through the CLI yet (patchright-python #121 is open), so use the bundled Chromium there. Frozen executables are a known gap too: patchright-python #45 (PyInstaller and Nuitka do not bundle Chromium) is still open.
# Python 3.10+: the package, then the browsers THIS patchright version expects
pip install -U patchright
patchright install chromium # bundled Chromium build
patchright install chrome # Google Chrome stable, for channel="chrome"
# Node.js 20+
npm i patchright
npx patchright install chromium
npx patchright install chrome # use the patchright CLI, not "npx playwright install"
# Pin the version so an automatic upstream release cannot change behaviour between deploys
pip install "patchright==1.64.4" # PyPI, 2026-11-02
npm i patchright@1.64.3 # npm, 2026-11-02
# Linux server without a display: run the headed browser inside Xvfb
xvfb-run -a python app.pyFix 2: use the documented best-practice launch
The README's recommended setup is launch_persistent_context with channel="chrome", headless=False and no_viewport=True, without custom headers or a user agent. A persistent profile keeps cookies such as cf_clearance between runs. On a server, run the headed browser inside Xvfb; the maintainers recommend it instead of headless.
If you see Chrome's "You are using an unsupported command-line flag: --disable-blink-features=AutomationControlled" bar, it is cosmetic: the maintainer said in #238 that a website cannot detect it, and it was later resolved on the Chrome side. Do not remove the flag with ignore_default_args, which brings back navigator.webdriver.
from patchright.sync_api import sync_playwright
TARGET = "https://example.com/"
with sync_playwright() as p:
# The README's "best practice": real Chrome, headed, persistent profile,
# no viewport emulation and no fingerprint injection of any kind.
context = p.chromium.launch_persistent_context(
user_data_dir="./patchright-profile",
channel="chrome", # needs: patchright install chrome
headless=False, # headless is detectable; use Xvfb on servers
no_viewport=True, # keep the real window size
# do NOT set user_agent, extra_http_headers or load extensions
# proxy={"server": "http://host:port", "username": "u", "password": "p"},
)
page = context.pages[0] if context.pages else context.new_page()
page.goto(TARGET)
print(page.title())
context.close()
# Node.js equivalent:
# chromium.launchPersistentContext("./patchright-profile",
# { channel: "chrome", headless: false, viewport: null })Fix 3: Turnstile and the "Just a moment..." challenge
In a clean headed browser the challenge often clears by itself, so wait for cf_clearance or a filled cf-turnstile-response before clicking. Click the checkbox at most once, inside the challenges.cloudflare.com frame. If a click registers but nothing happens on 1.60.0 to 1.61.1, that is regression #203; upgrade. Shadow-DOM access in the widget also regressed after 1.56.0 (#173, fixed in March 2026).
Older answers suggest CDP-Patches for OS-level clicks. That repository was archived on 28 September 2025 and its README now says the underlying Chromium input leak is fixed, with "no reason to use this package anymore, except for Select Elements".
from patchright.sync_api import sync_playwright
def turnstile_frame(page):
return next((f for f in page.frames if "challenges.cloudflare.com" in f.url), None)
def wait_for_cloudflare(page, context, timeout_s=30):
"""Wait for cf_clearance or a Turnstile token; click the checkbox at most once."""
clicked = False
for second in range(timeout_s):
if any(c["name"] == "cf_clearance" for c in context.cookies()):
return "cleared"
# The DOM is shared between worlds, so the default isolated context can read it
token = page.evaluate(
"() => document.querySelector('[name=\"cf-turnstile-response\"]')?.value || ''"
)
if token:
return "turnstile-token"
frame = turnstile_frame(page)
if frame and not clicked and second >= 5:
try:
# patchright locators reach into the widget's closed shadow root
frame.get_by_role("checkbox").click(timeout=3000)
clicked = True
except Exception:
pass
page.wait_for_timeout(1000)
return "timeout"
with sync_playwright() as p:
context = p.chromium.launch_persistent_context(
"./patchright-profile", channel="chrome", headless=False, no_viewport=True
)
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com/")
print(wait_for_cloudflare(page, context))
# Page globals (window.turnstile, site callbacks) live in the main world:
print(page.evaluate("() => typeof window.turnstile", isolated_context=False))
context.close()Fix 4: evaluate, init scripts, console and proxies
- Main-world globals: evaluate, evaluate_handle and evaluate_all take isolated_context (default True). Pass isolated_context=False to read window.turnstile or call a site's callback; keep the default for plain DOM reads.
- Console: page.on("console") will not fire. The README suggests in-page loggers, which can be detected too.
- Init scripts: issue #41 showed Cloudflare detecting add_init_script via a visible script tag and the injection fetch's TLS fingerprint. Both were fixed in March 2025; still, if a site only fails with an init script, test without it.
- Proxies: pass credentials through the proxy option, keep one exit IP per profile, and stay current; #166 and #259 were proxy bugs since fixed.
- Do not stack playwright-stealth on top. Patchright's best practice is "without fingerprint injection". If you are comparing approaches, see rebrowser-patches not working and our comparison of open-source Turnstile and Cloudflare solvers.
When to switch to an API
Patchright is the right tool when you need a real browser session: logins, clicks, multi-step flows. It is the wrong layer when you run dozens of headed Chrome instances under Xvfb for one token per form, or when the same widget keeps looping after the fixes above.
Then keep patchright for navigation and hand only the Turnstile step to a solver. Only automate sites you own or are authorised to access.
NSLSolver example: a Turnstile token for your patchright page
The Cloudflare Turnstile solver API takes the widget's site_key and the page url (plus action and cdata only if the widget sets them) and returns a token in about 250 ms on average. Solving is server-side, with no browser on our side. Inject the token as cf-turnstile-response in the main world, where the site's callback lives. It costs $0.80 per 1,000 solves, failed solves are free (a 503 is not billed and safe to retry), and sign-ups with Google, Gmail or Proton get free trial credit; see pricing.
For the full-page "Just a moment..." challenge, the Cloudflare Challenge solver API returns cf_clearance plus the user_agent to replay through the same proxy you send (about 3.3 s, $1.00 per 1,000). That clearance is issued for an iPhone Safari browser, so replay it from a plain HTTP client rather than inside desktop Chrome; the cf_clearance guide explains why. NSLSolver does not solve reCAPTCHA v2, hCaptcha, image CAPTCHAs or DataDome.
import requests
from patchright.sync_api import sync_playwright
API_KEY = "nsl_YOUR_API_KEY"
def solve_turnstile(site_key, url, action=None, cdata=None):
payload = {"type": "turnstile", "site_key": site_key, "url": url}
if action:
payload["action"] = action # only if the widget sets data-action
if cdata:
payload["cdata"] = cdata # only if the widget sets data-cdata
r = requests.post(
"https://api.nslsolver.com/solve",
headers={"X-API-Key": API_KEY},
json=payload,
timeout=120,
)
if r.status_code == 503: # not completed: not billed, safe to retry
raise RuntimeError("retry")
r.raise_for_status()
return r.json()["token"]
INJECT = """(token) => {
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;
const cb = document.querySelector('[data-callback]')?.getAttribute('data-callback');
if (cb && "undefined"[cb] === 'function') window[cb](token);
}"""
with sync_playwright() as p:
context = p.chromium.launch_persistent_context(
"./patchright-profile", channel="chrome", headless=False, no_viewport=True
)
page = context.pages[0] if context.pages else context.new_page()
page.goto("https://example.com/login")
widget = page.locator("[data-sitekey]").first
token = solve_turnstile(
widget.get_attribute("data-sitekey"),
page.url,
widget.get_attribute("data-action"),
widget.get_attribute("data-cdata"),
) # ~250 ms on average; a token is single-use and valid for 300 s
# isolated_context=False: the site's callback lives in the main world
page.evaluate(INJECT, token, isolated_context=False)
page.click("button[type=submit]")
context.close()Related guides
- Playwright Stealth not working: the stealth_sync ImportError, the Runtime.enable leak and patchright vs rebrowser.
- rebrowser-patches not working: the other patched Playwright and Puppeteer approach.
- cf-turnstile-response invalid: why an injected token is rejected on submit.
- The cf_clearance cookie explained: what binds it to IP and User-Agent.
- Cloudflare Challenge solver API: cf_clearance and the user_agent from one call.
Sources (checked 2026-12-01)
- GitHub: Kaliiiiiiiiii-Vinyzu/patchright (patches, init-script notes, bugs)
- GitHub: patchright-python README (install, best practice, isolated_context)
- GitHub: patchright-nodejs README (npx install, isolatedContext)
- PyPI: patchright (1.64.4, 2026-11-02, Python 3.10+)
- npm: patchright (1.64.3, 2026-11-02, Node 20+)
- patchright-python releases (latest tag v1.62.0, automatic deployments)
- Issue #37: managed challenges, fingerprinting out of scope
- Issue #82: HeadlessChrome user agent in headless mode
- Issue #73: Cloudflare captcha loop with a custom user agent
- Issue #203: Turnstile click regression in 1.60.0
- Issue #224: fails in Docker / GitHub Actions, works locally
- Issue #41: add_init_script detected by Cloudflare (fixed)
- Issue #259: authenticated proxy hang on 1.64.1 (fixed)
- patchright-python issue #121: install chrome on Linux arm64
- CDP-Patches README (archived 2025-09-28)