Skip to main content

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

Python 3.8+ PyPI version

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!

✨ What it does

This framework helps you solve captchas in Playwright or Playwright-based frameworks (like Camoufox or Patchright) automatically. It will:

  1. Detect the captcha on your page
  2. Solve it using your preferred method
  3. Apply the solution automatically
  4. Submit the form (when needed & possible)

📸 Demonstration (recorded in headless mode)

⚠️ 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

TwoCaptcha Solver

Uses the 2Captcha.com API for solving:

  • ✅ Cloudflare Interstitial
  • ✅ Cloudflare Turnstile
  • ✅ 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:

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())

TwoCaptcha Solver Example

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
        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:

  1. Find the captcha element on the page
  2. Click on it using browser automation
  3. Wait for successful completion

External Solver Process (e.g., TwoCaptcha):

  1. Find the captcha element
  2. Extract required data (site key, URL, etc.)
  3. Send to external solving service
  4. Apply the returned solution
  5. 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_script method. 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

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)
)

# TwoCaptcha solver with custom settings  
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

playwright_captcha-0.1.1.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playwright_captcha-0.1.1-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file playwright_captcha-0.1.1.tar.gz.

File metadata

  • Download URL: playwright_captcha-0.1.1.tar.gz
  • Upload date:
  • Size: 34.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for playwright_captcha-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e8f2ec7e7dab84bbba5053d56aadcc1030fe76c1a5314625cd254cd009a5b9d7
MD5 ca16d9fe3af2472dd1e09a7655b37d92
BLAKE2b-256 f2c5db6523f102bbf069746e7b6a47803cbc7f56a7e34635a504165844c09fc1

See more details on using hashes here.

File details

Details for the file playwright_captcha-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for playwright_captcha-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 edcca33c2e09fd9f51ca98ef753f949c3f8ecbe38abecb4b8a30c3b79ad79f4c
MD5 e54e8ed8047335603c85578a9d83bbb0
BLAKE2b-256 ec4faf153778ca11f7b273e4d2b40265ff1000dada009128dd661430962246fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page