On this page
reCAPTCHA v2 is the “I’m not a robot” checkbox that sometimes turns into an image grid. v3 has no widget: it watches the page in the background and gives the site a score. Below, both are solved from Python and Playwright with playwright-captcha, a library I wrote, and 2Captcha as the solving service.
Setup
You need Python 3.10 or newer (the current Playwright requires it) and a 2Captcha API key.
pip install playwright playwright-captcha python-dotenv
playwright install chromium
playwright-captcha brings its own async 2Captcha client, so don’t install the official 2captcha-python next to it: both provide the twocaptcha module.
Put the key in a .env file:
TWO_CAPTCHA_API_KEY=your_api_key_here
How the solver works
The solver reads the sitekey and a few other parameters from the page and sends them with the page URL to 2Captcha. The service solves the captcha on its side and returns a token. The solver puts the token into the page, and from there the form submits as if a person had solved it.
reCAPTCHA v2
Pass the solver the element that contains the widget. On the 2Captcha demo page that is #g-recaptcha; on your target, look for the element with data-sitekey.
import asyncio
import logging
import os
from dotenv import load_dotenv
from playwright.async_api import async_playwright
from twocaptcha import AsyncTwoCaptcha
from playwright_captcha import CaptchaType, TwoCaptchaSolver, FrameworkType
logging.basicConfig(level='INFO')
load_dotenv()
TWO_CAPTCHA_API_KEY = os.getenv('TWO_CAPTCHA_API_KEY')
async def solve_recaptcha_v2():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=False)
page = await browser.new_page()
framework = FrameworkType.PLAYWRIGHT
# Create solver BEFORE navigating to the page
async with TwoCaptchaSolver(
framework=framework,
page=page,
async_two_captcha_client=AsyncTwoCaptcha(TWO_CAPTCHA_API_KEY)
) as solver:
await page.goto('https://2captcha.com/demo/recaptcha-v2')
await asyncio.sleep(5)
# Find the reCAPTCHA container
recaptcha_container = page.locator('#g-recaptcha')
await recaptcha_container.wait_for()
# Solve it
await solver.solve_captcha(
captcha_container=recaptcha_container,
captcha_type=CaptchaType.RECAPTCHA_V2,
)
# Submit the form
submit_button = page.locator('//button[@data-action="demo_action"]')
await submit_button.wait_for()
await submit_button.click()
await asyncio.sleep(5)
try:
await page.locator('//p[text()="Captcha is passed successfully!"]').wait_for(timeout=10000)
logging.info('reCAPTCHA v2 solved successfully!')
except Exception as e:
logging.error(f'Failed: {e}')
asyncio.run(solve_recaptcha_v2())
reCAPTCHA v3
v3 has no widget to point at, so pass the whole page. The solver reads the sitekey and the action from the URL of the reCAPTCHA frame on the page.
import asyncio
import logging
import os
from dotenv import load_dotenv
from playwright.async_api import async_playwright
from twocaptcha import AsyncTwoCaptcha
from playwright_captcha import CaptchaType, TwoCaptchaSolver, FrameworkType
logging.basicConfig(level='INFO')
load_dotenv()
TWO_CAPTCHA_API_KEY = os.getenv('TWO_CAPTCHA_API_KEY')
async def solve_recaptcha_v3():
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(headless=True)
page = await browser.new_page()
framework = FrameworkType.PLAYWRIGHT
# Create solver BEFORE navigating to the page
async with TwoCaptchaSolver(
framework=framework,
page=page,
async_two_captcha_client=AsyncTwoCaptcha(TWO_CAPTCHA_API_KEY)
) as solver:
await page.goto('https://2captcha.com/demo/recaptcha-v3')
await asyncio.sleep(5)
# v3 is invisible, so pass the full page as container
await solver.solve_captcha(
captcha_container=page,
captcha_type=CaptchaType.RECAPTCHA_V3,
)
# Submit the form
submit_button = page.locator('//button[@data-action="demo_action"]')
await submit_button.wait_for()
await submit_button.click()
await asyncio.sleep(5)
try:
await page.locator('//p[text()="Captcha is passed successfully!"]').wait_for(timeout=10000)
logging.info('reCAPTCHA v3 solved successfully!')
except Exception as e:
logging.error(f'Failed: {e}')
asyncio.run(solve_recaptcha_v3())
About the v3 score
With the API solver the token, and its score, come from 2Captcha’s side, not from your browser. You can ask for a minimum by passing score=0.7 to solve_captcha(), which goes to 2Captcha as min_score. Their Python client’s documentation warns that tokens above 0.3 are hard to get, so a site with a strict threshold may still reject the token.
Your own browser’s score matters when you don’t use a solver at all. In the May 2026 run of my browser benchmark, 20 of 23 setups got 0.9 on a reCAPTCHA v3 test page, stock Playwright included.
Stealth browsers
The token doesn’t depend on your browser, but the site may run other bot checks besides reCAPTCHA. If it does, use a stealth browser. The library has built-in support for Patchright and Camoufox; anti-detect browsers such as AdsPower, Dolphin Anty, Multilogin or GoLogin work through Playwright as well.
Patchright
Patchright is Playwright with patches to Chrome and the driver that hide automation.
pip install patchright
patchright install chromium
from patchright.async_api import async_playwright
from playwright_captcha import FrameworkType
async with async_playwright() as playwright:
browser = await playwright.chromium.launch(channel="chrome", headless=True)
context = await browser.new_context()
page = await context.new_page()
framework = FrameworkType.PATCHRIGHT
# ... rest of your code
Camoufox
Camoufox is a Firefox build that fakes a consistent fingerprint.
pip install camoufox
camoufox fetch
from camoufox import AsyncCamoufox
from playwright_captcha.utils.camoufox_add_init_script.add_init_script import get_addon_path
from playwright_captcha import FrameworkType
import os
ADDON_PATH = get_addon_path()
async with AsyncCamoufox(
headless=True,
geoip=True,
humanize=True,
main_world_eval=True, # required for playwright-captcha
addons=[os.path.abspath(ADDON_PATH)] # required for playwright-captcha
) as browser:
context = await browser.new_context()
page = await context.new_page()
framework = FrameworkType.CAMOUFOX
# ... rest of your code
add_init_script doesn’t work properly in Camoufox. main_world_eval=True and the addon path above turn on the replacement that playwright-captcha ships.
Solver options
The solver retries 3 times with 5 seconds between attempts by default:
solver = TwoCaptchaSolver(
framework=framework,
page=page,
async_two_captcha_client=captcha_client,
max_attempts=3,
attempt_delay=10,
)
# If the sitekey isn't found, pass it when solving
await solver.solve_captcha(
captcha_container=page,
captcha_type=CaptchaType.RECAPTCHA_V3,
sitekey='your_sitekey_here',
)
v2 and v3 side by side
| reCAPTCHA v2 | reCAPTCHA v3 | |
|---|---|---|
| Visible to the user | Yes, a checkbox | No |
| Image puzzle | Sometimes | Never |
| What 2Captcha returns | A token | A token with a score |
What to pass as captcha_container |
The widget element | The page |
Common problems
The site rejects the v3 token. The site’s score threshold is probably above what the token got. Try score=0.7 in solve_captcha(), and check that the action the solver detected matches the one the page uses with grecaptcha.execute.
The sitekey isn’t detected. Find data-sitekey in the widget’s HTML (v2) or the render= parameter of the reCAPTCHA script URL (v3), and pass it as sitekey=.
Camoufox throws an add_init_script error. main_world_eval=True or the addon path is missing where you create the browser.
The library
playwright-captcha is open source. Besides reCAPTCHA v2 and v3 it solves Cloudflare Turnstile and the Cloudflare full-page challenge, with 2Captcha or 10Captcha as the service.