Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: 2captcha/2captcha-javascript
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.4
Choose a base ref
...
head repository: 2captcha/2captcha-javascript
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Jul 24, 2024

  1. Add Grid method

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    85d42e3 View commit details
  2. Copy the full SHA
    5032a02 View commit details
  3. Copy the full SHA
    f41153c View commit details
  4. Add Grid examples

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    29df604 View commit details
  5. Update README.md

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    91e3df2 View commit details
  6. Copy the full SHA
    23d9bcf View commit details
  7. Refactor

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    43423f8 View commit details
  8. Refactor

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    e03686c View commit details
  9. Merge pull request #13 from 2captcha/RC-2646

    RC-2646 Add Grid method
    dzmitry-duboyski authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9e75fe2 View commit details
  10. 1.1.0

    dzmitry-duboyski committed Jul 24, 2024
    Copy the full SHA
    90f8e19 View commit details
  11. Update README.md

    dzmitry-duboyski authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b39d6ea View commit details
  12. Update README.md

    dzmitry-duboyski authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c5df0ad View commit details
  13. Update README.md

    dzmitry-duboyski authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    160ac04 View commit details
  14. Update README.md

    dzmitry-duboyski authored Jul 24, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    e077ece View commit details

Commits on Aug 9, 2024

  1. Update README.md

    dzmitry-duboyski authored Aug 9, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ad13d02 View commit details

Commits on Aug 12, 2024

  1. fix invisible type

    dzmitry-duboyski committed Aug 12, 2024
    Copy the full SHA
    992887f View commit details
  2. types fix

    dzmitry-duboyski committed Aug 12, 2024
    Copy the full SHA
    d28a2cd View commit details
  3. 1.1.1

    dzmitry-duboyski committed Aug 12, 2024
    Copy the full SHA
    778dd9b View commit details

Commits on Sep 10, 2024

  1. Copy the full SHA
    45c682a View commit details
  2. refactor

    dzmitry-duboyski committed Sep 10, 2024
    Copy the full SHA
    059759f View commit details
  3. Merge pull request #16 from 2captcha/RC-2968

    RC-2968 Add extended response
    dzmitry-duboyski authored Sep 10, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c19b8c6 View commit details
  4. 1.2.0

    dzmitry-duboyski committed Sep 10, 2024
    Copy the full SHA
    ddf8641 View commit details

Commits on Oct 19, 2024

  1. Update README.md

    dzmitry-duboyski authored Oct 19, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    6c3631f View commit details

Commits on Oct 22, 2024

  1. Copy the full SHA
    653451c View commit details
  2. Add Text method

    dzmitry-duboyski committed Oct 22, 2024
    Copy the full SHA
    938c67a View commit details

Commits on Oct 23, 2024

  1. Copy the full SHA
    67696a3 View commit details

Commits on Oct 25, 2024

  1. Add Canvas Method

    dzmitry-duboyski committed Oct 25, 2024
    Copy the full SHA
    c2a7b92 View commit details
  2. Add Rotate method

    dzmitry-duboyski committed Oct 25, 2024
    Copy the full SHA
    2529345 View commit details
  3. Copy the full SHA
    7df649b View commit details
  4. Update Grid example

    dzmitry-duboyski committed Oct 25, 2024
    Copy the full SHA
    2ac2b59 View commit details
  5. Copy the full SHA
    16b1316 View commit details

Commits on Oct 28, 2024

  1. Copy the full SHA
    cab1fd4 View commit details
  2. typo

    dzmitry-duboyski committed Oct 28, 2024
    Copy the full SHA
    db71eff View commit details

Commits on Oct 29, 2024

  1. Copy the full SHA
    6c8626d View commit details
  2. Copy the full SHA
    7e48fcb View commit details
  3. Add Tencent method

    dzmitry-duboyski committed Oct 29, 2024
    Copy the full SHA
    60ee9e7 View commit details
  4. Copy the full SHA
    a7086f7 View commit details
  5. Add Audio method

    dzmitry-duboyski committed Oct 29, 2024
    Copy the full SHA
    b17e7ad View commit details

