Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created June 15, 2022 23:11
Show Gist options
  • Select an option

  • Save Octagon-simon/2dac24eed3189b090ccce2dcb896e9a6 to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/2dac24eed3189b090ccce2dcb896e9a6 to your computer and use it in GitHub Desktop.
function solveCaptcha(siteKey, pageUrl){
const apiKey = "YOUR_API_KEY";
//make a GET request to 2captcha
fetch(`https://2captcha.com/in.php?key=${apiKey}
&method=userrecaptcha&googlekey=${siteKey}&pageurl=${pageUrl}&json=1`)
.then(response => response.json())
.then(data => {
//check if there's an error
if(!data.status){
//print out error
logErr('Error:', (data.error_text !== undefined) ? data.error_text : data.request);
}else{
setTimeout(function(captchaId = data.request){
//make another call with the ID to get the captcha's status
fetch(`https://2captcha.com/res.php?key=${apiKey}&action=get&id=${captchaId}&json=1`)
.then(response => response.json())
.then(data => {
if(!data.status){
//print out error
logErr('Error:', (data.error_text !== undefined) ? data.error_text : data.request);
}else{
//do something else with the data
}
})
.catch(error => {
logErr('Error:', error);
});
}, 20000);
}
})
.catch(error => {
logErr('Error:', error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment