How to bypass captcha using Tampermonkey
In this article, you’ll learn how to automatically solve captchas directly in your browser using Tampermonkey and the captcha solver API. This is especially useful for testing flows, automating submissions, or scraping data from websites that use reCAPTCHA for bot protection.
You’ll get step-by-step instructions and working user scripts for both reCAPTCHA v2.
What you’ll need
- The Tampermonkey browser extension
- A 2captcha.com account and API key
- Basic familiarity with JavaScript and browser developer tools
Setting up Tampermonkey
- Go to tampermonkey.net and install the extension for your browser
- Open the Tampermonkey dashboard
- Click “Create a new script”
- Replace the template with the script for your captcha type (see below)
How to bypass reCAPTCHA v2 with Tampermonkey
reCAPTCHA v2 is typically shown as a checkbox that says “I’m not a robot.” Sometimes it also involves image selection challenges. You can identify it by looking for a <div class="g-recaptcha" data-sitekey="...">
in the HTML.
Here’s a user script that:
- Detects the sitekey
- Submits the solving task to 2Captcha
- Waits for the solution
- Injects the response token
- Submits the form automatically if possible
reCAPTCHA solver script
// ==UserScript==
// @name Auto reCAPTCHA v2 Solver with 2Captcha
// @namespace https://your-captcha-service.com/
// @version 1.0
// @description Automatically solves reCAPTCHA v2 using 2Captcha API v2
// @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,
isInvisible: false
}
})
});
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 not solved in time');
};
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();
})();
Tips and troubleshooting
- Make sure the captcha is fully loaded before the script executes. If needed, add a delay or use a MutationObserver to wait for DOM changes.
- Use a real API key from your 2Captcha account and make sure your balance is not zero.
- Check browser console logs for errors or failed requests.
- Some sites may require simulating a user action (like a mouse click) to trigger form submission after the token is injected.
Summary
With Tampermonkey and the API, you can automate captcha-solving tasks directly in your browser without relying on back-end code. These scripts can save hours of manual work when dealing with protected forms or client-side flows.
Want to support invisible captchas, Cloudflare Turnstile, or add proxy support? Let us know — we’ll provide dedicated scripts and examples.