Captcha solver for
Playwright
Resolve the challenge inside the run instead of failing the job. A working Python example, and the three things that decide whether your token is accepted.
import time
import requests
CAPTCHANO_KEY = "cn-YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {CAPTCHANO_KEY}"}
def solve(task: dict) -> dict:
"""Block until solved; returns e.g. {"token": "...", "userAgent": "..."}."""
r = requests.post(
"https://api.captchano.com/v1/solve",
params={"wait": 60},
json=task,
headers=HEADERS,
timeout=75,
)
data = r.json()
# A solve can outlast the 60 s wait: poll the task until it finishes.
while data.get("status") in ("queued", "solving"):
time.sleep(5)
data = requests.get(
f"https://api.captchano.com/v1/task/{data['id']}",
headers=HEADERS,
timeout=30,
).json()
if data.get("status") != "ready":
raise RuntimeError(data.get("error") or data)
return data["solution"]
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page()
page.goto("https://example.com/register")
sitekey = page.get_attribute("[data-sitekey]", "data-sitekey")
solution = solve({"type": "recaptcha_v2", "sitekey": sitekey, "url": page.url})
page.evaluate(
"t => document.getElementById('g-recaptcha-response').value = t",
solution["token"],
)
page.click("button[type=submit]")What decides whether the token is accepted
- Pass your proxy through. The token should be minted behind the same exit IP that submits it. For session-graded systems this is mandatory, not an optimisation.
- Match the user agent. Turnstile and several anti-bot systems bind the token to a user agent. We return the one used so you can replay it exactly.
- Request late. Tokens expire in roughly 120 seconds. Ask for one when you are ready to submit.
Blocking or polling
The example uses ?wait=60, so the call returns the finished solve and your Playwright step stays linear. If you would rather not hold a connection, drop the parameter, keep the returned id, and poll GET /v1/task/{id} every five seconds. A token you have paid for stays retrievable for ten minutes, so a dropped connection does not cost you the solve.
Cost
$0.00598 per successful reCAPTCHA v2 solve, with failed solves never billed. See pricing for every challenge type, or the API reference for the full request shape.
How the solve fits into Playwright
Playwright's locators make it easy to read the widget, and page.evaluate injects the token. Solve as late as possible so the two-minute token lifetime is not spent on navigation.
- 01Create a context
browser.new_context with the proxy and user agent you will submit from.
- 02Read the widget
page.locator('[data-sitekey]').first, then get_attribute for sitekey and callback.
- 03Solve
POST to /v1/solve?wait=60 with type, sitekey, page.url, proxy and user agent.
- 04Inject, submit, verify
page.evaluate to inject, click submit, then check what the page actually shows.
Getting the token into the page
page.evaluate fills the response field and calls the data-callback function with the token.
Where integrations usually go wrong
A script that logs 'solved' after clicking submit has verified nothing. Assert on the page's success state.
Set the proxy on the context you use for the page, and send the same one with the solve.
If the page calls grecaptcha.render, find the callback name in the page's own script.
Playwright captcha FAQ
Can Playwright bypass captchas without a solver?
Not reliably. Playwright automates the browser but cannot answer image challenges. Audio-transcription libraries work sometimes, but depend on the audio option being offered, which is often withheld from automated sessions.
Does this work with Playwright for Node, Java and .NET?
Yes. The example is Python, but the flow is the same HTTP call and the same page.evaluate in every Playwright language binding.
How do I test my own forms with Playwright?
Do not solve your own captcha in CI. Use the provider's test keys, such as Google's reCAPTCHA test site key or Cloudflare's Turnstile test keys, so your tests are fast and free.
What about reCAPTCHA v3 in Playwright?
v3 has no widget to fill. Request a v3 token with the page's action name and send it where the page sends its own token, usually in a form field or request body.
Guides that help
Ready to build?
Start with a free 7-day trial of the Hobby plan, then pay per successful solve or keep the plan as your traffic grows. Cancel before the trial ends and you pay nothing.