Captcha bypass tutorials

How to bypass captcha using Greasy Fork

How to bypass captcha using Greasy Fork

If you’re dealing with reCAPTCHA during testing or scraping, you don’t need browser automation or backend code. You can inject a userscript directly into the page and let 2Captcha do the solving.

This article about creating your scripts that run in the browser using Tampermonkey or Greasy Fork. We’ll show examples for both reCAPTCHA and hCaptcha.

What you’ll need

  • A 2Captcha account and your API key
  • The Tampermonkey extension (or Violentmonkey)
  • A GreasyFork script (hosted or local)
  • Basic JavaScript knowledge

reCAPTCHA solver Greasy Fork

reCAPTCHA v2 (the "I'm not a robot" checkbox or image challenge) can be solved using the RecaptchaV2TaskProxyless task type.

This user script:

  • Detects the data-sitekey
  • Sends a task to 2Captcha
  • Polls for the solution
  • Injects the token into the page
  • Submits the form
// ==UserScript==
// @name         reCAPTCHA Solver GreasyFork
// @namespace    https://example.com/
// @version      1.0
// @description  Solves reCAPTCHA v2 using 2Captcha API
// @match        *://*/*
// @grant        none
// ==/UserScript==

(async function () {
  const API_KEY = 'YOUR_2CAPTCHA_API_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) throw new Error(task.errorDescription);
  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) throw new Error('Timeout waiting for captcha result');

  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();
})();

If you want to reuse this with actual GreasyFork hosting, just upload the script and make sure your @match is scoped correctly. These are generic and work on any page that has a supported captcha.

References