Reference

CAPTCHA Token Injection Methods Reference

Solving a CAPTCHA with CaptchaAI gives you a token or cookie. The next step — injecting that result into the page so the form submission works — depends on the CAPTCHA type and your automation framework. This reference covers every injection method.


Injection by CAPTCHA type

CAPTCHA type What you get Where to inject Method
reCAPTCHA v2 Token string g-recaptcha-response textarea Hidden field
reCAPTCHA v2 Invisible Token string g-recaptcha-response textarea + callback Hidden field + JS
reCAPTCHA v3 Token string g-recaptcha-response textarea + callback Hidden field + JS
reCAPTCHA Enterprise Token string g-recaptcha-response textarea Hidden field
Cloudflare Turnstile Token string cf-turnstile-response field Hidden field
Cloudflare Challenge cf_clearance cookie Session cookies Cookie jar

reCAPTCHA v2 — Standard injection

reCAPTCHA v2 creates a hidden textarea named g-recaptcha-response. Set its value to the solved token.

JavaScript (browser console / Selenium execute_script)

// Set the token
document.getElementById("g-recaptcha-response").value = "SOLVED_TOKEN";

// Make it visible if needed (some sites validate display)
document.getElementById("g-recaptcha-response").style.display = "block";

Selenium (Python)

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://example.com/login")

# After solving with CaptchaAI
token = "SOLVED_TOKEN"

# Inject the token
driver.execute_script(f'''
    document.getElementById("g-recaptcha-response").value = "{token}";
''')

# Submit the form
driver.find_element("css selector", "form").submit()

Puppeteer (Node.js)

const puppeteer = require("puppeteer");

const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://example.com/login");

const token = "SOLVED_TOKEN";

await page.evaluate((t) => {
  document.getElementById("g-recaptcha-response").value = t;
}, token);

await page.click('button[type="submit"]');

HTTP request (no browser)

import requests

token = "SOLVED_TOKEN"

resp = requests.post("https://example.com/login", data={
    "username": "user",
    "password": "pass",
    "g-recaptcha-response": token
})

reCAPTCHA v2 Invisible / v3 — Callback injection

Invisible reCAPTCHA and v3 often use a JavaScript callback. Setting the textarea is not enough — you must trigger the callback function.

Finding the callback

// Check for data-callback attribute
document.querySelector("[data-callback]")?.getAttribute("data-callback");

// Or search for the callback in reCAPTCHA's internal state
___grecaptcha_cfg.clients[0]?.aa?.l?.callback;

Injecting with callback

// Set the token
document.getElementById("g-recaptcha-response").value = "SOLVED_TOKEN";

// Trigger the callback
// Method 1: If callback name is known
onSubmit("SOLVED_TOKEN");

// Method 2: Find and call the callback automatically
const callback = document.querySelector("[data-callback]")?.getAttribute("data-callback");
if (callback && window[callback]) {
    window[callback]("SOLVED_TOKEN");
}

Selenium (Python) with callback

token = "SOLVED_TOKEN"

driver.execute_script(f'''
    document.getElementById("g-recaptcha-response").value = "{token}";

    // Try to find and trigger callback
    var callback = document.querySelector("[data-callback]");
    if (callback) {{
        var fn = callback.getAttribute("data-callback");
        if (window[fn]) window[fn]("{token}");
    }}
''')

reCAPTCHA — Multiple widgets on one page

Some pages have multiple reCAPTCHA widgets. Each has its own g-recaptcha-response textarea.

// Find all response textareas
const textareas = document.querySelectorAll("[id^='g-recaptcha-response']");
console.log(`Found ${textareas.length} reCAPTCHA widgets`);

// Set the token on the correct widget (usually index 0)
textareas[0].value = "SOLVED_TOKEN";

Or find by parent form:

// Find the textarea inside a specific form
const form = document.querySelector("#login-form");
const textarea = form.querySelector("[name='g-recaptcha-response']");
textarea.value = "SOLVED_TOKEN";

Cloudflare Turnstile — Token injection

Turnstile uses cf-turnstile-response as the field name.

JavaScript

// Set Turnstile token
const input = document.querySelector("[name='cf-turnstile-response']");
if (input) {
    input.value = "SOLVED_TOKEN";
}

Selenium (Python)

token = "SOLVED_TOKEN"

driver.execute_script(f'''
    var input = document.querySelector("[name='cf-turnstile-response']");
    if (input) input.value = "{token}";
''')
driver.find_element("css selector", "form").submit()

HTTP request (no browser)

resp = requests.post("https://example.com/login", data={
    "username": "user",
    "password": "pass",
    "cf-turnstile-response": token
})

Cloudflare Challenge returns a cf_clearance cookie, not a token. Set it in your session cookies.

requests (Python)

import requests

session = requests.Session()

# Set the cookie
session.cookies.set("cf_clearance", "COOKIE_VALUE", domain=".example.com")

# MUST use same User-Agent and proxy as the solve
session.headers["User-Agent"] = "Mozilla/5.0 ..."
session.proxies = {"http": "http://user:pass@host:port", "https": "http://user:pass@host:port"}

# Now access the site
resp = session.get("https://example.com")

Selenium (Python)

driver.get("https://example.com")

# Add the cookie
driver.add_cookie({
    "name": "cf_clearance",
    "value": "COOKIE_VALUE",
    "domain": ".example.com",
    "path": "/"
})

# Reload the page — should bypass the challenge
driver.refresh()

Common injection mistakes

Mistake Result Fix
Wrong field name (g-recaptcha-response for Turnstile) Token ignored Use cf-turnstile-response for Turnstile
Token injected but form not submitted Nothing happens Submit the form after injection
Invisible reCAPTCHA without callback Token set but not processed Find and trigger the callback function
Cookie domain without dot prefix Cookie not sent for subdomains Use .example.com with dot
Delay between injection and submission Token expires Submit immediately after injection

Timing guidelines

CAPTCHA type Inject and submit within
reCAPTCHA v2 120 seconds
reCAPTCHA v3 120 seconds
Cloudflare Turnstile 300 seconds (5 minutes)
Cloudflare Challenge cookie 15–30 minutes

FAQ

How do I know which field name to use?

Inspect the form HTML. Look for hidden inputs or textareas with names containing recaptcha, turnstile, or captcha. The standard names are g-recaptcha-response and cf-turnstile-response.

Can I inject tokens without a browser?

Yes, for HTTP-based forms. Send the token as a POST field in your requests call. No browser needed. Browser-only injection is required for JavaScript-heavy SPAs where form submission happens via JavaScript.

Why does my token work with Selenium but not with requests?

The site may require additional cookies or headers that Selenium's session has from loading the page. Use session.get() to load the page first, then submit the token.


Get your CaptchaAI API key

Inject solved CAPTCHA tokens reliably at captchaai.com.


Discussions (0)

No comments yet.

Related Posts

Use Cases Multi-Step Checkout Automation with CAPTCHA Solving
Automate multi-step e-commerce checkout flows that include CAPTCHA challenges at cart, payment, or confirmation stages using Captcha AI.

Automate multi-step e-commerce checkout flows that include CAPTCHA challenges at cart, payment, or confirmatio...

Python Automation Cloudflare Turnstile
Mar 21, 2026
Comparisons Headless vs Headed Chrome for CAPTCHA Solving
Compare headless and headed Chrome for CAPTCHA automation — detection differences, performance trade-offs, and when to use each mode with Captcha AI.

Compare headless and headed Chrome for CAPTCHA automation — detection differences, performance trade-offs, and...

Python Automation Cloudflare Turnstile
Mar 09, 2026
API Tutorials Proxy Authentication Methods for CaptchaAI API
Configure proxy authentication with Captcha AI — IP whitelisting, username/password, SOCKS 5, and passing proxies directly to the solving API.

Configure proxy authentication with Captcha AI — IP whitelisting, username/password, SOCKS 5, and passing prox...

Python Automation Cloudflare Turnstile
Mar 09, 2026
API Tutorials CaptchaAI API Latency Optimization: Faster Solves
Reduce CAPTCHA solve latency with Captcha AI by optimizing poll intervals, connection pooling, prefetching, and proxy selection.

Reduce CAPTCHA solve latency with Captcha AI by optimizing poll intervals, connection pooling, prefetching, an...

Python Automation Cloudflare Turnstile
Feb 27, 2026
Use Cases CAPTCHA Solving in Ticket Purchase Automation
How to handle CAPTCHAs on ticketing platforms Ticketmaster, AXS, and event sites using Captcha AI for automated purchasing workflows.

How to handle CAPTCHAs on ticketing platforms Ticketmaster, AXS, and event sites using Captcha AI for automate...

Python Automation Cloudflare Turnstile
Feb 25, 2026
Reference Browser Session Persistence for CAPTCHA Workflows
Manage browser sessions, cookies, and storage across CAPTCHA-solving runs to reduce repeat challenges and maintain authenticated state.

Manage browser sessions, cookies, and storage across CAPTCHA-solving runs to reduce repeat challenges and main...

Python Automation Cloudflare Turnstile
Feb 24, 2026
Tutorials Caching CAPTCHA Tokens for Reuse
Cache and reuse CAPTCHA tokens with Captcha AI to reduce API calls and costs.

Cache and reuse CAPTCHA tokens with Captcha AI to reduce API calls and costs. Covers token lifetimes, cache st...

Python Automation Cloudflare Turnstile
Feb 15, 2026
Use Cases CAPTCHA Handling for Sneaker Bot Automation
How sneaker bots handle CAPTCHAs on Nike, Adidas, Footlocker, and other release sites using Captcha AI for fast checkout.

How sneaker bots handle CAPTCHAs on Nike, Adidas, Footlocker, and other release sites using Captcha AI for fas...

Python Automation Cloudflare Turnstile
Feb 04, 2026
API Tutorials Building a Python Wrapper Library for CaptchaAI API
Build a reusable Python wrapper library for the Captcha AI API with type hints, retry logic, context managers, and support for CAPTCHA types.

Build a reusable Python wrapper library for the Captcha AI API with type hints, retry logic, context managers,...

Python Automation Cloudflare Turnstile
Jan 31, 2026
Reference Chrome DevTools Protocol + CaptchaAI: Low-Level CAPTCHA Automation
Use Chrome Dev Tools Protocol (CDP) directly for CAPTCHA automation with Captcha AI — handleing Web Driver detection, intercepting network requests, and injecti...

Use Chrome Dev Tools Protocol (CDP) directly for CAPTCHA automation with Captcha AI — handleing Web Driver det...

Python Automation Cloudflare Turnstile
Jan 12, 2026
Reference CAPTCHA Solving Performance by Region: Latency Analysis
Analyze how geographic region affects Captcha AI solve times — network latency, proxy location, and optimization strategies for global deployments.

Analyze how geographic region affects Captcha AI solve times — network latency, proxy location, and optimizati...

Python Automation All CAPTCHA Types
Apr 05, 2026
Reference CAPTCHA Types Comparison Matrix 2025
Complete side-by-side comparison of every major CAPTCHA type in 2025 — re CAPTCHA, Turnstile, Gee Test, BLS, h Captcha, and image CAPTCHAs.

Complete side-by-side comparison of every major CAPTCHA type in 2025 — re CAPTCHA, Turnstile, Gee Test, BLS, h...

Web Scraping All CAPTCHA Types
Mar 31, 2026
Reference Cost Comparison Calculator: CaptchaAI vs Top 5 Competitors
Compare CAPTCHA solving costs across Captcha AI and the top 5 competitors — pricing tables, cost-per-solve calculations, and a usage-based comparison framework.

Compare CAPTCHA solving costs across Captcha AI and the top 5 competitors — pricing tables, cost-per-solve cal...

All CAPTCHA Types Migration
Mar 17, 2026