Automate captcha solving with Playwright and the CaptchaSonic API. Works with reCAPTCHA v2, reCAPTCHA v3, Cloudflare Turnstile, Geetest v4, AWS WAF, and image captchas.
# 1. Clone and install
git clone https://github.com/Captcha-Sonic/playwright-solver.git
cd captchasonic-playwright-examples
npm install
# 2. Install Playwright browsers
npx playwright install chromium
# 3. Configure your API key
cp .env.example .env
# Edit .env and add your API key
# 4. Run any example
npm run recaptcha-v2Get your API key at captchasonic.com.
| Captcha | Token Method | Script Method | Run Command |
|---|---|---|---|
| reCAPTCHA v2 | ✅ | ✅ | npm run recaptcha-v2 |
| reCAPTCHA v3 | ✅ | — | npm run recaptcha-v3 |
| Cloudflare Turnstile | ✅ | — | npm run turnstile |
| Geetest v4 | ✅ | ✅ | npm run geetest |
| AWS WAF | ✅ | ✅ | npm run aws-waf |
| Image Captcha (OCR) | ✅ | — | npm run image-captcha |
| Popular Captcha | ✅ | ✅ | npm run popularcaptcha |
Uses the CaptchaSonic API to solve captchas server-side — no visible browser interaction needed.
Your script → CaptchaSonic API → returns token → inject into page → submit
Best for: headless automation, CI/CD pipelines, maximum speed
Injects lightweight JS scripts into the page that detect, extract, and click captcha challenges using the CaptchaSonic image classification API.
Inject script → detect captcha → extract images → SDK classifies → inject clicks
Best for: Popular Captcha, Geetest, AWS WAF, and any visual challenge captcha
captchasonic-playwright-examples/
├── scripts/ # Vendored JS captcha scripts
│ ├── popularcaptcha.js
│ ├── recaptcha-v2.js
│ ├── geetest.js
│ └── aws-waf.js
├── shared/
│ ├── helpers.ts # Reusable utilities
│ └── solver.ts # ScriptSolver bridge class
├── examples/
│ ├── recaptcha-v2/
│ │ ├── token-method.ts
│ │ └── script-method.ts
│ ├── recaptcha-v3/
│ │ └── token-method.ts
│ ├── turnstile/
│ │ └── token-method.ts
│ ├── geetest/
│ │ ├── token-method.ts
│ │ └── script-method.ts
│ ├── aws-waf/
│ │ ├── token-method.ts
│ │ └── script-method.ts
│ ├── image-captcha/
│ │ └── token-method.ts
│ └── popularcaptcha/
│ ├── token-method.ts
│ └── script-method.ts
├── package.json
└── tsconfig.json
# Token method (API-based)
npm run recaptcha-v2
npm run recaptcha-v3
npm run turnstile
npm run geetest
npm run aws-waf
npm run image-captcha
npm run popularcaptcha
# Script method (JS injection)
npm run recaptcha-v2:script
npm run geetest:script
npm run aws-waf:script
npm run popularcaptcha:scriptcp .env.example .envCAPTCHASONIC_API_KEY=sonic_your_key_here| Variable | Required | Description |
|---|---|---|
CAPTCHASONIC_API_KEY |
✅ | Your CaptchaSonic API key (sonic_xxx) |
Each example targets a public demo page. To use on your own site:
- Open any
token-method.ts - Change
SITE_URLto your target page - Change
SITE_KEYto the captcha key on that page - Run the script
const SITE_URL = 'https://yoursite.com/login';
const SITE_KEY = 'your-site-key-here';- Node.js ≥ 18
- Playwright — installed automatically via
npm install - CaptchaSonic API key — get one here
- CaptchaSonic Documentation
- CaptchaSonic Dashboard
- Playwright Documentation
- Puppeteer TypeScript Examples
- Selenium Python Examples
MIT — free to use in commercial projects.