Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bypass Google reCaptcha Example
var reCaptcha = document.querySelector('.g-recaptcha');
var sitekey = reCaptcha.dataset.sitekey;
var API_KEY = <YOUR_2CAPTCHA_API_KEY>;
var byPassUrl = `https://2captcha.com/in.php?key=${API_KEY}&method=userrecaptcha&googlekey=${sitekey}&pageurl=https://www.google.com/recaptcha/api2/demo&json=1`;
fetch(byPassUrl).then(res => res.json()).then(res => {
// initiate bypass request
requestID = res.request;
// bypass request check params
var checkRequestCount = 0;
var checkRequestLimit = 20;
var checkRequestInterval = 5000;
const checkCaptchaResult = setInterval(() => {
checkRequestCount++;
var checkResultUrl = `https://2captcha.com/res.php?key=${API_KEY}&action=get&id=${requestID}&json=1`;
console.log('checking bypass status');
fetch(checkResultUrl).then(res => res.json()).then(res => {
if (res.status == 1) {
console.log('bypass sucessful', res.request);
// bypass successful
// next steps depends on how the implementing website or app handles the recaptcha success
// in this case, fill the g-recaptcha-response with the request token and attempt to submit the form
document.querySelector("#g-recaptcha-response").innerHTML = res.request;
// submit form by clicking button programmatically
document.querySelector("#recaptcha-demo-submit").click();
// in other cases, check for recaptcha success callback and invoke it
// for more info: https://2captcha.com/2captcha-api#callback
var reCaptchaCallback = reCaptcha.dataset.callback;
if (reCaptchaCallback) {
window[reCaptchaCallback]();
}
clearInterval(checkCaptchaResult);
}
if (res.request.startsWith('ERROR_')) {
// An error occured. Cancel request and retry bypass
clearInterval(checkCaptchaResult);
}
})
if (checkRequestCount == checkRequestLimit) {
// request limit reached. Cancel request and retry
clearInterval(checkCaptchaResult);
}
}, checkRequestInterval)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment