Automating captcha solving for Playwright. Supports Cloudflare Turnstile & Interstitial, and reCAPTCHA V2 & V3 with Click-based or API (2captcha) solving. Designed for easy integration with Playwright, Patchright, and Camoufox.
Project description
Playwright Captcha
A Python library that makes captcha solving simple and automated with Playwright and Playwright-based frameworks. Just a few lines of code, and you're ready to go!
(Need some help with Automation? You can hire me for custom development or consulting!)
โจ What it does
This framework helps you solve captchas in Playwright or Playwright-based frameworks (like Camoufox or Patchright) automatically. It will:
- Detect the captcha on your page
- Solve it using your preferred method
- Apply the solution automatically
- Submit the form (when needed & possible)
Nstproxy delivers reliable, scalable, and cost-efficient proxies โ residential, datacenter, ISP, and IPv6 โ with rotation, anti-block tech, and pricing from $0.1/GB for maximum uptime and ROI.
๐ Learn more: Nstproxy.com: https://www.nstproxy.com/?type=flow&utm_source=techinz | Dashboard
Telegram: https://t.me/nstproxy Discord: https://discord.gg/5jjWCAmvng
Use code: TECHINZ get 10% OFF
๐ธ Demonstration (recorded in headless mode)
Click Solver
Cloudflare Interstitial
https://github.com/user-attachments/assets/06c244ff-ba82-4d8a-9ef8-17ece400716c
Cloudflare Turnstile
https://github.com/user-attachments/assets/52b49abd-5aa4-4262-9cb6-a555a95330c9
API Solver (Twocaptcha used here but others work similarly)
Cloudflare Interstitial
https://github.com/user-attachments/assets/25a6233b-43fb-4164-b41c-ea80100b501d
Cloudflare Turnstile
https://github.com/user-attachments/assets/0f3f7999-1e0d-437e-9727-36a99a6c5abd
โ ๏ธ LEGAL DISCLAIMER
THIS TOOL IS PROVIDED FOR EDUCATIONAL AND RESEARCH PURPOSES ONLY
This software is designed to demonstrate security concepts and should not be used to bypass protections on websites without explicit permission from the website owner. Using this tool against websites without authorization may violate:
- The Computer Fraud and Abuse Act (CFAA)
- Terms of Service agreements
- Various cybersecurity laws in your jurisdiction
๐ Supported Captcha Types
Click Solver
Uses the browser's stealthiness to automatically click and solve captchas (works good only with playwright's stealthy patches e.g. camoufox/patchright):
- โ Cloudflare Interstitial
- โ Cloudflare Turnstile
API Solver
TwoCaptcha - https://2captcha.com
Uses the 2Captcha.com API for solving:
-
โ Cloudflare Interstitial
-
โ Cloudflare Turnstile
-
โ reCAPTCHA v2
-
โ reCAPTCHA v3
TenCaptcha - https://10captcha.com
Uses the 10Captcha.com API for solving:
-
โ reCAPTCHA v2
-
โ reCAPTCHA v3
CaptchaAI - https://captchaai.com
Uses the captchaai.com API for solving:
-
โ reCAPTCHA v2
-
โ reCAPTCHA v3
More captcha types and solvers coming soon! Contributions welcome.
๐ฆ Installation
pip install playwright-captcha
๐ง Quick Start
Check out the examples directory for detailed usage examples:
- Cloudflare Examples: Turnstile and Interstitial challenges
- reCAPTCHA Examples: v2 and v3 implementations
Each example includes configurations for Playwright, Patchright, and Camoufox.
Click Solver Example
import asyncio
from playwright.async_api import async_playwright
from playwright_captcha import CaptchaType, ClickSolver, FrameworkType
async def solve_captcha():
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 ClickSolver(framework=framework, page=page) as solver:
# Navigate to your target page
await page.goto('https://example.com/with-captcha')
# Solve the captcha
await solver.solve_captcha(
captcha_container=page,
captcha_type=CaptchaType.CLOUDFLARE_TURNSTILE
)
# Continue with your automation...
asyncio.run(solve_captcha())
API Solver Example (TwoCaptcha)
import asyncio
import os
from playwright.async_api import async_playwright
from twocaptcha import AsyncTwoCaptcha
from playwright_captcha import CaptchaType, TwoCaptchaSolver, FrameworkType
async def solve_with_2captcha():
# Initialize 2Captcha client
captcha_client = AsyncTwoCaptcha(os.getenv('TWO_CAPTCHA_API_KEY'))
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
# Available API Solvers:
# TwoCaptchaSolver
# TenCaptchaSolver
# CaptchaAISolver
async with TwoCaptchaSolver(framework=framework,
page=page,
async_two_captcha_client=captcha_client) as solver:
# Navigate to your target page
await page.goto('https://example.com/with-recaptcha')
# Solve reCAPTCHA v2
await solver.solve_captcha(
captcha_container=page,
captcha_type=CaptchaType.RECAPTCHA_V2
)
# Continue with your automation...
asyncio.run(solve_with_2captcha())
๐ฏ How It Works
Click Solver Process:
- Find the captcha element on the page
- Click on it using browser automation
- Wait for successful completion
External Solver Process (e.g., TwoCaptcha, TenCaptcha, CaptchaAI):
- Find the captcha element
- Extract required data (site key, URL, etc.)
- Send to external solving service
- Apply the returned solution
- Submit the form (when applicable)
๐บ๏ธ TODO
๐ฏ Next Captcha Types
- hCaptcha
๐ง New Solver Types
- CapSolver
- AI Solver
Other
- Unit & Integration Tests
๐ Browser Compatibility
Standard Playwright
Works with all standard Playwright browsers (Chrome, Firefox, Safari).
Stealth Browsers
For better success rates, especially with click-based solving:
Patchright
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=False)
framework = FrameworkType.PATCHRIGHT
# ... rest of your code
Camoufox
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=False,
geoip=True,
humanize=True,
main_world_eval=True, # add this
addons=[os.path.abspath(ADDON_PATH)] # add this
) as browser:
context = await browser.new_context()
page = await context.new_page()
framework = FrameworkType.CAMOUFOX
# ... rest of your code
Note: Camoufox currently has an issue with the
add_init_scriptmethod. I've included a temporary workaround that's automatically used in the package. See the examples folder for details.
๐ Project Structure
playwright-captcha/
โโโ examples/ # Usage examples
โ โโโ cloudflare/ # Cloudflare captcha examples
โ โโโ recaptcha/ # reCAPTCHA examples
โโโ playwright_captcha/ # Main package
โโโ captchas/ # Captcha type implementations
โโโ solvers/ # Solver implementations
โโโ types/ # Type definitions
โโโ utils/ # Utility functions
๐ง Configuration
Environment Variables
(Optional) Create a .env file for your API keys:
TWO_CAPTCHA_API_KEY=your_2captcha_api_key_here
TEN_CAPTCHA_API_KEY=your_10captcha_api_key_here
CAPTCHA_AI_API_KEY=your_captchaai_api_key_here
Solver Options
# Click solver with custom settings
solver = ClickSolver(
framework=framework, # Framework type (PLAYWRIGHT, PATCHRIGHT, CAMOUFOX)
page=page,
max_attempts=5, # Number of solving attempts
attempt_delay=3 # Delay between attempts (seconds)
)
# API solver with custom settings (TwoCaptcha)
solver = TwoCaptchaSolver(
framework=framework, # Framework type (PLAYWRIGHT, PATCHRIGHT, CAMOUFOX)
page=page,
async_two_captcha_client=captcha_client,
max_attempts=3,
attempt_delay=10,
# also you can specify the captcha data like sitekey manually if it fails to detect automatically
sitekey='sitekey'
# ...
)
๐ Support
- ๐ Check the examples folder for usage patterns
- ๐ Report issues or request features on GitHub Issues
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file playwright_captchax-0.1.4.tar.gz.
File metadata
- Download URL: playwright_captchax-0.1.4.tar.gz
- Upload date:
- Size: 49.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef2072251376ef9edb85e8e302ee03df43c44d2f0249d2b020ac27748fe1508e
|
|
| MD5 |
1eb441fa3e0ef45d3f867a2441f93b9e
|
|
| BLAKE2b-256 |
429924b3bd39725db70eeb5a211e913422be43c659677c695e85d867f0df6a11
|
File details
Details for the file playwright_captchax-0.1.4-py3-none-any.whl.
File metadata
- Download URL: playwright_captchax-0.1.4-py3-none-any.whl
- Upload date:
- Size: 80.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd03dce58d834e863ad147dd115bba06c41d102f824d2017463371ef9e6a8b27
|
|
| MD5 |
860d1414ddfd076c05033c0694e38d9b
|
|
| BLAKE2b-256 |
d484da207ae3eae2346f9840932b244423907c70b5f61917855b5487d208afd6
|