How to bypass CAPTCHA?
Tags: javascript, beginners, webdev
Published: 2022-02-07 12:01:17

Nowadays, almost every time we send a form, we are forced to solve a minor challenge. For many, this is a very annoying task. Well, here is the solution for those of us who hate saving CAPTCHA.

## What is CAPTCHA, and how does it work?

CAPTCHA (Completely Automated Public Turing Test to Tell Computers and Humans Apart) is a challenge that prevents computers from submitting forms that are not planned for them. 

CAPTCHA tests can only be solved by humans, in theory. CAPTCHAs are becoming more and more complex as computers become more powerful and capable of recognizing characters (unfortunately).

**What are CAPTCHA's weaknesses?**


- It's often impossible to figure out what's on the Captcha test
- Some CAPTCHAs aren't compatible with all browsers
- Tests make website visitors feel uncomfortable

## [2Captcha](https://2captcha.com)
[2Captcha](https://2captcha.com) is an image and CAPTCHA recognition service. 2Captcha's main purpose is for workers to solve CAPTCHA fast and correctly.
[2Captcha](https://2captcha.com) allows you to solve almost all CAPTCHAs currently in use.

![2Captcha main webpage](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v1t2ajc0gr2ss5cynshy.png)

### 2Captcha Advantages

- High level of accuracy
- CAPTCHA resolution speed—around 12 seconds
- Numerous APIs and SDKs for practically all programming languages
- Nearly 100% rescue assurance

# How to use JavaScript to solve the CAPTCHA test?

Before we begin, we must first obtain the API key. It's available through the 2Captcha control panel. We create a user account if we haven't already done so before receiving the API key.

![2Captcha dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atjgvorps1iqpi2e2j0y.png)
 

Now we'll make a basic communication form. The user must complete the CAPTCHA test generated by the backend before submitting the message.

[This link](https://drive.google.com/file/d/1Fg0aU1FIQdeD_poCRy4rLMVUnu6k2dtu/view?usp=sharing) will take you to the complete source code. 

**How our site works**

We make a request to 2Captcha to save CAPTCHA built with our backend when we push the solution button.

![Our example page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ki9qt8fm13nsv8loiiv6.png)
 

We won't be using the CAPTCHA auto-solve button in real life, of course. The goal of this example is to demonstrate how 2Captcha solves CAPTCHA.

Our JavaScript code

```js
import Captcha from '<https://cdn.skypack.dev/2captcha>';
const solver = new Captcha.Solver("<YOUR API KEY>");

function getBase64Image(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img, 0, 0);
    var dataURL = canvas.toDataURL("image/png");
    return dataURL.replace(/^data:image\\/(png|jpg);base64,/, "");
}

var refreshButton = document.getElementById("refresh-captcha");
var captchaImage = document.getElementById("image-captcha");
var solveButton = document.getElementById("solve");
var token = document.getElementById("token");

refreshButton.onclick = function(event) {
    event.preventDefault();
    captchaImage.src = 'captcha/image.php?' + Date.now();
}

solveButton.onclick = function(event) {
    event.preventDefault();
    solver.imageCaptcha(getBase64Image(captchaImage), "base64").then((res) => {
        console.log(res);
        token.value = res['data'];
    });
}
```

The code makes use of the JavaScript package 2Captcha, which handles all aspects of sending and receiving the 2Captcha API answers. The library's documentation [may be found here](https://github.com/furry/2captcha#readme).

CAPTCHA solving demonstration

![demo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k8wyy63j80344cjjyejt.gif)
 

## Bonus 🤑
[In one of my previous posts](https://blog.thepatik.eu.org/how-to-make-money-as-a-programmer-in-a-simple-way), I looked at easy ways for us to make money. We may now add another choice. This one is accomplished by saving CAPTCHA. Starting at $0.50 per hour, you can make (maybe more). Before you begin solving CAPTCHAs, you must first complete a 10-minute training session about how to solve a CAPTCHA. This is to avoid numerous CAPTCHA being lost.

## Final Thoughts

2Captcha helps us to solve CAPTCHA for us automatically.
If we don't want to mess around with the API, there is a free Chrome plug-in that will solve all CAPTCHA checks for us without any further setups. You can download the plug-in at the following link: [2Captcha Solver](https://chrome.google.com/webstore/detail/2captcha-solver/ifibfemgeogfhoebkmokieepdoobkbpo)

**Let’s connect**
- [Twitter](https://twitter.com/Patik123_)
- [GitHub](https://github.com/patik123)
- [PolyWork](https://www.polywork.com/patik123)

<a href="https://www.buymeacoffee.com/patik123" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 30px !important;width: 200px !important;" ></a>