# CAPTCHA Solver Skill

## Overview
Solve CAPTCHAs using multiple approaches:
1. **Capsolver API** - Fast, reliable, paid ($0.001-0.003/solve)
2. **Gemini Vision** - Free, for image CAPTCHAs
3. **2Captcha** - Backup, $1/1000 solves

## Setup

### Option 1: Capsolver (Recommended)
```bash
# Sign up at https://dashboard.capsolver.com
export CAPSOLVER_API_KEY="your_key_here"
```

### Option 2: 2Captcha
```bash
npm install @2captcha/captcha-solver
export TWOCAPTCHA_API_KEY="your_key_here"
```

## Usage

### For reCAPTCHA v2 (checkbox/invisible)
```bash
# Using Capsolver
curl -X POST https://api.capsolver.com/createTask \
  -H "Content-Type: application/json" \
  -d '{
    "clientKey": "'$CAPSOLVER_API_KEY'",
    "task": {
      "type": "ReCaptchaV2TaskProxyLess",
      "websiteURL": "https://example.com",
      "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
    }
  }'
```

### For Image CAPTCHA (using Gemini)
```bash
# Screenshot the CAPTCHA
agent-browser screenshot /tmp/captcha.png

# Use Gemini to solve
gemini "Look at this CAPTCHA image and tell me exactly what text/numbers are shown. Be precise." --image /tmp/captcha.png
```

### For hCaptcha
```bash
curl -X POST https://api.capsolver.com/createTask \
  -H "Content-Type: application/json" \
  -d '{
    "clientKey": "'$CAPSOLVER_API_KEY'",
    "task": {
      "type": "HCaptchaTaskProxyLess",
      "websiteURL": "https://example.com",
      "websiteKey": "your_hcaptcha_site_key"
    }
  }'
```

## Workflow for Browser Automation

1. **Detect CAPTCHA** - Screenshot page, check for CAPTCHA elements
2. **Extract Parameters** - Get sitekey from page source
3. **Solve via API** - Send to Capsolver/2Captcha
4. **Inject Token** - Use JavaScript to set the response token
5. **Submit Form** - Continue automation

### Example: Solving reCAPTCHA in agent-browser
```bash
# 1. Get the sitekey from the page
SITEKEY=$(agent-browser eval 'document.querySelector("[data-sitekey]")?.getAttribute("data-sitekey") || document.querySelector(".g-recaptcha")?.getAttribute("data-sitekey")' 2>&1)

# 2. Get current URL
URL=$(agent-browser get url 2>&1)

# 3. Solve via Capsolver
TASK_RESPONSE=$(curl -s -X POST https://api.capsolver.com/createTask \
  -H "Content-Type: application/json" \
  -d '{
    "clientKey": "'$CAPSOLVER_API_KEY'",
    "task": {
      "type": "ReCaptchaV2TaskProxyLess",
      "websiteURL": "'$URL'",
      "websiteKey": "'$SITEKEY'"
    }
  }')

TASK_ID=$(echo $TASK_RESPONSE | jq -r '.taskId')

# 4. Poll for result (typically 10-30 seconds)
sleep 15
RESULT=$(curl -s -X POST https://api.capsolver.com/getTaskResult \
  -H "Content-Type: application/json" \
  -d '{
    "clientKey": "'$CAPSOLVER_API_KEY'",
    "taskId": "'$TASK_ID'"
  }')

TOKEN=$(echo $RESULT | jq -r '.solution.gRecaptchaResponse')

# 5. Inject the token into the page
agent-browser eval 'document.getElementById("g-recaptcha-response").innerHTML = "'$TOKEN'"'

# 6. Submit the form
agent-browser click "submit-button"
```

## Pricing Reference
- **Capsolver**: ~$0.80-2.00 per 1000 reCAPTCHA v2
- **2Captcha**: ~$1.00 per 1000 standard CAPTCHAs
- **Gemini**: Free (but slower, for images only)

## Tips
1. Use residential proxies to reduce CAPTCHA frequency
2. Add human-like delays between actions
3. Randomize mouse movements and typing speed
4. Use browser profiles with cookies/history
5. Try OAuth/SSO first - often bypasses CAPTCHA
