Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Examples of API requests for different captcha types are available on the [JavaS
- [Yidun NECaptcha](#yidun-necaptcha)
- [Alibaba Captcha](#alibaba-captcha)
- [TSPD](#tspd)
- [Basilisk](#basilisk)
- [Other methods](#other-methods)
- [goodReport](#goodreport)
- [badReport](#badreport)
Expand Down Expand Up @@ -887,6 +888,30 @@ console.log(err);
})
```

### Basilisk

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

This method can be used to solve Basilisk captcha. Returns a token.

Required parameters: `pageurl`, `sitekey`.

```js
solver.basilisk({
pageurl: "https://example.com/login",
sitekey: "b7890h...19fb2600897",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
proxy: "login:password@1.2.3.4:8080",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
```

## Other methods

### goodReport
Expand Down
18 changes: 18 additions & 0 deletions examples/basilisk.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.basilisk({
pageurl: "https://example.com/login",
sitekey: "b7890h...19fb2600897",
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
proxy: "login:password@1.2.3.4:8080",
proxytype: "HTTP"
})
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"Audio Recognition",
"Yidun NECaptcha",
"Alibaba Captcha",
"TSPD"
"TSPD",
"Basilisk"
],
"scripts": {
"build": "tsc && node ./dist/index.js",
Expand Down
71 changes: 71 additions & 0 deletions src/structs/2captcha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,14 @@ export interface paramsTspd {
userAgent?: string,
}

export interface paramsBasilisk {
pageurl: string,
sitekey: string,
userAgent?: string,
proxy?: string,
proxytype?: string,
}

/**
* An object containing properties of the captcha solution.
* @typedef {Object} CaptchaAnswer
Expand Down Expand Up @@ -2579,6 +2587,69 @@ public async tspd(params: paramsTspd): Promise<CaptchaAnswer> {
}
}

/**
* ### Solves Basilisk Captcha
*
* Token-based method for automatic solving of Basilisk captcha. Returns a token.
* [Read more about Basilisk captcha](https://2captcha.com/2captcha-api#basilisk-captcha).
*
* @param {{ pageurl, sitekey, userAgent, proxy, proxytype }} params Parameters Basilisk Captcha as an object.
* @param {string} params.pageurl Full URL of the page where you see the captcha.
* @param {string} params.sitekey Value of the `data-sitekey` parameter found on the page.
* @param {string} params.userAgent Optional. Browser User-Agent used to open the page. Use the same User-Agent in requests to the target site.
* @param {string} params.proxy Optional. Proxy in format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
* @param {string} params.proxytype Optional. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
*
* @returns {Promise<CaptchaAnswer>} The result from the solve.
* @throws APIError
*
* @example
* solver.basilisk({
* pageurl: "https://example.com/login",
* sitekey: "b7890h...19fb2600897",
* userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
* proxy: "login:password@1.2.3.4:8080",
* proxytype: "HTTP"
* })
* .then((res) => {
* console.log(res);
* })
* .catch((err) => {
* console.log(err);
* })
*/
public async basilisk(params: paramsBasilisk): Promise<CaptchaAnswer> {
params = renameParams(params)

checkCaptchaParams(params, "basilisk")

const payload = {
...this.defaultPayload,
...params,
method: "basilisk",
};

const response = await fetch(this.in, {
body: JSON.stringify(payload),
method: "post",
headers: { "Content-Type": "application/json" }
})
const result = await response.text()

let data;
try {
data = JSON.parse(result)
} catch {
throw new APIError(result)
}

if (data.status == 1) {
return this.pollResponse(data.request)
} else {
throw new APIError(data.request)
}
}

/**
* Reports a captcha as correctly solved.
*
Expand Down
6 changes: 5 additions & 1 deletion src/utils/checkCaptchaParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +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', 'grid',
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd']
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd', 'basilisk']

// Names of required fields that must be contained in the parameters captcha
const recaptchaRequiredFields = ['pageurl','googlekey']
Expand Down Expand Up @@ -40,6 +40,7 @@ const audioRequiredFields = ['body', 'lang']
const yidunRequiredFields = ['pageurl', 'sitekey']
const alibabaRequiredFields = ['pageurl', 'scene_id', 'prefix']
const tspdRequiredFields = ['pageurl', 'tspd_cookie', 'html_page_base64', 'proxy', 'proxytype']
const basiliskRequiredFields = ['pageurl', 'sitekey']

/**
* Getting required arguments for a captcha.
Expand Down Expand Up @@ -156,6 +157,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
case "tspd":
requiredFieldsArr = tspdRequiredFields
break;
case "basilisk":
requiredFieldsArr = basiliskRequiredFields
break;
}
return requiredFieldsArr
}
Expand Down