Skip to content

Commit ffe3862

Browse files
authored
Add Basilisk captcha support (#35)
1 parent e832b59 commit ffe3862

5 files changed

Lines changed: 121 additions & 2 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Examples of API requests for different captcha types are available on the [JavaS
5353
- [Yidun NECaptcha](#yidun-necaptcha)
5454
- [Alibaba Captcha](#alibaba-captcha)
5555
- [TSPD](#tspd)
56+
- [Basilisk](#basilisk)
5657
- [Other methods](#other-methods)
5758
- [goodReport](#goodreport)
5859
- [badReport](#badreport)
@@ -887,6 +888,30 @@ console.log(err);
887888
})
888889
```
889890

891+
### Basilisk
892+
893+
<sup>[API method description.](https://2captcha.com/2captcha-api#basilisk)</sup>
894+
895+
This method can be used to solve Basilisk captcha. Returns a token.
896+
897+
Required parameters: `pageurl`, `sitekey`.
898+
899+
```js
900+
solver.basilisk({
901+
pageurl: "https://example.com/login",
902+
sitekey: "b7890h...19fb2600897",
903+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
904+
proxy: "login:password@1.2.3.4:8080",
905+
proxytype: "HTTP"
906+
})
907+
.then((res) => {
908+
console.log(res);
909+
})
910+
.catch((err) => {
911+
console.log(err);
912+
})
913+
```
914+
890915
## Other methods
891916

892917
### goodReport

examples/basilisk.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const TwoCaptcha = require("../dist/index.js");
2+
require('dotenv').config();
3+
const APIKEY = process.env.APIKEY
4+
const solver = new TwoCaptcha.Solver(APIKEY);
5+
6+
solver.basilisk({
7+
pageurl: "https://example.com/login",
8+
sitekey: "b7890h...19fb2600897",
9+
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
10+
proxy: "login:password@1.2.3.4:8080",
11+
proxytype: "HTTP"
12+
})
13+
.then((res) => {
14+
console.log(res);
15+
})
16+
.catch((err) => {
17+
console.log(err);
18+
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"Audio Recognition",
5959
"Yidun NECaptcha",
6060
"Alibaba Captcha",
61-
"TSPD"
61+
"TSPD",
62+
"Basilisk"
6263
],
6364
"scripts": {
6465
"build": "tsc && node ./dist/index.js",

src/structs/2captcha.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,14 @@ export interface paramsTspd {
362362
userAgent?: string,
363363
}
364364

365+
export interface paramsBasilisk {
366+
pageurl: string,
367+
sitekey: string,
368+
userAgent?: string,
369+
proxy?: string,
370+
proxytype?: string,
371+
}
372+
365373
/**
366374
* An object containing properties of the captcha solution.
367375
* @typedef {Object} CaptchaAnswer
@@ -2579,6 +2587,69 @@ public async tspd(params: paramsTspd): Promise<CaptchaAnswer> {
25792587
}
25802588
}
25812589

2590+
/**
2591+
* ### Solves Basilisk Captcha
2592+
*
2593+
* Token-based method for automatic solving of Basilisk captcha. Returns a token.
2594+
* [Read more about Basilisk captcha](https://2captcha.com/2captcha-api#basilisk-captcha).
2595+
*
2596+
* @param {{ pageurl, sitekey, userAgent, proxy, proxytype }} params Parameters Basilisk Captcha as an object.
2597+
* @param {string} params.pageurl Full URL of the page where you see the captcha.
2598+
* @param {string} params.sitekey Value of the `data-sitekey` parameter found on the page.
2599+
* @param {string} params.userAgent Optional. Browser User-Agent used to open the page. Use the same User-Agent in requests to the target site.
2600+
* @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).
2601+
* @param {string} params.proxytype Optional. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
2602+
*
2603+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
2604+
* @throws APIError
2605+
*
2606+
* @example
2607+
* solver.basilisk({
2608+
* pageurl: "https://example.com/login",
2609+
* sitekey: "b7890h...19fb2600897",
2610+
* userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
2611+
* proxy: "login:password@1.2.3.4:8080",
2612+
* proxytype: "HTTP"
2613+
* })
2614+
* .then((res) => {
2615+
* console.log(res);
2616+
* })
2617+
* .catch((err) => {
2618+
* console.log(err);
2619+
* })
2620+
*/
2621+
public async basilisk(params: paramsBasilisk): Promise<CaptchaAnswer> {
2622+
params = renameParams(params)
2623+
2624+
checkCaptchaParams(params, "basilisk")
2625+
2626+
const payload = {
2627+
...this.defaultPayload,
2628+
...params,
2629+
method: "basilisk",
2630+
};
2631+
2632+
const response = await fetch(this.in, {
2633+
body: JSON.stringify(payload),
2634+
method: "post",
2635+
headers: { "Content-Type": "application/json" }
2636+
})
2637+
const result = await response.text()
2638+
2639+
let data;
2640+
try {
2641+
data = JSON.parse(result)
2642+
} catch {
2643+
throw new APIError(result)
2644+
}
2645+
2646+
if (data.status == 1) {
2647+
return this.pollResponse(data.request)
2648+
} else {
2649+
throw new APIError(data.request)
2650+
}
2651+
}
2652+
25822653
/**
25832654
* Reports a captcha as correctly solved.
25842655
*

src/utils/checkCaptchaParams.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
33
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid',
4-
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd']
4+
'textcaptcha', 'canvas', 'rotatecaptcha', 'keycaptcha', 'cutcaptcha', 'tencent', 'atb_captcha', 'prosopo', 'captchafox', 'vkimage', 'vkcaptcha', 'temu', 'altcha', 'binance', 'audio', 'yidun', 'alibaba', 'tspd', 'basilisk']
55

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

4445
/**
4546
* Getting required arguments for a captcha.
@@ -156,6 +157,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
156157
case "tspd":
157158
requiredFieldsArr = tspdRequiredFields
158159
break;
160+
case "basilisk":
161+
requiredFieldsArr = basiliskRequiredFields
162+
break;
159163
}
160164
return requiredFieldsArr
161165
}

0 commit comments

Comments
 (0)