Commits on Oct 30, 2024

  1. Update README.md

    dzmitry-duboyski committed Oct 30, 2024
    Copy the full SHA
    d2c69ea View commit details
  2. Refactor

    dzmitry-duboyski committed Oct 30, 2024
    Copy the full SHA
    5a2ec5c View commit details

Commits on Oct 31, 2024

  1. Merge pull request #18 from 2captcha/RC-2942

    RC-2942 Add methods
    dzmitry-duboyski authored Oct 31, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    9dfe287 View commit details
  2. 1.3.0

    dzmitry-duboyski committed Oct 31, 2024
    Copy the full SHA
    5e69259 View commit details
  3. Update package.json

    dzmitry-duboyski committed Oct 31, 2024
    Copy the full SHA
    3a6e9c9 View commit details

Commits on Nov 19, 2024

  1. Update README.md

    dzmitry-duboyski committed Nov 19, 2024
    Copy the full SHA
    eb5f7d6 View commit details
  2. Update examples

    dzmitry-duboyski committed Nov 19, 2024
    Copy the full SHA
    b779f9e View commit details
  3. Update README.md

    dzmitry-duboyski committed Nov 19, 2024
    Copy the full SHA
    55fcbd0 View commit details
  4. Update example file

    dzmitry-duboyski committed Nov 19, 2024
    Copy the full SHA
    d1f66a4 View commit details

Commits on Nov 21, 2024

  1. refactor

    dzmitry-duboyski committed Nov 21, 2024
    Copy the full SHA
    d4bad25 View commit details
277 changes: 243 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
# JavaScript captcha solver module for 2Captcha API
<a href="https://github.com/2captcha/2captcha-python"><img src="https://github.com/user-attachments/assets/37e1d860-033b-4cf3-a158-468fc6b4debc" width="82" height="30"></a>
<a href="https://github.com/2captcha/2captcha-javascript"><img src="https://github.com/user-attachments/assets/371b271e-33c3-4217-af21-b95517a4677c" width="36" height="30"></a>
<a href="https://github.com/2captcha/2captcha-go"><img src="https://github.com/user-attachments/assets/ab22182e-6cb2-41fa-91f4-d5e89c6d7c6f" width="63" height="30"></a>
<a href="https://github.com/2captcha/2captcha-ruby"><img src="https://github.com/user-attachments/assets/0270d56f-79b0-4c95-9b09-4de89579914b" width="75" height="30"></a>
<a href="https://github.com/2captcha/2captcha-cpp"><img src="https://github.com/user-attachments/assets/36de8512-acfd-44fb-bb1f-b7c793a3f926" width="45" height="30"></a>
<a href="https://github.com/2captcha/2captcha-php"><img src="https://github.com/user-attachments/assets/e8797843-3f61-4fa9-a155-ab0b21fb3858" width="52" height="30"></a>
<a href="https://github.com/2captcha/2captcha-java"><img src="https://github.com/user-attachments/assets/a3d923f6-4fec-4c07-ac50-e20da6370911" width="50" height="30"></a>
<a href="https://github.com/2captcha/2captcha-csharp"><img src="https://github.com/user-attachments/assets/f4d449de-780b-49ed-bb0a-b70c82ec4b32" width="38" height="30"></a>

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.
# JavaScript module for 2Captcha API (captcha solver)

- [JavaScript captcha solver module for 2Captcha API](#javascript-captcha-solver-module-for-2captcha-api)
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)
- [FunCaptcha](#funcaptcha)
- [GeeTest](#geetest-captcha)
- [GeeTest V4](#geetest-v4-captcha)
@@ -25,13 +34,27 @@ The easiest way to quickly integrate the [2Captcha](https://2captcha.com/) captc
- [MTCaptcha](#mtcaptcha)
- [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)
- [Useful articles](#useful-articles)
- [Examples using Puppeteer](#examples-using-puppeteer)
- [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
@@ -95,7 +118,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({
@@ -105,7 +127,6 @@ solver.imageCaptcha({
max_len: 5
})
.then((res) => {
// Logs the image text
console.log(res);
})
.catch((err) => {
@@ -154,26 +175,6 @@ solver.recaptcha({
})
```


### hCaptcha

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

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

```js
solver.hcaptcha({
pageurl: "https://2captcha.com/demo/hcaptcha?difficulty=moderate",
sitekey: "b76cd927-d266-4cfb-a328-3b03ae07ded6"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### FunCaptcha

<sup>[API method description.](https://2captcha.com/2captcha-api#solving_funcaptcha_new)</sup>
@@ -426,7 +427,7 @@ console.log(err);
The ClickCaptcha method returns the coordinates of points on the captcha image. It can be used if you need to click on particular points in the image.

```js
const imageBase64 = fs.readFileSync("./tests/media/hCaptchaImage.jpg", "base64")
const imageBase64 = fs.readFileSync("./tests/media/coordinates.jpg", "base64")

solver.coordinates({
body: imageBase64,
@@ -440,7 +441,7 @@ solver.coordinates({
})
```

### Bounding Box Method:
### Bounding Box Method

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

@@ -462,6 +463,186 @@ solver.boundingBox({
})
```

### Grid

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

This method allows to solve any captcha where image can be divided into equal parts like reCAPTCHA V2. A grid is applied above the image. And you receive the numbers clicked boxes.

> [!IMPORTANT]
> You must to send instruction `imginstructions` or `textinstructions`.
```js
solver.grid({
body: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAR4AAACwCAIAAAB...",
textinstructions: "Select cars in the image"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

### 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
@@ -499,7 +680,7 @@ solver.balance()

## Proxies

You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha, keycaptcha, capy puzzle, lemin, turnstile, amazon waf, DataDome, CyberSiARA, MTCaptcha, Friendly Captcha and etc. The proxy will be forwarded to the API to solve the captcha.
You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, keycaptcha, capy puzzle, lemin, turnstile, amazon waf, DataDome, CyberSiARA, MTCaptcha, Friendly Captcha and etc. The proxy will be forwarded to the API to solve the captcha.

We have our own proxies that we can offer you. [Buy residential proxies] for avoid restrictions and blocks. [Quick start].

@@ -516,17 +697,45 @@ solver.recaptcha({

Examples of solving all supported captcha types are located in the [examples] directory.

## Examples using Puppeteer
Also we have a separate repositories you can find examples of solving captcha using Puppeteer.
At the moment we have implemented examples of bypassing Cloudflare Challenge page and reCAPTCHA.
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

<a href="mailto:support@2captcha.com"><img src="https://github.com/user-attachments/assets/539df209-7c85-4fa5-84b4-fc22ab93fac7" width="80" height="30"></a>
<a href="https://2captcha.com/support/tickets/new"><img src="https://github.com/user-attachments/assets/be044db5-2e67-46c6-8c81-04b78bd99650" width="81" height="30"></a>

## Join the team 👪

There are many ways to contribute, of which development is only one! Find your next job. Open positions: AI experts, scrapers, developers, technical support, and much more! 😍

<a href="mailto:job@2captcha.com"><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:support@2captcha.com">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
[Quick start]: https://2captcha.com/proxy?openAddTrafficModal=true
[examples]: ./examples
[examples]: ./examples
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);
})
14 changes: 8 additions & 6 deletions examples/boundingBox.js

Large diffs are not rendered by default.

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);
})
2 changes: 1 addition & 1 deletion examples/coordinates.js
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);


const imageBase64 = fs.readFileSync("./media/hCaptchaImage.jpg", "base64")
const imageBase64 = fs.readFileSync("./media/coordinates.jpg", "base64")

solver.coordinates({
body: imageBase64,
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);
})
21 changes: 21 additions & 0 deletions examples/grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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/recaptchaGrid4x4.jpg", "base64")
const instructionsImageBase64 = fs.readFileSync("./media/recaptchaGridImginstructions4x4.jpg", "base64")

solver.grid({
body: imageBase64,
textinstructions: "Select all squares with stairs",
imginstructions: instructionsImageBase64,
cols: 4,
rows: 4
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
28 changes: 28 additions & 0 deletions examples/grid_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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/recaptchaGrid4x4.jpg", "base64");
const imageInstructionsBase64 = fs.readFileSync("./media/recaptchaGridImginstructions4x4.jpg", "base64");

solver.grid({
body: imageBase64,
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'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
});
18 changes: 18 additions & 0 deletions examples/keyCaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

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);
})
Binary file added examples/media/boundingBox.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/media/boundingBoxImginstructions.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/media/canvas.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/media/canvasImgInstructions.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added examples/media/example.mp3
Binary file not shown.
Binary file added examples/media/recaptchaGrid3x3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/media/recaptchaGrid4x4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/media/rotatecaptcha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/rotate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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/rotatecaptcha.png", "base64")

solver.rotate({
body: imageBase64,
angle: 15,
textinstructions: "Rotate the object to the correct position"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
6 changes: 3 additions & 3 deletions examples/hcaptcha.js → examples/tencent.js
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.hcaptcha({
pageurl: "https://2captcha.com/demo/hcaptcha",
sitekey: "b76cd927-d266-4cfb-a328-3b03ae07ded6"
solver.tencent({
pageurl: "https://mysite.com/page/with/tencent",
appId: "189956587"
})
.then((res) => {
console.log(res);
15 changes: 15 additions & 0 deletions examples/text.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const TwoCaptcha = require("../dist/index.js");
require('dotenv').config();
const APIKEY = process.env.APIKEY
const solver = new TwoCaptcha.Solver(APIKEY);

solver.text({
textcaptcha: "If tomorrow is Saturday, what day is today?",
lang: 'en'
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
4 changes: 2 additions & 2 deletions package-lock.json
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@2captcha/captcha-solver",
"version": "1.0.4",
"description": "JavaScript library for easy integration with the API of 2captcha captcha solving service to bypass reCAPTCHA, hCaptcha, funcaptcha, geetest and solve any other captchas.",
"version": "1.3.0",
"description": "JavaScript library for easy integration with the API of 2captcha captcha solving service to bypass reCAPTCHA, funcaptcha, geetest and solve any other captchas.",
"main": "dist/index.js",
"repository": {
"type": "git",
@@ -21,7 +21,6 @@
"captchasolver",
"capmonster",
"reCAPTCHA",
"hCaptcha",
"FunCaptcha",
"Geetest",
"image captcha",
@@ -41,7 +40,15 @@
"CyberSiARA",
"MTCaptcha",
"Bounding Box Method",
"Friendly Captcha"
"Friendly Captcha",
"Text Captcha",
"Canvas",
"Rotate",
"KeyCaptcha",
"Cutcaptcha",
"Tencent",
"atbCAPTCHA",
"Audio Recognition"
],
"scripts": {
"build": "tsc && node ./dist/index.js",
704 changes: 627 additions & 77 deletions src/structs/2captcha.ts

Large diffs are not rendered by default.

60 changes: 53 additions & 7 deletions src/utils/checkCaptchaParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Captcha methods for which parameter checking is available
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha']
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid',
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'audio']

// Names of required fields that must be contained in the parameters captcha
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -16,10 +17,19 @@ const turnstileRequiredFields = ['pageurl','sitekey']
const base64RequiredFields = ['body']
const capyPuzzleRequiredFields = ['captchakey']
const dataDomeRequiredFields = ['pageurl', 'captcha_url', 'userAgent', 'proxy', 'proxytype']
const сyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
const mtСaptchaRequiredFields = ['pageurl', 'sitekey']
const cyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
const mtCaptchaRequiredFields = ['pageurl', 'sitekey']
const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstructions
const friendlyCaptchaFields = ['pageurl','sitekey']
const gridRequiredFields = ['body'] // and textinstructions or imginstructions
const textCaptchaRequiredFields = ['textcaptcha']
const canvasRequiredFields = ['body'] // and textinstructions or imginstructions
const rotateRequiredFields = ['body']
const keycaptchaRequiredFields = ['pageurl', 's_s_c_user_id', 's_s_c_session_id', 's_s_c_web_server_sign', 's_s_c_web_server_sign2']
const cutcaptchaRequiredFields = ['pageurl', 'misery_key', 'api_key']
const tencentRequiredFields = ['pageurl', 'app_id']
const atbCaptchaRequiredFields = ['pageurl', 'app_id', 'api_server']
const audioRequiredFields = ['body', 'lang']

/**
* Getting required arguments for a captcha.
@@ -61,29 +71,64 @@ const getRequiredFildsArr = (method: string):Array<string> => {
case "base64":
requiredFieldsArr = base64RequiredFields
break;
case "grid":
requiredFieldsArr = gridRequiredFields
break;
case "capy":
requiredFieldsArr = capyPuzzleRequiredFields
break;
case "datadome":
requiredFieldsArr = dataDomeRequiredFields
break;
case "cybersiara":
requiredFieldsArr = сyberSiARARequiredFields
requiredFieldsArr = cyberSiARARequiredFields
break;
case "mt_captcha":
requiredFieldsArr = mtСaptchaRequiredFields
requiredFieldsArr = mtCaptchaRequiredFields
break;
case "bounding_box":
requiredFieldsArr = boundingBoxRequiredFields
break;
case "friendly_captcha":
requiredFieldsArr = friendlyCaptchaFields
break;
case "textcaptcha":
requiredFieldsArr = textCaptchaRequiredFields
break;
case "canvas":
requiredFieldsArr = canvasRequiredFields
break;
case "rotatecaptcha":
requiredFieldsArr = rotateRequiredFields
break;
case "keycaptcha":
requiredFieldsArr = keycaptchaRequiredFields
break;
case "cutcaptcha":
requiredFieldsArr = cutcaptchaRequiredFields
break;
case "tencent":
requiredFieldsArr = tencentRequiredFields
break;
case "atb_captcha":
requiredFieldsArr = atbCaptchaRequiredFields
break;
case "audio":
requiredFieldsArr = audioRequiredFields
break;
}
return requiredFieldsArr
}

/**
* ### Captcha Required Parameters Check.
*
* Checking required captcha parameters before sending.
* This function checks for required fields in the provided captcha parameters.
* Throws an error if the specified method is not supported or if required fields are missing.
*
* Note: The `checkCaptchaParams()` function should be called after `renameParams()`, if function `renameParams()` is used.
*
* @param { Object } params Captcha parameters that need to be checked.
* @returns true | false | Error
* @example
@@ -111,12 +156,13 @@ export default function checkCaptchaParams(params: Object, method: string) {
}
})

if(method === "bounding_box") {
//The parameters `textinstructions` and `imginstructions` are mandatory for the methods `bounding_box`, `grid`, and `canvas`.
if(method === "bounding_box" || method === "grid" || method === "canvas") {
if(params.hasOwnProperty('textinstructions') || params.hasOwnProperty('imginstructions')) {
isCorrectCaptchaParams = true
} else {
isCorrectCaptchaParams = false
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "bounding_box" method. Please add field "textinstructions" or "imginstructions" in object and try again.\nPlease correct your code for the "bounding_box" method according to the code examples`)
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "${method}" method. Please add field "textinstructions" or "imginstructions" to captcha parameters.`)
}
}

53 changes: 53 additions & 0 deletions src/utils/renameParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
*
* ### Renaming captcha parameters
*
* Description: parameter names used in the API may differ from those used in the library, in such cases parameter names are renamed in accordance with those used in the API.
*
* @param params - captcha parameters as an object
* @returns returns new object with renamed params
*
*/
export default function renameParams(params: any) {
let newParams: any = new Object();

/**
* Captcha parameters that need to be renamed before sent to the API.
*/
const replaceParams: any = {
// Grid
"cols" : "recaptchacols",
"rows" : "recaptcharows",
"minClicks" : "min_clicks",
"maxClicks" : "max_clicks",
"canSkip" : "can_no_answer",
"previousId" : "previousID",
"imgType" : "img_type",

// KeyCaptcha
"userId" : "s_s_c_user_id",
"sessionId":"s_s_c_session_id",
"webServerSign":"s_s_c_web_server_sign",
"webServerSign2":"s_s_c_web_server_sign2",

// Cutcaptcha
"miseryKey":"misery_key",
"apiKey":"api_key",

// Tencent
"appId": "app_id",

// atbCAPTCHA
"apiServer": "api_server",
}

for(let key in params) {
if(replaceParams.hasOwnProperty(key)) {
newParams[replaceParams[key]] = params[key]
} else {
newParams[key] = params[key]
}
}

return newParams
}