Skip to content

Commit

Permalink
Merge pull request #18 from 2captcha/RC-2942
Browse files Browse the repository at this point in the history
RC-2942 Add methods
  • Loading branch information
dzmitry-duboyski authored Oct 31, 2024
2 parents 6c3631f + 5a2ec5c commit 9dfe287
Show file tree
Hide file tree
Showing 19 changed files with 918 additions and 79 deletions.
191 changes: 183 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

# JavaScript module for 2Captcha API (captcha solver)

The easiest way to quickly integrate the [2Captcha](https://2captcha.com/) captcha-solving service into your code and automate the solving of any type of captcha.
Examples of API requests for different captcha types are available on the [JavaScript captcha solver](https://2captcha.com/lang/javascript) page.
The easiest way to quickly integrate the [2Captcha] captcha-solving service into your code and automate the solving of any type of captcha.
Examples of API requests for different captcha types are available on the [JavaScript captcha solver] page.

- [JavaScript module for 2Captcha API (captcha solver)](#javascript-module-for-2captcha-api-captcha-solver)
- [Installation](#installation)
- [Configuration](#configuration)
- [TwoCaptcha instance options](#twocaptcha-instance-options)
- [Solve captcha](#solve-captcha)
- [Image captchas](#image-captcha)
- [Image Captcha](#image-captcha)
- [reCAPTCHA v2](#recaptcha-v2)
- [reCAPTCHA v3](#recaptcha-v3)
- [hCaptcha](#hcaptcha)
Expand All @@ -36,16 +36,26 @@ Examples of API requests for different captcha types are available on the [JavaS
- [Friendly Captcha](#friendly-captcha)
- [Bounding Box Method](#bounding-box-method)
- [Grid](#grid)
- [Text Captcha](#text-captcha)
- [Canvas](#canvas)
- [Rotate](#rotate)
- [KeyCaptcha](#keycaptcha)
- [Cutcaptcha](#cutcaptcha)
- [Tencent](#tencent)
- [atbCAPTCHA](#atbcaptcha)
- [Audio Captcha](#audio-captcha)
- [Other methods](#other-methods)
- [goodReport](#goodreport)
- [badReport](#badreport)
- [balance](#balance)
- [Proxies](#proxies)
- [Examples](#examples)
- [Examples using Puppeteer](#examples-using-puppeteer)
- [Useful articles](#useful-articles)
- [Useful articles](#useful-articles)
- [Get in touch](#get-in-touch)
- [Join the team 👪](#join-the-team-)
- [License](#license)
- [Graphics and Trademarks](#graphics-and-trademarks)


## Installation
Expand Down Expand Up @@ -109,7 +119,6 @@ Below you can find basic examples for every captcha type, check out the code bel
To bypass a normal captcha (distorted text on an image) use the following method. This method can also be used to recognize any text in an image.

```js
// Read from a file as base64 text
const imageBase64 = fs.readFileSync("./examples/media/imageCaptcha_6e584.png", "base64")

solver.imageCaptcha({
Expand All @@ -119,7 +128,6 @@ solver.imageCaptcha({
max_len: 5
})
.then((res) => {
// Logs the image text
console.log(res);
})
.catch((err) => {
Expand Down Expand Up @@ -498,6 +506,164 @@ solver.grid({
})
```

### Text Captcha

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_text_captcha)</sup>

This method can be used to bypass a captcha that requires answering a question provided in clear text.

```js
solver.textCaptcha({
textcaptcha: "If tomorrow is Saturday, what day is today?",
lang: 'en'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### Canvas

<sup>[API method description.](https://2captcha.com/2captcha-api#canvas)</sup>

The canvas method can be used when you need to draw a line around an object on an image. Returns a set of points' coordinates to draw a polygon.

```js
solver.canvas({
body: 'iVBORw0KGgoAAAANSgAAAcIA...',
imginstructions: '/9j/4AAQSkZJRgABAQEA...',
textinstructions: 'Highlight the red CIRCLE'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### Rotate

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_rotatecaptcha)</sup>

This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha. Returns the rotation angle.

```js
solver.rotate({
body: imageBase64,
textinstructions: "Rotate the object to the correct position"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### KeyCaptcha

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_keycaptcha)</sup>

Token-based method to solve KeyCaptcha.

```js
solver.keyCaptcha({
pageurl: "https://2captcha.com/demo/keycaptcha",
userId: '184015',
sessionId: '0917788cad24ad3a69813c4fcd556061',
webServerSign: '02f7f9669f1269595c4c69bcd4a3c52e',
webServerSign2: 'd888700f6f324ec0f32b44c32c50bde1'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### Cutcaptcha

<sup>[API method description.](https://2captcha.com/2captcha-api#cutcaptcha)</sup>

Use this method to solve Cutcaptcha. Returns the response in JSON.

```js
solver.cutCaptcha({
pageurl: "https://mysite.com/page/with/cutcaptcha",
misery_key: "098e6a849af406142e3150dbf4e6d0538db2b51f",
api_key: "SAs61IAI",
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### Tencent

<sup>[API method description.](https://2captcha.com/2captcha-api#tencent)</sup>

Use this method to solve Tencent captcha. Returns the response in JSON.

```js
solver.tencent({
pageurl: "https://mysite.com/page/with/tencent",
appId: "189956587"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### atbCAPTCHA

<sup>[API method description.](https://2captcha.com/2captcha-api#atb-captcha)</sup>

Use this method to solve atbCAPTCHA challenge. Returns a token to bypass the captcha.

```js
solver.atbCaptcha({
pageurl: "https://mysite.com/page/with/atbCAPTCHA",
appId: "af25e409b33d722a95e56a230ff8771c",
apiServer: "https://cap.aisecurius.com"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### Audio Captcha

<sup>[API method description.](https://2captcha.com/2captcha-api#audio-recognition)</sup>

Use the following method to bypass an audio captcha (`mp3` formats only). You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".

```js
solver.audio({
body: "SUQzBAAAAAAAHFRTU0UAAAA...",
lang: "en"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

## Other methods

### goodReport
Expand Down Expand Up @@ -558,15 +724,14 @@ At the moment we have implemented examples of bypassing Cloudflare Challenge pag
Links:
- [Cloudflare Bypassing Demo using Puppeteer](https://github.com/2captcha/cloudflare-demo)
- [Solving reCAPTCHA V2 using Puppeteer and clicks](https://github.com/2captcha/puppeteer-recaptcha-solver-using-clicks)
- [Custom Slider Captcha Demo](https://github.com/2captcha/custom-slider-demo)


## Useful articles
* [How to bypass captcha using JavaScript](https://2captcha.com/blog/how-to-use-javascript-to-bypass-captcha#how-to-solve-and-bypass-a-captcha-with-javascript-using-npm-package-2captchacaptcha-solver)
* [Bypassing Cloudflare Challenge with Puppeteer and 2Captcha](https://2captcha.com/blog/bypassing-cloudflare-challenge-with-puppeteer-and-2captcha)
* [How to bypass Geetest v4 CAPTCHA](https://2captcha.com/blog/geetest-v4-support)
* [Automatic reCAPTCHA V3 resolution - a tutorial for developers and customers](https://2captcha.com/blog/recaptcha-v3-automatic-resolution)
* [Custom Slider Captcha Demo](https://github.com/2captcha/custom-slider-demo)
* [Cloudflare Challenge page bypass code example](https://github.com/2captcha/cloudflare-demo)

## Get in touch

Expand All @@ -579,7 +744,17 @@ There are many ways to contribute, of which development is only one! Find your n

<a href="mailto:[email protected]"><img src="https://github.com/user-attachments/assets/36d23ef5-7866-4841-8e17-261cc8a4e033" width="80" height="30"></a>

## License

The code in this repository is licensed under the MIT License. See the [LICENSE](./LICENSE) file for more details.

### Graphics and Trademarks

The graphics and trademarks included in this repository are not covered by the MIT License. Please contact <a href="mailto:[email protected]">support</a> for permissions regarding the use of these materials.

<!-- Shared links -->
[2Captcha]: https://2captcha.com/
[JavaScript captcha solver]: https://2captcha.com/lang/javascript
[post options]: https://2captcha.com/2captcha-api#normal_post
[list of supported languages]: https://2captcha.com/2captcha-api#language
[Buy residential proxies]: https://2captcha.com/proxy/residential-proxies
Expand Down
16 changes: 16 additions & 0 deletions examples/atbcaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.atbCaptcha({
pageurl: "https://mysite.com/page/with/atbCAPTCHA",
appId: "af25e409b33d722a95e56a230ff8771c",
apiServer: "https://cap.aisecurius.com"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
17 changes: 17 additions & 0 deletions examples/audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);
const fs = require('fs')
const audioCaptchaBase64 = fs.readFileSync("./media/example.mp3", "base64")

solver.audio({
body: audioCaptchaBase64,
lang: 'en'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
19 changes: 19 additions & 0 deletions examples/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);
const fs = require('fs')
const imageBase64 = fs.readFileSync("./media/canvas.png", "base64")
const imginstructionsBase64 = fs.readFileSync("./media/canvasImgInstructions.jpg", "base64")

solver.canvas({
body: imageBase64,
textinstructions: 'Highlight the red CIRCLE',
imginstructions: imginstructionsBase64,
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
16 changes: 16 additions & 0 deletions examples/cutcaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.cutCaptcha({
pageurl: "https://mysite.com/page/with/cutcaptcha",
miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
apiKey: "SAs61IAI",
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
8 changes: 6 additions & 2 deletions examples/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);
const fs = require('fs')
const imageBase64 = fs.readFileSync("./media/recaptchaGrid3x3.jpg", "base64")
const imageBase64 = fs.readFileSync("./media/recaptchaGrid4x4.jpg", "base64")
const instructionsImageBase64 = fs.readFileSync("./media/recaptchaGridImginstructions4x4.jpg", "base64")

solver.grid({
body: imageBase64,
textinstructions: "Select cars in the image"
textinstructions: "Select all squares with stairs",
imginstructions: instructionsImageBase64,
cols: 4,
rows: 4
})
.then((res) => {
console.log(res);
Expand Down
5 changes: 3 additions & 2 deletions examples/grid_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ const imageInstructionsBase64 = fs.readFileSync("./media/recaptchaGridImginstruc

solver.grid({
body: imageBase64,
textinstructions: "Select all squares with stairs",
textinstructions: "select all squares with stairs if there are none, click skip",
imginstructions: imageInstructionsBase64,
cols: 4,
rows: 4,
minClicks: 2,
maxClicks: 6,
lang: "en",
canSkip: 1,
imgType: "recaptcha" /* More information about the `img_type` parameter can be found at: https://2captcha.com/2captcha-api#grid */
// pingback: '123.123.123.123' /* More info about pingback https://2captcha.com/setting/pingback */
// previousId: '123456789'
})
Expand All @@ -24,4 +25,4 @@ solver.grid({
})
.catch((err) => {
console.log(err);
});
});
Loading

0 comments on commit 9dfe287

Please sign in to comment.