Captcha bypass tutorials

Was this helpful?

How to bypass reCAPTCHA v2 Invisible

Gregory Fisher

Technical engineer

Introduction

reCAPTCHA v2 Invisible is Google's hidden CAPTCHA variant that operates in the background without requiring explicit user interaction with a widget. Unlike the classic reCAPTCHA v2 checkbox ("I'm not a robot"), the invisible version triggers automatically when specific actions occur on the page: clicking a button, submitting a form, or loading content.

For developers working on automation, testing, or web scraping, reCAPTCHA v2 Invisible presents a unique challenge: the CAPTCHA isn't visually displayed, yet it blocks target actions until verification is complete.

This article serves as a practical guide to bypassing reCAPTCHA v2 Invisible using the 2Captcha API. You'll learn how to identify CAPTCHA parameters, submit a solving task, retrieve the token, and properly inject it into the page.

What Is reCAPTCHA v2 Invisible

reCAPTCHA v2 Invisible is a verification mechanism that:

  • Does not display a visible widget on the page
  • Triggers automatically upon user actions (clicks, form submissions)
  • Uses a callback function to handle verification results
  • Requires token submission via a callback function rather than a form field

Key Differences from Standard reCAPTCHA v2:

Feature reCAPTCHA v2 (Checkbox) reCAPTCHA v2 Invisible
Visible widget on page Yes ("I'm not a robot" checkbox) No (hidden verification)
Activation User clicks the checkbox Automatically upon action
Token field g-recaptcha-response Callback function
isInvisible parameter false or omitted true

Required API Parameters

To solve reCAPTCHA v2 Invisible via the 2Captcha API, you'll need the following parameters:

Mandatory Parameters

Parameter Description Example
type Task type: RecaptchaV2TaskProxyless or RecaptchaV2Task "RecaptchaV2TaskProxyless"
websiteURL Full URL of the page containing the CAPTCHA "https://target-site.com/login"
websiteKey CAPTCHA sitekey (data-sitekey attribute) "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u"
isInvisible Flag for invisible version true
Parameter Description Example
userAgent Browser User-Agent for session consistency "Mozilla/5.0 (Windows NT 10.0; Win64; x64)..."
cookies Cookies for authenticated sessions "session_id=abc123; user=john"
recaptchaDataSValue Value of the data-s parameter (for Google services) "some_value"
apiDomain reCAPTCHA loading domain: google.com or recaptcha.net "recaptcha.net"

Proxy Parameters (for RecaptchaV2Task type)

Parameter Description Example
proxyType Proxy type: http, socks4, socks5 "http"
proxyAddress Proxy server IP or hostname "1.2.3.4"
proxyPort Proxy server port 8080
proxyLogin Proxy authentication username "proxy_user"
proxyPassword Proxy authentication password "proxy_pass"

How to Find reCAPTCHA v2 Invisible Parameters

Step 1: Identifying the Sitekey

  1. Open the target page in your browser
  2. Launch DevTools (F12) → Elements or Network tab
  3. Locate the CAPTCHA element—typically a <div> with class g-recaptcha and a data-sitekey attribute
html Copy
<div class="g-recaptcha" 
     data-sitekey="6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u"
     data-callback="onSubmit"
     data-size="invisible">
</div>
  1. Copy the data-sitekey value—this is your websiteKey

Step 2: Finding the Callback Function

For the invisible version, identifying the callback function name is critical:

  1. In the same element, locate the data-callback attribute
  2. The attribute value is the function name you'll need to invoke with the token

Example: data-callback="onSubmit" → call onSubmit(token)

Step 3: Alternative Method – Console Script

If parameters are hidden or dynamically loaded, use this script to extract reCAPTCHA data:

javascript Copy
function findRecaptchaClients() {
    if (typeof ___grecaptcha_cfg === 'undefined') return [];
    
    return Object.entries(___grecaptcha_cfg.clients).map(([cid, client]) => {
        const data = {
            id: cid,
            version: client['C'] ? 'V3' : 'V2',
            sitekey: client['C']?.['k'] || client['k'],
            callback: client['C']?.['C']?.['callback']?.toString() || null,
            action: client['C']?.['C']?.['action'] || null
        };
        return data;
    }).filter(item => item.sitekey);
}

console.log(JSON.stringify(findRecaptchaClients(), null, 2));

Run this script in your browser console—it returns an array of objects containing parameters for all CAPTCHAs on the page.

API Task Types

Uses 2Captcha's internal proxy pool. Suitable for most use cases.

json Copy
{
    "clientKey": "YOUR_API_KEY",
    "task": {
        "type": "RecaptchaV2TaskProxyless",
        "websiteURL": "https://target-site.com/login",
        "websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
        "isInvisible": true
    }
}

RecaptchaV2Task (With Your Proxy)

Use when a fixed IP address is required (e.g., for Google services).

json Copy
{
    "clientKey": "YOUR_API_KEY",
    "task": {
        "type": "RecaptchaV2Task",
        "websiteURL": "https://target-site.com/login",
        "websiteKey": "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u",
        "isInvisible": true,
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64)...",
        "cookies": "session=abc123",
        "proxyType": "http",
        "proxyAddress": "1.2.3.4",
        "proxyPort": 8080,
        "proxyLogin": "user",
        "proxyPassword": "pass"
    }
}

Bypass Algorithm for reCAPTCHA v2 Invisible

  1. Preparation: Obtain your API key from your 2Captcha dashboard
  2. Parameter Collection: Identify websiteKey, websiteURL, and the callback function
  3. Task Submission: Create a task via the createTask endpoint
  4. Wait for Solution: Poll getTaskResult at 5-second intervals
  5. Retrieve Token: Extract gRecaptchaResponse from the response
  6. Inject Token: Invoke the callback function with the obtained token

Code Example: Python + SeleniumBase

python Copy
import time
import requests
from seleniumbase import Driver

API_KEY = "YOUR_API_KEY"
SITE_KEY = "6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u"
PAGE_URL = "https://target-site.com/login"
CALLBACK_NAME = "onSubmit"  # callback function name from data-callback

def solve_recaptcha_invisible(sitekey, url, callback_name=None):
    """Submits a task to solve reCAPTCHA v2 Invisible"""
    
    payload = {
        "clientKey": API_KEY,
        "task": {
            "type": "RecaptchaV2TaskProxyless",
            "websiteURL": url,
            "websiteKey": sitekey,
            "isInvisible": True
        }
    }
    
    # Submit task
    response = requests.post(
        f"https://api.2captcha.com/createTask",
        json=payload
    )
    task_id = response.json()["taskId"]
    
    # Wait for solution
    while True:
        time.sleep(5)
        result = requests.post(
            f"https://api.2captcha.com/getTaskResult",
            json={"clientKey": API_KEY, "taskId": task_id}
        ).json()
        
        if result["status"] == "ready":
            return result["solution"]["gRecaptchaResponse"]
        elif result["errorId"] != 0:
            raise Exception(f"API Error: {result.get('errorDescription')}")

# Initialize browser in UC mode (Undetected Chromedriver)
driver = Driver(uc=True, headless=False)

try:
    # Navigate to target page
    driver.get(PAGE_URL)
    time.sleep(3)
    
    # Solve CAPTCHA
    token = solve_recaptcha_invisible(SITE_KEY, PAGE_URL)
    print(f"Token received: {token[:50]}...")
    
    # Inject token via callback function
    if CALLBACK_NAME:
        driver.execute_script(f"{CALLBACK_NAME}('{token}');")
    else:
        # Fallback: insert into hidden field and submit form
        driver.execute_script(
            f"document.getElementById('g-recaptcha-response').value = '{token}';"
        )
        driver.execute_script("document.querySelector('form').submit();")
    
    # Verify result
    time.sleep(5)
    if "success" in driver.page_source.lower():
        print("CAPTCHA successfully bypassed!")
    else:
        print("Token validation may have failed")
        
