Socket
Socket
Sign inDemoInstall

capsolver-npm

Package Overview
Dependencies
8
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

examples/anticloudflare.js

9

examples/README.md

@@ -1,15 +0,14 @@

PM2
PM2 Benchmark
-
- **Perform test/benchmark for a website with multiple PM2 process.**
- **Perform tests for a website with multiple PM2 processes.**
1. Install pm2 globally: `npm install -g pm2`.
3. Set [config file](https://github.com/0qwertyy/capsolver-npm/blob/master/examples/ecosystem.config.js) as your preference.
3. Set [pm2 config file](https://github.com/0qwertyy/capsolver-npm/blob/master/examples/ecosystem.config.js) as your preference.
4. Control processes: `pm2 start ecosystem.config.js` & `pm2 delete all`.
5. Print logs for all process: `pm2 logs`.
- [screenshot](https://s1.gifyu.com/images/webstorm64_rDATvCkhSP.gif)
- [screenshot](https://s3.gifyu.com/images/webstorm64_pvt9zUKloT.gif)
📁 More task examples

@@ -16,0 +15,0 @@ -

const CapSolver = require('../src/CapSolver');
const handler = new CapSolver('CAI-XXX...', 1);
const handler = new CapSolver('CAI-XXXX ...');
(async function () {
await handler.recaptchav2proxyless('https://www.nakedcph.com/en/auth/view', '6LeNqBUUAAAAAFbhC-CS22rwzkZjr_g4vMmqD_qo')
await handler.recaptchav2('https://www.nakedcph.com/en/auth/view', '6LeNqBUUAAAAAFbhC-CS22rwzkZjr_g4vMmqD_qo', {'proxy':'proxy.provider.io:23331:user1:password1'})
.then(response => {

@@ -7,0 +7,0 @@ if (response.error === 0) {

{
"name": "capsolver-npm",
"version": "1.0.0",
"version": "1.0.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "src/CapSolver.js",

@@ -1,8 +0,3 @@

# capsolver.com api wrapper🧠 (tasks handler)
Want you to get verified captcha **tokens** calling one function within your NodeJS application?
Run with this repo and find a fast way to perform web/api automations.
- **Manage to solve captcha challenges with AI in a NodeJS app ([captcha service based](https://capsolver.com/)).**
# capsolver.com api wrapper🧠
- **Manage to solve captcha challenges with AI in a NodeJS app (captcha service based).**
- ❗ An API key it's **required**. [**Get here.**](https://dashboard.capsolver.com/passport/register?inviteCode=CHhA_5os)

@@ -12,7 +7,6 @@ - 👀 **Puppeteer integration at** [**puppeteer-extra-plugin-capsolver**](https://github.com/0qwertyy/puppeteer-extra-plugin-capsolver).

now binded: 🔥 *AntiKasada & AntiAkamaiBMP. 🔥 HCaptcha & FunCaptcha Images Classification.*
now binded: *🔥 AntiTurnstile. 🔥 AntiCloudflare. 🔥 Geetest V4.*
[![](https://img.shields.io/badge/1.0.0-capsolver--npm-blue?logo=npm&logoColor=white)](https://www.npmjs.com/package/capsolver-npm)
[![](https://img.shields.io/badge/provider-capsolver.com-blue)](https://dashboard.capsolver.com/passport/register?inviteCode=CHhA_5os)
[![](https://img.shields.io/badge/API_doc-captchaai.atlassian.net-blue)](https://captchaai.atlassian.net/wiki/spaces/capsolver/pages/393295/All+task+types+and+price+list)
[![](https://img.shields.io/badge/1.0.1-capsolver--npm-blue?logo=npm&logoColor=white)](https://www.npmjs.com/package/capsolver-npm)
[![](https://img.shields.io/badge/documentation-docs.capsolver.com-blue)](https://docs.capsolver.com/guide/getting-started.html)

@@ -31,7 +25,6 @@ ⬇️ Install

```
2. Define tasks handler (singleton).
3. Declare singleton/handler.
```javascript
const handler = new CapSolver(apikey); // task handler / solver
const handler = new CapSolver(apikey); // captcha task handler
```

@@ -41,7 +34,7 @@

**❗ There are 2 different versions in order to handle task results:**
**❗ 2 version for handle captcha tasks results are the followind:**
**1️⃣ task-bind methods**
**1️⃣ task-bind methods** (handle task results in one step)
*example: check capsolver.com balance + run for one `.hcaptchaproxyless()`*
*example: check capsolver.com balance + run for one hcaptcha token (`.hcaptchaproxyless()`):*

@@ -61,35 +54,24 @@ ```javascript

*example: run for one HCaptchaTask with `.hcaptcha()` with custom proxy.*
**2️⃣ Run any task and build `taskData` schema for a task type.**
```javascript
const CapSolver = require('capsolver-npm');
const handler = new CapSolver('apikey', 1); // verbose level 1
let b = await handler.balance();
if(b > 0){ // usd balance
await handler.hcaptcha(
'https://websiteurl.com/',
'000000-000000000-0000000',
{ proxy: "proxyType:proxyAddress:proxyPort:proxyLogin:proxyPassword" } // 2nd proxyInfo format
)
.then(async response => {
if(response.error === 0){ console.log(response.solution) }
else{ console.log('error ' + JSON.stringify(response.apiResponse)) }
});
}
```
**Check task parameters at [official docs](https://docs.capsolver.com/guide/recognition/ImageToTextTask.html) in order to bind manually captcha tasks.**
**2️⃣ Run any task. Build `taskData` schema for a task type.**
*example: build & run `taskData` schema with custom proxy for HCaptchaTask.*
*example: run for one hcaptcha token w/ custom proxy (.runAnyTask()):*
```javascript
const CapSolver = require('capsolver-npm');
const handler = new CapSolver('apikey');
const CapSolver = require("capsolver-npm");
const handler = new CapSolver("apikey");
const taskData = // build a task
{
type : 'HCaptchaTask',
websiteURL : 'https://website.com/',
websiteKey : '000000-00000-000000-000000000',
// also string format is supported with `proxy`
// proxyInfo: { proxy: "proxyType:proxyAddress:proxyPort:proxyLogin:proxyPassword" },
proxyInfo: { 'proxyType': 'http', 'proxyAddress': 'ip_address', 'proxyPort': 3221, 'proxyLogin': 'username', 'proxyPassword': 'password' },
type : "HCaptchaTask",
websiteURL : "https://website.com/",
websiteKey : "000000-00000-000000-000000000",
proxyInfo: {
// string format also supported
// "proxy": "proxy.provider.io:23331:user1:password1",
"proxyType": "http",
"proxyAddress": "ip_address",
"proxyPort": 3221,
"proxyLogin": "username", // not required
"proxyPassword": "password" // not required
},
}

@@ -100,9 +82,9 @@

if(response.error === 0){ console.log(response.solution) }
else{ console.log('error ' + JSON.stringify(response.apiResponse)) }
else{ console.log("error " + JSON.stringify(response.apiResponse)) }
});
```
↩️ Returned object
↩️ Get solutions
-
**All methods return the following schema.**
**All methods returns the following schema:**

@@ -121,9 +103,9 @@ | Parameter | Type | Description |

error: 0,
statusText: '200 OK',
statusText: "200 OK",
apiResponse: {
errorId: 0,
taskId: '4e6c33f5-bc14-44d0-979e-d5f37b072c59',
status: 'ready',
taskId: "4e6c33f5-bc14-44d0-979e-d5f37b072c59",
status: "ready",
solution: {
gRecaptchaResponse: '03AIIukzgCys9brSNnrVbwXE9mTesvkxQ-ocK ...'
gRecaptchaResponse: "03AIIukzgCys9brSNnrVbwXE9mTesvkxQ-ocK ..."
}

@@ -135,6 +117,6 @@ }

```javascript
// ❌ ERROR_INVALID_TASK_DATA response
// ❌ Error response (invalid API key)
{
error: -1,
statusText: '400 Bad Request',
statusText: "400 Bad Request",
apiResponse: {

@@ -148,29 +130,39 @@ errorCode: "ERROR_INVALID_TASK_DATA",

- Each method it's an easy way to **launch and handle multiple requests** to capsolver API.
- Some determinated captcha tasks have required arguments which mostly are of type string or type object. Anycase, this is described in capsolver.com official docs page.
- [**reffered docs.**](https://docs.capsolver.com/)
# 📖 Supported captcha tasks
# ⚙️Supported API methods
| Method | Returns |
|:-------------------------------------|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `await handler.balance()` | directly the float value or an error object |
| `await handler.getBalance()` | succes or error object |
| `await handler.runAnyTask(taskData)` | handle task results for a `taskData` schema passed. In order to build this object, use [**!reffered docs**](https://docs.capsolver.com/) and **check parameters by catpcha task type**. |
| `await handler.balance()` | get balance as float number |
| `await handler.runAnyTask(taskData)` | CapSolver API response |
* `taskData` schema it's shown in examples.
* `proxyInfo` schema has 2 versions:
Custom proxy usage (proxyInfo schema):
`{ 'proxy' : 'proxyType:proxyAddress:proxyPort:proxyLogin:proxyPassword' }`
```javascript
// version 1
const proxyInfo = {
"proxyType": "http",
"proxyAddress": "ip_address",
"proxyPort": 3221,
"proxyLogin": "username",
"proxyPassword": "password"
}
or
// version 2
const proxyInfo = {
proxy: "proxyType:proxyAddress:proxyPort:proxyLogin:proxyPassword"
}
`{ 'proxyType': 'http', 'proxyAddress': 'ip_address', 'proxyPort': 3221, 'proxyLogin': 'username', 'proxyPassword': 'password' }`
```
*(proxyLogin & proxyPassword are optionals)*
*task-bind methods*
task-bin methods:
-
retrieve solutions (tokens/coordenates) with the followings:
⚙️ **HCaptcha**
Parameter `queries`: base64 images array
```javascript

@@ -180,29 +172,60 @@ // * check required parameters for a website with API docs.

await handler.hcaptchaproxyless(websiteURL, websiteKey, userAgent, isInvisible, enterprisePayload)
await handler.hcaptchaclassification(question, queries, coordinate)
await handler.hcaptchaclassification(question, base64)
```
⚙️ **ReCaptcha**
```javascript
await handler.recaptchav2(websiteURL, websiteKey, proxyInfo, userAgent, isInvisible, recaptchaDataSValue, cookies)
await handler.recaptchav2proxyless(websiteURL, websiteKey, userAgent, isInvisible, recaptchaDataSValue, cookies)
await handler.recaptchav2enterprise(websiteURL, websiteKey, proxyInfo, userAgent, enterprisePayload, apiDomain, cookies)
await handler.recaptchav2enterpriseproxyless(websiteURL, websiteKey, userAgent, enterprisePayload, apiDomain, cookies)
await handler.recaptchav3(websiteURL, websiteKey, proxyInfo, pageAction, minScore)
await handler.recaptchav3proxyless(websiteURL, websiteKey, pageAction, minScore)
await handler.recaptchav2proxyless(websiteURL, websiteKey, userAgent=null, isInvisible=null, recaptchaDataSValue=null, cookies=null)
await handler.recaptchav2enterprise(websiteURL, websiteKey, proxyInfo, userAgent=null, enterprisePayload=null, apiDomain=null, cookies=null)
await handler.recaptchav2enterpriseproxyless(websiteURL, websiteKey, userAgent=null, enterprisePayload=null, apiDomain=null, cookies=null)
await handler.recaptchav3(websiteURL, websiteKey, proxyInfo, pageAction, minScore=null)
await handler.recaptchav3proxyless(websiteURL, websiteKey, pageAction, minScore=null)
await handler.recaptchav3enterprise(websiteURL, websiteKey, proxyInfo, pageAction, minScore=null, enterprisePayload=null, apiDomain=null, userAgent=null, cookies=null)
await handler.recaptchav3enterpriseproxyless(websiteURL, websiteKey, pageAction, minScore=null, enterprisePayload=null, apiDomain=null, userAgent=null, cookies=null)
```
⚙️ **Datadome**
```javascript
await handler.datadome(websiteURL, userAgent, captchaUrl, proxyInfo)
```
⚙️ **FunCaptcha**
Parameter `image`: base64 screenshot image
```javascript
await handler.funcaptcha(websiteURL, websitePublicKey, proxyInfo, funcaptchaApiJSSubdomain, userAgent, data)
await handler.funcaptchaproxyless(websiteURL, websitePublicKey, funcaptchaApiJSSubdomain, userAgent, data)
await handler.funcaptchaclassification(image, question)
```
await handler.geetest(websiteURL, gt, challenge, geetestApiServerSubdomain, proxyInfo, version, userAgent, geetestGetLib, initParameters)
await handler.geetestproxyless(websiteURL, gt, challenge, geetestApiServerSubdomain, version, userAgent, geetestGetLib, initParameters)
⚙️ **Geetest**
await handler.image2text(body)
❗ Supports for Geetest V3 & Geetest V4: Manage through [GeetestTask documentation](https://docs.capsolver.com/guide/captcha/Geetest.html).
await handler.antikasada(pageURL, proxyInfo, onlyCD, userAgent) // *: pageUrl & proxyInfo are always required
await handler.antiakamaibmp(packageName, version, deviceId, deviceName, count) // *: packageName it's always required
```javascript
await handler.geetest(websiteURL, gt, challenge, proxyInfo, geetestApiServerSubdomain, captchaId)
await handler.geetestproxyless(websiteURL, gt, challenge, geetestApiServerSubdomain, captchaId)
```
*pass null instead of empty for optional arguments*
⚙️ **MTCaptcha**
```javascript
await handler.mtcaptcha(websiteURL, websiteKey, proxyInfo)
await handler.mtcaptchaproxyless(websiteURL, websiteKey)
```
⚙️ **ImageToText**
```javascript
await handler.image2text(body)
```
**Currently unsupported API methods:**
❌ ReCaptchaV2Classification
❌ ReCaptchaV2Classification ❌ VoiceRecognition ❌ Turnstile ❌ Cloudflare Challenge

@@ -212,27 +235,18 @@ Verbose level

```javascript
const handler = new CapSolver(apikey, verbose); // on handler initialization
// on CapSolver handler definition
const handler = new CapSolver(apikey, verbose);
```
Verbose level `undefined || 0`: Dont print logs, just get response.
Verbose level `undefined` or `0`: Dont print logs, just handle for solution.
Verbose level `1`: Print logs about performed requests during execution.
Verbose level `1`: Only log task status in console.
Verbose level `2`: Appends full capsolver api response in verbose level 1 outputs.
Verbose level `2`: Log API response in console.
References
📁 Working examples
-
- [**HCaptchaClassification: Recognize the images that you need to click.**](https://captchaai.atlassian.net/wiki/spaces/capsolver/pages/426261/HCaptchaClassification+recognize+the+images+that+you+need+to+click)
- Responds through image recognition.
- Send a base64 **images array** with `.hcaptchaclassification(question, queries, coordinate)`.
- 👀 Find [**here**](https://github.com/0qwertyy/puppeteer-extra-plugin-capsolver) an **integration within `puppeteer-extra`**.
- [**FunCaptchaClassification (beta): Recognize the images that you need to click.**](https://captchaai.atlassian.net/wiki/spaces/capsolver/pages/426261/HCaptchaClassification+recognize+the+images+that+you+need+to+click)
- Send a base64 **screenshot image** with `.funcaptchaclassification(image, question)`.
- [**AntiKasadaTask: Solving Kasada.**](https://captchaai.atlassian.net/wiki/spaces/capsolver/pages/426407/AntiKasadaTask+solving+Kasada)
- This task type AntiKasadaTask require that you send us your proxies.
- [**AntiAkamaiBMPTask: Solving Akamai Mobile.**](https://captchaai.atlassian.net/wiki/spaces/capsolver/pages/426407/AntiKasadaTask+solving+Kasada)
- This task type AntiKasadaTask require that you send us your proxies.
**Figure out [here](https://github.com/0qwertyy/capsolver-npm/tree/master/examples) all supported captcha examples.**

@@ -8,8 +8,6 @@ const Tasker = require("./Tasker");

class CapSolver {
constructor(apikey, verbose=0, rqdelay=2500) { this.apikey = apikey; this.verbose = verbose; this.rqdelay = rqdelay; this.init(); }
constructor(apikey, verbose=0, rqdelay=1700) { this.apikey = apikey; this.verbose = verbose; this.rqdelay = rqdelay; this.init(); }
/** * Set-up handler **/
init(){
if(this.verbose === 2){ console.log('[' + this.constructor.name + '][Verbose level '+this.verbose+' running at: '+this.apikey+']'); }
}
init(){ if(this.verbose === 2){ console.log('[' + this.constructor.name + '][Verbose level '+this.verbose+' running at: '+this.apikey+']'); } }

@@ -53,3 +51,2 @@ /** * Return USD balance as float number **/

}
if(this.verbose === 1) { console.log('['+ this.constructor.name +'][proxyInfo]['+proxyInfo.proxyAddress+':'+proxyInfo.proxyPort+']'); }
return tasker;

@@ -62,6 +59,7 @@ }

* @param {object} taskData - taskData schema
* @param retrieve
*/
async runAnyTask(taskData) {
async runAnyTask(taskData, retrieve=true) {
if(taskData.hasOwnProperty('type')){
let tasker = new Tasker(null, this.apikey, this.verbose);
let tasker = new Tasker(null, this.apikey, this.verbose, retrieve);
tasker.taskData = taskData;

@@ -72,12 +70,32 @@ if(taskData.hasOwnProperty('proxyInfo')){ this.attachProxy(tasker, taskData.proxyInfo); }

return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
}else{ throw TypeError('taskData has not type property.'); }
}else{
throw TypeError('taskData has not type property.');
}
}
/** Fast-bind methods **/
/** mtcaptcha **/
async mtcaptcha(websiteURL, websiteKey, proxyInfo){
let tasker = new Tasker('MtCaptchaTask', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.websiteKey = websiteKey;
this.attachProxy(tasker, proxyInfo);
return await tasker.execute(this.rqdelay);
}
/** img2txt **/
async mtcaptchaproxyless(websiteURL, websiteKey){
let tasker = new Tasker('MtCaptchaTaskProxyLess', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.websiteKey = websiteKey;
return await tasker.execute(this.rqdelay);
}
/** img2txt **/
async image2text(body){
let tasker = new Tasker('ImageToTextTask', this.apikey, this.verbose);
let tasker = new Tasker('ImageToTextTask', this.apikey, this.verbose, false);
// binding
tasker.taskData.body = body;
return await tasker.createTask();
return await tasker.execute(this.rqdelay);
}

@@ -94,5 +112,3 @@

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -107,13 +123,10 @@

if(enterprisePayload!==null) { tasker.taskData.isEnterprise = true; tasker.taskData.enterprisePayload = enterprisePayload }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
async hcaptchaclassification(question, base64, coordinate=true){
let tasker = new Tasker('HCaptchaClassification', this.apikey, this.verbose);
async hcaptchaclassification(question, base64){
let tasker = new Tasker('HCaptchaClassification', this.apikey, this.verbose, false);
tasker.taskData.queries = base64;
tasker.taskData.question = question;
tasker.taskData.coordinate = coordinate;
return await tasker.createTask();
return await tasker.execute(this.rqdelay);
}

@@ -131,5 +144,3 @@

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -145,5 +156,3 @@

if(cookies!==null) { tasker.taskData.cookies = cookies }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -160,5 +169,3 @@

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -174,5 +181,3 @@

if(cookies!==null) { tasker.taskData.cookies = cookies; }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -187,5 +192,3 @@

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}

@@ -199,7 +202,32 @@

if(minScore!==null) { tasker.taskData.minScore = minScore; }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
async recaptchav3enterprise(websiteURL, websiteKey, proxyInfo, pageAction, minScore=null, enterprisePayload=null, apiDomain=null, userAgent=null, cookies=null){
let tasker = new Tasker('RecaptchaV3Task', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.websiteKey = websiteKey;
tasker.taskData.pageAction = pageAction;
if(minScore!==null) { tasker.taskData.minScore = minScore; }
if(enterprisePayload!==null) { tasker.taskData.enterprisePayload = enterprisePayload; }
if(apiDomain!==null) { tasker.taskData.apiDomain = apiDomain; }
if(userAgent!==null) { tasker.taskData.userAgent = userAgent; }
if(cookies!==null) { tasker.taskData.cookies = cookies; }
this.attachProxy(tasker, proxyInfo);
return await tasker.execute(this.rqdelay);
}
async recaptchav3enterpriseproxyless(websiteURL, websiteKey, pageAction, minScore=null, enterprisePayload=null, apiDomain=null, userAgent=null, cookies=null){
let tasker = new Tasker('RecaptchaV3TaskProxyless', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.websiteKey = websiteKey;
tasker.taskData.pageAction = pageAction;
if(minScore!==null) { tasker.taskData.minScore = minScore; }
if(enterprisePayload!==null) { tasker.taskData.enterprisePayload = enterprisePayload; }
if(apiDomain!==null) { tasker.taskData.apiDomain = apiDomain; }
if(userAgent!==null) { tasker.taskData.userAgent = userAgent; }
if(cookies!==null) { tasker.taskData.cookies = cookies; }
return await tasker.execute(this.rqdelay);
}
/** datadome **/

@@ -212,9 +240,7 @@ async datadome(websiteURL, userAgent, captchaUrl, proxyInfo){

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
/** funcap **/
async funcaptcha(websiteURL, websitePublicKey, proxyInfo, funcaptchaApiJSSubdomain, userAgent = null, data=null){
async funcaptcha(websiteURL, websitePublicKey, proxyInfo, funcaptchaApiJSSubdomain, userAgent=null, data=null){
let tasker = new Tasker('FunCaptchaTask', this.apikey, this.verbose);

@@ -227,8 +253,6 @@ tasker.taskData.websiteURL = websiteURL;

this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
async funcaptchaproxyless(websiteURL, websitePublicKey, funcaptchaApiJSSubdomain, userAgent = null, data=null){
async funcaptchaproxyless(websiteURL, websitePublicKey, funcaptchaApiJSSubdomain, userAgent=null, data=null){
let tasker = new Tasker('FunCaptchaTaskProxyless', this.apikey, this.verbose);

@@ -240,77 +264,58 @@ tasker.taskData.websiteURL = websiteURL;

if(data!==null) { tasker.taskData.data = data; }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
async funcaptchaclassification(base64, question){
let tasker = new Tasker('FunCaptchaClassification', this.apikey, this.verbose);
let tasker = new Tasker('FunCaptchaClassification', this.apikey, this.verbose, false);
tasker.taskData.image = base64;
tasker.taskData.question = question;
return await tasker.createTask();
return await tasker.execute(this.rqdelay);
}
/** geetest **/
async geetest(websiteURL, gt, challenge, geetestApiServerSubdomain, proxyInfo, version=null, userAgent=null, geetestGetLib=null, initParameters=null){
async geetest(websiteURL, gt=null, challenge=null, proxyInfo, geetestApiServerSubdomain=null, captchaId=null){
let tasker = new Tasker('GeeTestTask', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.gt = gt;
tasker.taskData.challenge = challenge;
tasker.taskData.geetestApiServerSubdomain = geetestApiServerSubdomain;
if(userAgent!==null) { tasker.taskData.userAgent = userAgent; }
if(geetestGetLib!==null) { tasker.taskData.geetestGetLib = geetestGetLib; }
if(version!==null) { tasker.taskData.version = version; }
if(initParameters!==null) { tasker.taskData.initParameters = initParameters; }
if(challenge!==null) { tasker.taskData.challenge = challenge; }
if(gt!==null) { tasker.taskData.gt = gt; }
if(geetestApiServerSubdomain!==null) { tasker.taskData.geetestApiServerSubdomain = geetestApiServerSubdomain; }
if(captchaId!==null) { tasker.taskData.captchaId = captchaId; }
this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
return await tasker.execute(this.rqdelay);
}
async geetestproxyless(websiteURL, gt, challenge, geetestApiServerSubdomain, version=null, userAgent=null, geetestGetLib=null, initParameters=null){
async geetestproxyless(websiteURL, gt=null, challenge=null, geetestApiServerSubdomain=null, captchaId=null){
let tasker = new Tasker('GeeTestTaskProxyless', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.gt = gt;
tasker.taskData.challenge = challenge;
tasker.taskData.geetestApiServerSubdomain = geetestApiServerSubdomain;
if(userAgent!==null) { tasker.taskData.userAgent = userAgent; }
if(geetestGetLib!==null) { tasker.taskData.geetestGetLib = geetestGetLib; }
if(version!==null) { tasker.taskData.version = version; }
if(initParameters!==null) { tasker.taskData.initParameters = initParameters; }
let tasked = await tasker.createTask();
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
if(challenge!==null) { tasker.taskData.challenge = challenge; }
if(gt!==null) { tasker.taskData.gt = gt; }
if(geetestApiServerSubdomain!==null) { tasker.taskData.geetestApiServerSubdomain = geetestApiServerSubdomain; }
if(captchaId!==null) { tasker.taskData.captchaId = captchaId; }
return await tasker.execute(this.rqdelay);
}
/** antikadasa **/
async antikasada(pageURL, proxyInfo, onlyCD=null, userAgent=null){
let tasker = new Tasker('isnotcaptcha', this.apikey, this.verbose);
delete tasker.taskData.type;
tasker.taskData.pageURL = pageURL;
if(onlyCD!==null) { tasker.taskData.onlyCD = onlyCD; }
if(userAgent!==null) { tasker.taskData.userAgent = userAgent; }
/** anticloudflare turnstile captcha **/
async antiturnstile(websiteURL, websiteKey, proxyInfo, metadata=null){
let tasker = new Tasker('AntiCloudflareTask', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
tasker.taskData.websiteKey = websiteKey;
this.attachProxy(tasker, proxyInfo);
let tasked = await tasker.createTask('https://api.capsolver.com/kasada/invoke');
if(tasked.error !== 0) return tasked;
return await tasker.getTaskResult(tasked.apiResponse.taskId, this.rqdelay);
if(metadata!==null) { tasker.taskData.metadata = metadata; }
return await tasker.execute(this.rqdelay);
}
/** antiakamaibmp **/
async antiakamaibmp(packageName, version=null, deviceId=null, deviceName=null, count=null){
let tasker = new Tasker('isnotcaptcha', this.apikey, this.verbose);
delete tasker.taskData.type;
tasker.taskData.packageName = packageName;
if(version!==null) { tasker.taskData.version = version; }
if(deviceId!==null) { tasker.taskData.version = deviceId; }
if(deviceName!==null) { tasker.taskData.version = deviceName; }
if(count!==null) { tasker.taskData.userAgent = count; }
return await tasker.createTask('https://api.capsolver.com/akamaibmp/invoke');
/** anticloudflare challenge **/
async anticloudflare(websiteURL, proxyInfo, metadata=null, html=null){
let tasker = new Tasker('AntiCloudflareTask', this.apikey, this.verbose);
tasker.taskData.websiteURL = websiteURL;
this.attachProxy(tasker, proxyInfo);
if(metadata!==null) { tasker.taskData.metadata = metadata; }
if(html!==null) { tasker.taskData.html = html; }
return await tasker.execute(this.rqdelay);
}
// unsupported methods:
// ❌ ReCaptchaV2Classification
// ✅ HCaptchaClassification (added on 1.2.1)
// ✅ FunCaptchaClassification (added on 1.2.4)
// ✅ AntiKasadaTask (added on 1.2.4)
// ✅ AntiAkamaiBMPTask (added on 1.2.4)
// ❌ ReCaptchaClassification
// ❌ VoiceRecognition
// ❌ Perimeterx

@@ -317,0 +322,0 @@ }

@@ -6,5 +6,6 @@ const Validation = require('./Validation');

class Tasker {
constructor(type, apiKey, verbose) {
constructor(type, apiKey, verbose, retrieve=true) {
this.apikey = apiKey;
this.verbose = verbose;
this.retrieve = retrieve;
this.parameters = new Validation().parameters;

@@ -15,2 +16,15 @@ this.taskData = { 'type' : type };

/**
* executes the task
*/
async execute(rqdelay){
if(this.retrieve === true){
let tasked = await this.createTask();
if(tasked.error !== 0) return tasked;
return await this.getTaskResult(tasked.apiResponse.taskId, rqdelay);
}else{
return await this.createTask();
}
}
/**
* api.capsolver.com/createTask

@@ -22,2 +36,3 @@ */

let req = { url: (url === undefined) ? 'https://api.capsolver.com/createTask' : url, headers: { }, method: 'post', data: { 'clientKey': this.apikey.toString(), 'appId': 'AF0F28E5-8245-49FD-A3FD-43D576C0E9B3', 'task': this.taskData } };
if(this.verbose === 2 ){ console.log(req); }
let handled = await axios(req)

@@ -34,3 +49,3 @@ .then(async function (response) {

});
if(this.verbose !== 0){ console.log('[' + this.taskData.type + ']['+handled.statusText+'][' + req.url + ']'); }
if(this.verbose === 1){ console.log('[' + this.taskData.type + '][created task][' + handled.apiResponse.taskId + ']'); }
return handled;

@@ -42,5 +57,5 @@ }

* @param {string} taskId - associated taskId
* @param {number} rqDelay - retrieve results delay in ms
* @param rqdelay
*/
async getTaskResult(taskId, rqDelay){
async getTaskResult(taskId, rqdelay){
let self = this; let status = ''; let fails = 0; let handled = null;

@@ -51,7 +66,6 @@ if(taskId === undefined) return;

while(status !== 'ready'){
await sleep(rqDelay);
await sleep(rqdelay);
if(fails > 10) break;
handled = await axios(req)
.then(async function (response) {
if(self.verbose === 2){ console.log(requestData); }
if(response.data.errorId !== 0){

@@ -69,5 +83,4 @@ status = response.data.errorDescription;

});
if(this.verbose !== 0)
console.log('[' + this.taskData.type + ']['+handled.statusText+'][api.capsolver.com/getTaskResult][for: ' + (this.taskData.websiteURL ? this.taskData.websiteURL : this.taskData.captchaUrl) + '][taskId: '+taskId+'][status: '+status+']');
if(this.verbose === 2){ console.log(handled.apiResponse)}
if(this.verbose === 1){ console.log('['+taskId+'][status: '+status+']'); }
if(this.verbose === 2){ console.log(handled.apiResponse); }
if(handled.error !== 0) break;

@@ -104,3 +117,2 @@ }

}
// process.exit(1)
return true;

@@ -107,0 +119,0 @@ }

class Validation {
constructor() { // supported api methods
this.parameters = {};
this.parameters.ImageToTextTask =
[ { name:'body', required: true, type: 'string' } ];
[
{ name:'body', required: true, type: 'string' }, { name:'module', required: false, type: 'string' },
{ name:'score', required: false, type: 'number' }, { name:'case', required: false, type: 'boolean' },
];
this.parameters.AwsWafClassification =
[
{ name:'images', required: true, type: 'object' }, { name:'question', required: false, type: 'string' },
{ name:'score', required: false, type: 'number' }, { name:'case', required: false, type: 'boolean' },
];
this.parameters.BinanceCaptchaTask =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'validateId', required: true, type: 'string' }, { name:'proxyType', required: false, type: 'string' },
{ name:'proxyAddress', required: false, type: 'string' }, { name:'proxyPort', required: false, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }
];
this.parameters.MtCaptchaTask = [
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxy', required: false, type: 'string' }, { name:'proxyPassword', required: false, type: 'string' }
];
this.parameters.MtCaptchaTaskProxyLess = [
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' }
];
this.parameters.HCaptchaTask =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'proxyType', required: true, type: 'string' }, { name:'proxyAddress', required: true, type: 'string' },
{ name:'proxyPort', required: true, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'userAgent', required: false, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxy', required: false, type: 'string' }, { name:'proxyPassword', required: false, type: 'string' },
{ name:'isInvisible', required: false, type: 'boolean' }, { name:'isEnterprise', required: false, type: 'boolean' },
{ name:'enterprisePayload', required: false, type: 'object' },
{ name:'enterprisePayload', required: false, type: 'object' }, { name:'userAgent', required: false, type: 'string' }
];
this.parameters.HCaptchaTaskProxyless =

@@ -21,12 +53,18 @@ [

];
this.parameters.HCaptchaClassification = [ { name:'question', required: true, type: 'string' }, { name:'queries', required: true, type: 'object' } ];
this.parameters.HCaptchaClassification =
[
{ name:'question', required: true, type: 'string' }, { name:'queries', required: true, type: 'object' },
];
this.parameters.RecaptchaV2Task =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'proxyType', required: true, type: 'string' }, { name:'proxyAddress', required: true, type: 'string' },
{ name:'proxyPort', required: true, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'userAgent', required: false, type: 'string' },
{ name:'isInvisible', required: false, type: 'boolean' }, { name:'recaptchaDataSValue', required: false, type: 'string' },
{ name:'cookies', required: false, type: 'string' },
{ name:'cookies', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' }
];
this.parameters.RecaptchaV2TaskProxyless =

@@ -38,11 +76,13 @@ [

];
this.parameters.RecaptchaV2EnterpriseTask =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'proxyType', required: true, type: 'string' }, { name:'proxyAddress', required: true, type: 'string' },
{ name:'proxyPort', required: true, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'userAgent', required: false, type: 'string' },
{ name:'enterprisePayload', required: false, type: 'object' }, { name:'apiDomain', required: false, type: 'string' },
{ name:'cookies', required: false, type: 'string' },
{ name:'cookies', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' }
];
this.parameters.RecaptchaV2EnterpriseTaskProxyless =

@@ -55,10 +95,12 @@ [

];
this.parameters.RecaptchaV3Task =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: true, type: 'string' },
{ name:'proxyType', required: true, type: 'string' }, { name:'proxyAddress', required: true, type: 'string' },
{ name:'proxyPort', required: true, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'pageAction', required: true, type: 'string' },
{ name:'minScore', required: false, type: 'number' },
{ name:'minScore', required: false, type: 'number' }, { name:'proxy', required: false, type: 'string' }
];
this.parameters.RecaptchaV3TaskProxyless =

@@ -69,27 +111,31 @@ [

];
this.parameters.ReCaptchaV2Classification = [ { name:'question', required: true, type: 'string' }, { name:'image', required: true, type: 'string' } ];
this.parameters.ReCaptchaV2Classification =
[ { name:'question', required: true, type: 'string' }, { name:'image', required: true, type: 'string' } ];
this.parameters.GeeTestTask =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'gt', required: true, type: 'string' },
{ name:'challenge', required: true, type: 'string' }, { name:'geetestApiServerSubdomain', required: true, type: 'string' },
{ name:'proxyType', required: true, type: 'string' }, { name:'proxyAddress', required: true, type: 'string' },
{ name:'proxyPort', required: true, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'websiteURL', required: true, type: 'string' }, { name:'gt', required: false, type: 'string' },
{ name:'challenge', required: false, type: 'string' }, { name:'geetestApiServerSubdomain', required: false, type: 'string' },
{ name:'proxyType', required: false, type: 'string' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyPort', required: false, type: 'number' }, { name:'proxyLogin', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'userAgent', required: false, type: 'string' },
{ name:'geetestGetLib', required: false, type: 'string' }, { name:'version', required: false, type: 'number' },
{ name:'initParameters', required: false, type: 'object' },
{ name:'captchaId', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' }
];
this.parameters.GeeTestTaskProxyless =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'gt', required: true, type: 'string' },
{ name:'challenge', required: true, type: 'string' }, { name:'geetestApiServerSubdomain', required: true, type: 'string' },
{ name:'userAgent', required: false, type: 'string' }, { name:'geetestGetLib', required: false, type: 'string' },
{ name:'version', required: false, type: 'number' }, { name:'initParameters', required: false, type: 'object' },
{ name:'websiteURL', required: true, type: 'string' }, { name:'gt', required: false, type: 'string' },
{ name:'challenge', required: false, type: 'string' }, { name:'geetestApiServerSubdomain', required: false, type: 'string' },
{ name:'userAgent', required: false, type: 'string' }, { name:'captchaId', required: false, type: 'string' }
];
this.parameters.DataDomeSliderTask =
[
{ name:'websiteURL', required: true, type: 'string' }, { name:'captchaUrl', required: true, type: 'string' },
{ name:'userAgent', required: true, type: 'string' }, { name:'proxyType', required: true, type: 'string' },
{ name:'proxyAddress', required: true, type: 'string' }, { name:'proxyPort', required: true, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxyPassword', required: false, type: 'string' },
{ name:'userAgent', required: true, type: 'string' }, { name:'proxyType', required: false, type: 'string' },
{ name:'proxyAddress', required: false, type: 'string' }, { name:'proxyPort', required: false, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' },
];
this.parameters.FunCaptchaTask =

@@ -99,8 +145,14 @@ [

{ name:'funcaptchaApiJSSubdomain', required: true, type: 'string' }, { name:'data', required: false, type: 'string' },
{ name:'userAgent', required: false, type: 'string' }, { name:'proxyType', required: true, type: 'string' },
{ name:'proxyAddress', required: true, type: 'string' }, { name:'proxyPort', required: true, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxyPassword', required: false, type: 'string' },
{ name:'userAgent', required: false, type: 'string' }, { name:'proxyType', required: false, type: 'string' },
{ name:'proxyAddress', required: false, type: 'string' }, { name:'proxyPort', required: false, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' },
];
this.parameters.FunCaptchaClassification =
[ { name:'image', required: true, type: 'string' }, { name:'question', required: true, type: 'string' }, ];
[
{ name:'image', required: true, type: 'string' },
{ name:'question', required: true, type: 'string' },
];
this.parameters.FunCaptchaTaskProxyless =

@@ -113,18 +165,12 @@ [

this.parameters.AntiKasadaTask =
// beta
this.parameters.AntiCloudflareTask =
[
{ name:'pageURL', required: true, type: 'string' }, { name:'onlyCD', required: false, type: 'string' },
{ name:'userAgent', required: false, type: 'string' },
{ name:'proxyAddress', required: true, type: 'string' }, { name:'proxyPort', required: true, type: 'number' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxyPassword', required: false, type: 'string' },
{ name:'websiteURL', required: true, type: 'string' }, { name:'websiteKey', required: false, type: 'string' },
{ name:'metadata', required: false, type: 'object' }, { name:'proxyAddress', required: false, type: 'string' },
{ name:'proxyLogin', required: false, type: 'string' }, { name:'proxy', required: false, type: 'string' },
{ name:'proxyPassword', required: false, type: 'string' }, { name:'proxyPort', required: false, type: 'number' },
];
this.parameters.AntiAkamaiBMPTask =
[
{ name:'packageName', required: true, type: 'string' }, { name:'version', required: false, type: 'string' },
{ name:'deviceId', required: false, type: 'string' }, { name:'deviceName', required: false, type: 'string' },
{ name:'count', required: false, type: 'string' }
];
}
}
module.exports = Validation
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc