How to Bypass reCAPTCHA v2 Using Tampermonkey and 2Captcha API

 

https://2captcha.com/h/how-to-bypass-captcha-using-tampermonkey

As a technical specialist, I often deal with websites that use reCAPTCHA v2 to block bots and automation. While this is understandable from a security perspective, there are legitimate cases — such as automated testing, data scraping, or form submissions — where bypassing captchas in a controlled environment becomes necessary.

In this article, I’ll walk you through how to automate solving reCAPTCHA v2 using the Tampermonkey browser extension and the 2Captcha API, with a fully functional userscript written in JavaScript.


Prerequisites

Before we start, ensure you have the following:

  • Tampermonkey installed in your browser (Download here)

  • ✅ An active 2Captcha.com account and API key

  • ✅ Basic knowledge of JavaScript and how to inspect elements in the browser


Installing and Setting Up Tampermonkey

  1. Go to tampermonkey.net and install the extension for your preferred browser.

  2. Click the Tampermonkey icon and open the Dashboard.

  3. Click “Create a new script”.

  4. Paste the userscript provided below.

  5. Replace YOUR_2CAPTCHA_API_KEY with your actual API key from 2Captcha.

  6. Save and reload any target page containing reCAPTCHA v2.


Understanding the Script

This script performs the following steps:

  • Detects the presence of reCAPTCHA v2

  • Extracts the sitekey value from the DOM

  • Submits a task to 2Captcha to solve the challenge

  • Waits for the solution using polling

  • Injects the response token into the page

  • Optionally submits the form automatically


reCAPTCHA v2 Solver Script

// ==UserScript== // @name reCAPTCHA v2 Auto-Solver with 2Captcha // @namespace https://your-captcha-service.com/ // @version 1.0 // @description Solves reCAPTCHA v2 via 2Captcha API // @match *://*/* // @grant none // ==/UserScript== (async function () { const API_KEY = 'YOUR_2CAPTCHA_API_KEY'; const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); const recaptcha = document.querySelector('.g-recaptcha[data-sitekey]'); if (!recaptcha) return; const sitekey = recaptcha.getAttribute('data-sitekey'); const pageUrl = window.location.href; const createTask = async () => { const res = await fetch('https://api.2captcha.com/createTask', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientKey: API_KEY, task: { type: 'RecaptchaV2TaskProxyless', websiteURL: pageUrl, websiteKey: sitekey } }) }); const data = await res.json(); if (data.errorId !== 0) throw new Error(data.errorDescription); return data.taskId; }; const getToken = async (taskId) => { for (let i = 0; i < 24; i++) { await sleep(5000); const res = await fetch('https://api.2captcha.com/getTaskResult', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ clientKey: API_KEY, taskId }) }); const data = await res.json(); if (data.status === 'ready') return data.solution.gRecaptchaResponse; } throw new Error('Timeout: Captcha solving exceeded expected duration.'); }; const token = await getToken(await createTask()); let el = document.querySelector('[name="g-recaptcha-response"]'); if (!el) { el = document.createElement('textarea'); el.name = 'g-recaptcha-response'; el.style.display = 'none'; document.body.appendChild(el); } el.value = token; const form = recaptcha.closest('form'); if (form) form.submit(); })();

Technical Considerations

  • Captcha Load Timing: Ensure the script runs only after the captcha is rendered. If needed, use MutationObserver or explicit delays.

  • 2Captcha Account: Your account must have a positive balance. A zero balance will result in task errors.

  • Error Handling: Use your browser console to monitor logs or troubleshoot any failures.

  • User Events: Some forms may require simulating human actions (e.g., clicking) to allow form submission post-injection.


Summary

This Tampermonkey-based solution allows seamless client-side automation of reCAPTCHA v2 challenges using 2Captcha’s proxyless API. It’s ideal for developers automating workflows or running repetitive tests without backend integration.


What’s Next?

We’re actively working on support scripts for:

  • reCAPTCHA v3

  • Invisible captchas

  • Cloudflare Turnstile

  • Proxy-based solving (if needed for stricter environments)

If you need help adapting this to your specific use case or want to request additional captcha support — feel free to reach out.

Комментарии

Популярные сообщения из этого блога

Roblox captcha solver

Bypassing Cloudflare Challenge with Puppeteer and 2Captcha