How to Bypass reCAPTCHA v2 Using Greasy Fork and 2Captcha

CAPTCHAFORUM

Administrator
1751884587753.png

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

As developers, we often face reCAPTCHA v2 challenges while building automation flows, scraping data, or running QA tests. These challenges are designed to prevent bots — but in legitimate contexts, bypassing them programmatically can be necessary.


This article outlines how to solve reCAPTCHA v2 automatically in the browser using a userscript hosted on Greasy Fork, executed through Tampermonkey (or Violentmonkey), and powered by the 2Captcha API. No backend code or complex automation frameworks are required.




✅ Prerequisites​


To implement this solution, you’ll need:
  • A registered account at 2Captcha and an active API key
  • A userscript manager like Tampermonkey (Chrome, Edge, Firefox) or Violentmonkey
  • A hosted or local Greasy Fork script
  • Basic understanding of JavaScript and browser DOM



🛠️ Concept Overview​


The script will:
  1. Detect the presence of reCAPTCHA v2 on the page
  2. Extract the sitekey from the DOM
  3. Submit a task to 2Captcha’s RecaptchaV2TaskProxyless API
  4. Poll the API until a solution token is ready
  5. Inject the solution token into the DOM
  6. Automatically submit the form (if available)

This approach works entirely in the client-side browser environment and requires no control over the target server.




🔧 Greasy Fork User Script for reCAPTCHA v2​

Code:
// ==UserScript==
// @name         reCAPTCHA Solver via 2Captcha
// @namespace    https://example.com/
// @version      1.0
// @description  Automatically solves reCAPTCHA v2 using the 2Captcha API
// @match        *://*/*
// @grant        none
// ==/UserScript==

(async function () {
  const API_KEY = 'YOUR_2CAPTCHA_API_KEY';  // Replace with your actual key
  const sleep = ms => new Promise(r => setTimeout(r, ms));

  const el = document.querySelector('.g-recaptcha[data-sitekey]');
  if (!el) return;

  const sitekey = el.getAttribute('data-sitekey');
  const url = window.location.href;

  const task = await fetch('https://api.2captcha.com/createTask', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      clientKey: API_KEY,
      task: {
        type: 'RecaptchaV2TaskProxyless',
        websiteKey: sitekey,
        websiteURL: url,
        isInvisible: false
      }
    })
  }).then(res => res.json());

  if (task.errorId) {
    console.error('2Captcha error:', task.errorDescription);
    return;
  }

  const taskId = task.taskId;
  let token;

  for (let i = 0; i < 20; i++) {
    await sleep(5000);
    const result = await fetch('https://api.2captcha.com/getTaskResult', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({ clientKey: API_KEY, taskId })
    }).then(res => res.json());

    if (result.status === 'ready') {
      token = result.solution.gRecaptchaResponse;
      break;
    }
  }

  if (!token) {
    console.error('Captcha timeout: No response from 2Captcha.');
    return;
  }

  let input = document.querySelector('[name="g-recaptcha-response"]');
  if (!input) {
    input = document.createElement('textarea');
    input.name = 'g-recaptcha-response';
    input.style.display = 'none';
    document.body.appendChild(input);
  }
  input.value = token;

  const form = el.closest('form');
  if (form) form.submit();
})();




📝 Script Hosting on Greasy Fork​


To use this script via Greasy Fork:
  1. Create an account at https://greasyfork.org/
  2. Go to "Submit a Script"
  3. Paste your full script
  4. Ensure the @match field is correctly scoped (e.g., *://*/* or a specific domain)
  5. Publish and test the script via Tampermonkey/Violentmonkey

Scripts hosted on Greasy Fork are easily installable and shareable, making this method suitable for small teams or internal automation.




📌 Notes & Recommendations​


  • The script assumes the reCAPTCHA is loaded and visible at runtime. Use MutationObserver if needed for dynamic content.
  • Ensure your 2Captcha account has a sufficient balance.
  • This method works reliably for reCAPTCHA v2 (visible) and can be adapted for invisible captchas as well.
  • Avoid abuse. Use this method only where it's permitted or within environments you control.



🧩 Future Extensions​


This script can be extended or adapted to:
  • Solve hCaptcha using HCaptchaTaskProxyless
  • Handle multiple captchas on the same page
  • Integrate with custom browser automation flows (e.g., Puppeteer, Playwright)
  • Add proxy-based solving (via 2Captcha with proxies)
By using Greasy Fork, Tampermonkey, and 2Captcha’s API, you can create client-side automation scripts to handle reCAPTCHA challenges efficiently. This approach is ideal for testers, developers, or data engineers working in environments where full browser automation is overkill.

If you require enterprise-grade solutions, deeper integration, or support for other captcha types — consider building a more modular script architecture or integrating with server-side logic where appropriate.