Skip to content
Programmatic guide

hCaptcha solver for Playwright Python

Drop a Sonic-issued hCaptcha token into Playwright Python. Works for standard and Enterprise widgets; no widget interaction required.

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://accounts.hcaptcha.com/demo')

    sonic = CaptchaSonic('YOUR_API_KEY')
    result = sonic.solve(
        type='HCaptchaTaskProxyless',
        website_url=page.url,
        website_key='10000000-ffff-ffff-ffff-000000000001',
    )

    await page.evaluate(
        '(t) => { document.querySelector("[name=h-captcha-response]").value = t; '
        'document.querySelector("[name=g-recaptcha-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

Can Playwright + Sonic clear hCaptcha Enterprise?
Yes. Pass the rqdata value (find it in the widget's bootstrap JS) and Sonic returns an Enterprise-valid token.
Why set both response fields?
hCaptcha is a drop-in replacement for reCAPTCHA. Backends that integrated reCAPTCHA before may still read g-recaptcha-response; new ones read h-captcha-response. Setting both covers either case.
Does this work headless?
Yes. Token injection lives in DOM, not in browser interaction history. Headless and headed Playwright sessions produce the same outcome.

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)
hCaptcha (incl. Enterprise)
Success rate (trailing 30d)99.9%~95%~98%~95%~97%
Price per 1k — hCaptcha$0.90$2.99$1.20$2.00$1.50
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