Auto-solve reCAPTCHA, hCaptcha & Turnstile in Playwright (Python + Node.js) — Last Updated: August 29, 2026
⚡ TL;DR: Playwright has no built-in captcha solving. The reliable pattern: extract sitekey → request token from CaptchaKings (~3s) → inject via page.evaluate() → continue. Works in headless Chromium, Firefox & WebKit. Free $0.50 credit on signup.
Playwright is the best modern browser-automation framework — but CAPTCHAs are explicitly designed to stop it. Microsoft's stealth techniques help you look human; a solving API makes you pass as human. Combining both gives you the highest success rate for scraping, testing, and automation at scale.
pip install playwright captchakings
playwright install chromium
from playwright.sync_api import sync_playwright
from captchakings import CaptchaKings
API_KEY = "ck_your_api_key_here"
PAGE_URL = "https://example.com/login"
client = CaptchaKings(API_KEY)
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page()
page.goto(PAGE_URL)
# 1. Pull the sitekey out of the DOM
sitekey = page.get_attribute("[data-sitekey]", "data-sitekey")
# 2. Solve with CaptchaKings (<3s average)
token = client.solve_recaptcha_v2(sitekey=sitekey, page_url=PAGE_URL)
# 3. Inject the token & submit
page.evaluate("""(t) => {
document.getElementById('g-recaptcha-response').innerHTML = t;
}""", token)
page.click("button[type=submit]")
page.wait_for_load_state("networkidle")
print("Passed:", page.url)
browser.close()
const { chromium } = require('playwright');
const axios = require('axios');
const API_KEY = 'ck_your_api_key_here';
const PAGE_URL = 'https://example.com/login';
async function solveRecaptcha(sitekey, pageUrl) {
const { data } = await axios.post('https://captchakings.com/api', {
api_key: API_KEY,
captcha_type: 'recaptcha_v2',
sitekey: sitekey,
page_url: pageUrl
});
return data.token;
}
(async () => {
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(PAGE_URL);
const sitekey = await page.getAttribute('[data-sitekey]', 'data-sitekey');
const token = await solveRecaptcha(sitekey, PAGE_URL);
await page.evaluate((t) => {
document.getElementById('g-recaptcha-response').innerHTML = t;
}, token);
await page.click('button[type=submit]');
await page.waitForLoadState('networkidle');
console.log('Passed:', page.url());
await browser.close();
})();
Turnstile follows the identical pattern — the only difference is the target field cf-turnstile-response:
token = client.solve_turnstile(sitekey=sitekey, page_url=PAGE_URL)
page.evaluate("""(t) => {
document.querySelector('[name=cf-turnstile-response]').value = t;
}""", token)
| Capability | Playwright alone | Playwright + CaptchaKings |
|---|---|---|
| reCAPTCHA v2/v3/Enterprise | ❌ Blocked | ✅ <3s token injection |
| hCaptcha / Turnstile | ❌ Blocked | ✅ <3s token injection |
| AWS WAF challenges | ❌ Blocked | ✅ Solved + cookie reuse |
| Image/text captchas | ❌ No OCR | ✅ AI OCR, <2s |
| Cost at 100k solves/mo | — | from $0.30 / 1,000 |
Yes — solving is done on CaptchaKings servers, so headless Chromium, Firefox and WebKit all work identically. No browser extension is required.
Absolutely. After passing the challenge, export context.storage_state() and reload it in later runs to skip solving again until the session expires.
Pass Playwright's proxy settings as usual and make sure the solving IP matches — or use the built-in CaptchaKings IP Rotator for automatic rotation.
🎁 Free $0.50 credit — test the full Playwright flow on us. Create your API key →