CAPTCHAFORUM
Administrator
https://2captcha.com/h/how-to-bypass-captcha-using-tampermonkey
Before proceeding, ensure the following requirements are met:
- A Chromium-based or Firefox browser with the Tampermonkey extension installed
- An active 2Captcha account with sufficient balance
- A valid 2Captcha API key
- Basic familiarity with JavaScript and browser developer tools (DevTools)
Overview
This implementation enables the automatic solving of reCAPTCHA v2 challenges (checkbox or image-based) by detecting the sitekey, requesting a token via the 2Captcha API, and injecting the token back into the page to simulate human verification.Implementation Steps
- Install the Tampermonkey browser extension from tampermonkey.net.
- Open the Tampermonkey dashboard and select "Create a new script".
- Delete the default template code and replace it with the script below.
- Replace 'YOUR_2CAPTCHA_API_KEY' with your actual API key.
- Save the script and reload the target website containing reCAPTCHA v2.
Tampermonkey Userscript
Code:
// ==UserScript==
// @name Auto reCAPTCHA v2 Solver (2Captcha)
// @namespace https://your-captcha-solution.com/
// @version 1.0
// @description Automates solving of reCAPTCHA v2 using 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 = location.href;
const createTask = async () => {
const response = 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 response.json();
if (data.errorId !== 0) throw new Error(data.errorDescription);
return data.taskId;
};
const getToken = async (taskId) => {
for (let attempt = 0; attempt < 24; attempt++) {
await sleep(5000);
const response = await fetch('https://api.2captcha.com/getTaskResult', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ clientKey: API_KEY, taskId })
});
const data = await response.json();
if (data.status === 'ready') return data.solution.gRecaptchaResponse;
}
throw new Error('Captcha solving timeout');
};
const token = await getToken(await createTask());
let responseField = document.querySelector('[name="g-recaptcha-response"]');
if (!responseField) {
responseField = document.createElement('textarea');
responseField.name = 'g-recaptcha-response';
responseField.style.display = 'none';
document.body.appendChild(responseField);
}
responseField.value = token;
const form = recaptcha.closest('form');
if (form) form.submit();
})();
Troubleshooting & Recommendations
Ensure captcha visibility: The reCAPTCHA widget must be fully loaded in the DOM before the script executes. Use a MutationObserver if dynamic content is loaded via JavaScript.
Form behavior: Some websites may require manual user interaction (e.g. clicking a button) after token injection to trigger form submission.
Check your API key and balance: Invalid API keys or empty account balances will result in task creation failures.
Inspect console logs: Use browser DevTools to monitor for network or JavaScript errors during execution.
Usage limits: Avoid exceeding the 2Captcha API rate limits to prevent temporary account throttling.
This Tampermonkey script, combined with the 2Captcha API, offers a client-side method to automate reCAPTCHA v2 solving directly in the browser. It is suitable for controlled environments such as QA automation, browser scripting, and legal data extraction from public interfaces. Ensure all usage complies with the terms of service of the websites you interact with.
For support with invisible reCAPTCHA, Cloudflare Turnstile, or proxy-enabled scenarios, contact your automation provider or consult the 2Captcha documentation.