finally:
    driver.quit()

Working with Callback Functions

Why Callbacks Matter for the Invisible Version

With invisible reCAPTCHA v2, websites don't directly check the g-recaptcha-response field. Instead, they expect a specific JavaScript function to be called with the token. Simply injecting the token into a hidden field may not trigger the expected behavior.

How to Find and Invoke the Callback

  1. Via DevTools:

    • Open the Elements tab
    • Locate <div class="g-recaptcha">
    • Copy the data-callback attribute value
  2. Via Console:

    javascript Copy
    // List all reCAPTCHA callback functions on the page
    Object.values(___grecaptcha_cfg.clients).forEach(client => {
        const cb = client['C']?.['C']?.['callback'];
        if (cb) console.log('Callback:', cb.toString());
    });
  3. Invoke the Callback:

    javascript Copy
    // If callback is named "onSubmit"
    onSubmit('03AGdBq24PxK...');

If the Callback Isn't Globally Accessible

Sometimes the callback function is defined within a closure or iframe. In such cases:

python Copy
# Attempt to locate callback by scanning global functions
driver.execute_script("""
    for (let prop in window) {
        if (typeof window[prop] === 'function' && 
            (prop.toLowerCase().includes('recaptcha') || 
             prop.toLowerCase().includes('submit'))) {
            console.log('Possible callback:', prop);
        }
    }
""")

Error Handling

Common API Errors

Error Code Description Solution
ERROR_WRONG_USER_KEY Invalid API key Verify your key in the dashboard
ERROR_KEY_DOES_NOT_EXIST Key not found Ensure the key is active
ERROR_ZERO_BALANCE Insufficient funds Top up your account balance
ERROR_NO_SLOT_AVAILABLE No available workers Retry after 10–20 seconds
ERROR_CAPTCHA_UNSOLVABLE CAPTCHA cannot be solved Verify parameters; try with proxy
ERROR_WRONG_CAPTCHA_ID Invalid taskId Use the current taskId from createTask

Website-Side Errors

Symptom Possible Cause Solution
Token rejected Expired token (~2 min lifetime) Inject token immediately after retrieval
Site ignores token Callback not invoked Locate and call the data-callback function
IP blocking Suspicious activity from single address Use residential proxies
CAPTCHA fails to load Dynamic widget loading Add delay before collecting parameters

Best Practices

  1. Use UC Mode in Selenium: Undetected Chromedriver mode hides automation signals from Google detectors.

  2. Synchronize User-Agent: Pass the same User-Agent to the API request that your browser uses.

  3. Work with Sessions: Include cookies in your API task if the site requires authentication.

  4. Avoid Caching Parameters: Sitekeys and callbacks can change—extract them on each run.

  5. Handle Timeouts: Set a solution wait limit (typically 60–120 seconds).

  6. Use Residential Proxies: Improves solving success rates for Google services.

  7. Test with Google's Test Keys: Debug token injection logic without consuming balance.

Code Examples for Other Languages

Official 2Captcha libraries are available for:

Conclusion

Bypassing reCAPTCHA v2 Invisible boils down to three key steps: accurately identifying CAPTCHA parameters (especially the callback function), submitting the task to the API with isInvisible: true, and correctly injecting the returned token by invoking the callback function.

Key Takeaways:

  • Always set "isInvisible": true in your API request for the invisible version
  • Locate and invoke the function specified in data-callback—without this, the site won't accept the token
  • Use Google's test keys for debugging without consuming balance
  • Synchronize User-Agent and cookies between your browser session and API requests

Following these guidelines will enable you to reliably integrate reCAPTCHA v2 Invisible bypassing into your automation projects.