Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2d5f46d
feat: add client debug mode
dariyaanis Nov 12, 2026
58dfee8
feat: expand debug lifecycle logging
dariyaanis Nov 12, 2026
c264312
docs: explain example execution flows
dariyaanis Nov 12, 2026
bae5310
docs: print Kaleidoscope result as JSON
dariyaanis Nov 12, 2026
82b6145
feat: log sanitized server exchanges
dariyaanis Nov 12, 2026
a0f6c38
test: enforce debug response ordering
dariyaanis Nov 12, 2026
aa2a270
feat: add final solve debug summary
dariyaanis Nov 12, 2026
f6f7f88
feat: show readable solve duration
dariyaanis Nov 12, 2026
533ff4b
feat: label server exchanges as JSON blocks
dariyaanis Nov 12, 2026
9901b81
feat: harden structured debug logging
dariyaanis Nov 12, 2026
c7657e3
docs: enable debug directly in Kaleidoscope example
dariyaanis Nov 12, 2026
96294e1
feat: add concise and trace debug modes
dariyaanis Nov 12, 2026
8229848
feat: format debug output as Linux-style lines
dariyaanis Nov 12, 2026
ca39e95
feat: improve concise debug readability
dariyaanis Nov 12, 2026
f53a858
Revert "feat: improve concise debug readability"
dariyaanis Nov 12, 2026
280ceaa
Revert "feat: format debug output as Linux-style lines"
dariyaanis Nov 12, 2026
6e45217
Revert "feat: add concise and trace debug modes"
dariyaanis Nov 12, 2026
b239ffc
Revert "docs: enable debug directly in Kaleidoscope example"
dariyaanis Nov 12, 2026
f2d2893
Revert "feat: harden structured debug logging"
dariyaanis Nov 12, 2026
2b777a9
docs: align README with current SDK
dariyaanis Nov 12, 2026
88893ef
feat: compact timestamped debug output
dzmitry-duboyski Nov 12, 2026
0af2871
feat: always pair debug REQUEST with a RESPONSE line
dzmitry-duboyski Nov 12, 2026
f2bf4fa
feat: show request duration in debug RESPONSE
dzmitry-duboyski Nov 12, 2026
5f5f1cc
docs: add debug mode example, disable debug in Kaleidoscope example
dzmitry-duboyski Nov 12, 2026
69382fd
feat: mask proxyAddress in debug output
dzmitry-duboyski Nov 12, 2026
95d99fe
feat: explain missing taskId in SOLVE SUMMARY
dzmitry-duboyski Nov 12, 2026
1ae1355
test: cover debug output for HTTP errors, invalid JSON and solve timeout
dzmitry-duboyski Nov 12, 2026
84f15f4
fix: tell a timed-out response body apart from invalid JSON in debug log
dzmitry-duboyski Nov 12, 2026
60a3faa
fix: never let debug output change request results
dzmitry-duboyski Nov 12, 2026
4e513cb
docs: align debug guide with runnable example
dariyaanis Nov 13, 2026
ddabe0e
docs: shorten debug mode guide
dariyaanis Nov 13, 2026
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
51 changes: 40 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ Full API reference (all endpoints, error codes, captcha-type details): **https:/
- [Image to Text](#image-to-text)
- [GeeTest (v3 & v4)](#geetest-v3--v4)
- [Yandex SmartCaptcha](#yandex-smartcaptcha)
- [Kaleidoscope puzzle](#kaleidoscope-puzzle)
- [Coordinates (click captcha)](#coordinates-click-captcha)
- [Tencent](#tencent)
- [Advanced Usage](#advanced-usage)
- [Check balance](#check-balance)
- [Custom timeout and polling](#custom-timeout-and-polling)
- [Debug mode](#debug-mode)
- [Worker language pool](#worker-language-pool)
- [Solving multiple captchas in parallel](#solving-multiple-captchas-in-parallel)
- [Error handling](#error-handling)
Expand Down Expand Up @@ -162,8 +164,9 @@ Constructor. Takes a single options object.
|---|---|---|---|
| `clientKey` | `string` | required | Your Captcha Solver API key. Throws `ValidationError` if empty. |
| `baseUrl` | `string` | `https://api.captcha-solver.com` | API base URL. Override only for self-hosted/staging deployments. |
| `timeout` | `number` | `120000` | Default max milliseconds `solve()` waits for a solution before throwing `TimeoutError`. |
| `timeout` | `number` | `120000` | Per-request HTTP timeout and polling time budget used by `solve()`. |
| `pollingInterval` | `number` | `5000` | Milliseconds between `getTaskResult` polls inside `solve()`. |
| `debug` | `boolean` | `false` | Print timestamped, sanitized request and `solve()` diagnostics with `console.debug`. See [Debug mode](#debug-mode). |

There's no manual connection pool to open or close -- `fetch` (via Node's built-in
`undici`) already reuses keep-alive connections per host automatically, unlike Python's
Expand All @@ -179,28 +182,30 @@ solution -- wraps `createTask()` + `getTaskResult()` so you don't poll by hand.
| `task` | task object | One of the classes from `Tasks` (see [Captcha Types](#captcha-types)). |
| `languagePool` | `string \| null` | Optional worker pool selector, `'en'` or `'ru'`. Defaults to `null` (account default pool). |

Returns a `Promise` resolving to the `solution` object once `status` is `'ready'` --
its shape depends on the task type (see [Captcha Types](#captcha-types)).
Returns a `Promise` resolving to the task-specific `solution` value once `status` is
`'ready'`. Most tasks return an object; Yandex SmartCaptcha Kaleidoscope returns a
string. See [Captcha Types](#captcha-types) for each result format.
Rejects with `ApiError`, `TimeoutError`, or `NetworkError`.

### `createTask(task, languagePool)`

Submits `task` and returns a `Promise` resolving to its numeric task ID, without
waiting for a solution. Same parameters as `solve()`. Use this instead of `solve()`
only if you need to manage polling yourself (e.g. checking on many tasks from a
different process). Rejects with `ApiError`, `NetworkError`.
different process). Rejects with `ApiError`, `TimeoutError`, or `NetworkError`.

### `getTaskResult(taskId)`

Fetches the current status of a task created with `createTask()`. Resolves to an
object with a `status` key (`'processing'` or `'ready'`); when `'ready'`, also has a
`solution` object. This is a single poll, not a wait -- call it repeatedly (as
`solve()` does) until `status` is `'ready'`. Rejects with `ApiError`, `NetworkError`.
Fetches the current status of a task created with `createTask()`. Resolves to the API
response with a `status` key (`'processing'` or `'ready'`); when `'ready'`, it also
has a task-specific `solution` value. This is a single poll, not a wait -- call it
repeatedly (as `solve()` does) until `status` is `'ready'`. Rejects with `ApiError`,
`TimeoutError`, or `NetworkError`.

### `getBalance()`

Returns a `Promise` resolving to the account's current balance (`number`) in the
account's currency. Rejects with `ApiError`, `NetworkError`.
account's currency. Rejects with `ApiError`, `TimeoutError`, or `NetworkError`.

## Captcha Types

Expand Down Expand Up @@ -677,6 +682,26 @@ const captchaSolver = new CaptchaClient({
});
```

### Debug mode

Enable `debug` to inspect how the SDK communicates with the API. It logs timestamped
requests, server responses, errors, request duration, task status, and a final
`solve()` summary with the task ID, elapsed time, and poll count.

```javascript
// Create a client with sanitized debug logging enabled.
const captchaSolver = new CaptchaClient({
clientKey: 'your_api_key',
debug: true
});
```

Credentials and cookies are masked, base64 images are replaced with their length,
and long strings are shortened. Review logs before sharing them because URLs and
custom task fields may still contain application-specific data.

See [examples/debug_mode.js](examples/debug_mode.js) for a runnable example.

### Worker language pool

Pass `languagePool` as the second argument to `solve()` (or `createTask()`) to pick a
Expand Down Expand Up @@ -756,9 +781,12 @@ matches this README.

## Running the examples

- **Image/click captchas** (`image_to_text.js`, `coordinates.js`) run end-to-end
- **Image/click captchas** (`image_to_text.js`, `image_to_text_math.js`,
`image_to_text_language_pool.js`, `coordinates.js`, `coordinates_traffic_lights.js`,
`yandex_smartcaptcha_image.js`, `yandex_smartcaptcha_kaleidoscope.js`, `debug_mode.js`) run end-to-end
with nothing but a valid `CAPTCHA_API_KEY` -- they read sample images bundled in
[examples/assets](examples/assets), no target page needed.
- **Token captchas** (`recaptcha_v2.js`, `recaptcha_v2_enterprise.js`, `recaptcha_v3.js`,
`turnstile.js`, `yandex_smartcaptcha.js`, `geetest_v4.js`, `tencent.js`) use
placeholder values (`https://example.com/...`, `YOUR_WEBSITE_KEY`, `YOUR_APP_ID`,
`YOUR_CAPTCHA_ID`) -- replace these with the real values from your own target
Expand All @@ -779,14 +807,15 @@ export CAPTCHA_API_KEY=your_api_key
node examples/balance.js
node examples/image_to_text.js
node examples/coordinates.js
node examples/debug_mode.js
```

Full details, an example index, and a per-type breakdown of what each script
covers live in [examples/README.md](examples/README.md).

## Requirements

- Node.js 18 or newer. Modern browser with fetch support.
- Node.js 18 or newer. The repository examples also rely on Node.js APIs and `dotenv`.
- Captcha Solver account with a valid API key.

## API Documentation
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Additional one-scenario examples:
- [`image_to_text_math.js`](image_to_text_math.js) — math CAPTCHA with an instruction image.
- [`image_to_text_language_pool.js`](image_to_text_language_pool.js) — select the English worker pool.
- [`coordinates_traffic_lights.js`](coordinates_traffic_lights.js) — click coordinates with an instruction image.
- [`debug_mode.js`](debug_mode.js) — enable `debug: true` and watch the SDK's request, response and solve summary log.

> **Important:** `geetest_v3.js` and `geetest_v3_proxy.js` contain a placeholder
> initialization endpoint. Replace it with the target website's endpoint and
Expand Down
23 changes: 13 additions & 10 deletions examples/balance.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
import 'dotenv/config';
import { CaptchaClient } from '@captcha-solver-api/javascript-sdk';

/**
* Example: Get account balance.
* Check the current Captcha Solver account balance without creating a CAPTCHA task.
* Set the CAPTCHA_API_KEY environment variable before running this example.
*
* Prerequisites:
* Set the CAPTCHA_API_KEY environment variable.
* Returns the current available balance of your account.
* How it works:
* STEP-01 - Read the API key and configure the SDK client.
* STEP-02 - Request the account balance with CaptchaClient.getBalance().
* STEP-03 - Print the returned amount or report an error.
*/

import 'dotenv/config';
import { CaptchaClient } from '@captcha-solver-api/javascript-sdk';

// STEP-01: Read the API key and configure the SDK client.
const apiKey = process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY';

const captchaSolver = new CaptchaClient({ clientKey: apiKey });

// Get the current account balance.
// Returns a float with the available amount in your account currency.
// STEP-02: Request the balance; this method does not create a CAPTCHA task.
captchaSolver.getBalance()
.then((balance) => {
// STEP-03: Print the available amount in the account currency.
console.log('Balance:', balance);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
29 changes: 27 additions & 2 deletions examples/coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,37 @@ import 'dotenv/config';
import fs from 'fs';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';

/**
* Solve a coordinate CAPTCHA from a local image without a proxy.
* It creates Tasks.CoordinatesTask from the shown parameters, submits it with
* CaptchaClient.solve(), and prints the relevant returned value. Applying that value to a
* target page is site-specific. Replace all target-specific placeholders before running.
*
* How it works:
* STEP-01 - Configure the SDK client.
* STEP-02 - Create the CAPTCHA task from the required parameters or local assets.
* STEP-03 - Submit the task and wait for CaptchaClient.solve() to return the solution.
* STEP-04 - Print the relevant solution value or report an error.
*/


// STEP-01: Configure the SDK client with the API key.
const client = new CaptchaClient({ clientKey: process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY' });

// STEP-02: Create the CAPTCHA task with the values required by this challenge.
const task = new Tasks.CoordinatesTask({
body: fs.readFileSync(new URL('./assets/coordinates-captcha.png', import.meta.url)).toString('base64'),
comment: 'Click on the green apple'
});


// STEP-03: Submit the task; solve() handles task creation and polling.
client.solve(task)
.then((solution) => console.log(solution.coordinates))
.catch(console.error);
.then((solution) => {
// STEP-04: Print only the useful field returned for this CAPTCHA type.
console.log(solution.coordinates);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
29 changes: 27 additions & 2 deletions examples/coordinates_traffic_lights.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,39 @@ import 'dotenv/config';
import fs from 'fs';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';

/**
* Solve an instruction-image coordinate CAPTCHA without a proxy.
* It creates Tasks.CoordinatesTask from the shown parameters, submits it with
* CaptchaClient.solve(), and prints the relevant returned value. Applying that value to a
* target page is site-specific. Replace all target-specific placeholders before running.
*
* How it works:
* STEP-01 - Configure the SDK client.
* STEP-02 - Create the CAPTCHA task from the required parameters or local assets.
* STEP-03 - Submit the task and wait for CaptchaClient.solve() to return the solution.
* STEP-04 - Print the relevant solution value or report an error.
*/


// STEP-01: Configure the SDK client with the API key.
const client = new CaptchaClient({ clientKey: process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY' });

// STEP-02: Create the CAPTCHA task with the values required by this challenge.
const task = new Tasks.CoordinatesTask({
body: fs.readFileSync(new URL('./assets/traffic-lights.png', import.meta.url)).toString('base64'),
imgInstructions: fs.readFileSync(new URL('./assets/traffic-lights-instructions.png', import.meta.url)).toString('base64'),
minClicks: 1,
maxClicks: 5
});


// STEP-03: Submit the task; solve() handles task creation and polling.
client.solve(task)
.then((solution) => console.log(solution.coordinates))
.catch(console.error);
.then((solution) => {
// STEP-04: Print only the useful field returned for this CAPTCHA type.
console.log(solution.coordinates);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
46 changes: 46 additions & 0 deletions examples/debug_mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'dotenv/config';
import fs from 'fs';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';

/**
* Debug mode: watch every API request, server response and the final solve summary.
* It enables `debug: true`, solves a text CAPTCHA from a bundled image with
* CaptchaClient.solve(), and prints the recognized text. The `[CaptchaClient] ...`
* lines are the SDK's debug log; the last line is printed by this example.
* Credentials in the log are shown as [MASKED], so the output is safe to share.
*
* How it works:
* STEP-01 - Configure the SDK client with debug logging enabled.
* STEP-02 - Create the CAPTCHA task from a local image.
* STEP-03 - Submit the task; the SDK logs each request and a SOLVE SUMMARY.
* STEP-04 - Print the solution or report an error.
*/

if (!process.env.CAPTCHA_API_KEY) {
throw new Error('Set CAPTCHA_API_KEY in .env or in the current shell before running this example.');
}

// STEP-01: Configure the SDK client; debug: true turns on the debug log.
const client = new CaptchaClient({
clientKey: process.env.CAPTCHA_API_KEY,
debug: true
});

// STEP-02: Create the CAPTCHA task from the bundled sample image.
const task = new Tasks.ImageToText({
body: fs.readFileSync(new URL('./assets/text-captcha.png', import.meta.url)).toString('base64'),
numeric: 2,
minLength: 4,
maxLength: 6
});

// STEP-03: Submit the task; solve() handles task creation and polling and logs each step.
client.solve(task)
.then((solution) => {
// STEP-04: Print the result returned by solve(), after the SDK's SOLVE SUMMARY.
console.log('Result:', solution.text);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
39 changes: 32 additions & 7 deletions examples/geetest_v3.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,39 @@
import 'dotenv/config';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';

/**
* Solve GeeTest v3 with a challenge fetched from the target site and without a proxy.
* It creates Tasks.GeeTestProxyless from the shown parameters, submits it with
* CaptchaClient.solve(), and prints the relevant returned value. Applying that value to a
* target page is site-specific. Replace all target-specific placeholders before running.
*
* How it works:
* STEP-01 - Configure the SDK client.
* STEP-02 - Fetch the current challenge from the target site's GeeTest endpoint.
* STEP-03 - Create and submit the task, then wait for CaptchaClient.solve().
* STEP-04 - Print the relevant solution value or report an error.
*/


// STEP-01: Configure the SDK client with the API key.
const client = new CaptchaClient({ clientKey: process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY', timeout: 300000 });

// STEP-02: Fetch the dynamic challenge immediately before creating the task.
fetch('https://target-site.com/path/to/geetest/init')
.then((response) => response.json())
.then(({ challenge }) => client.solve(new Tasks.GeeTestProxyless({
websiteURL: 'https://example.com/login',
gt: 'YOUR_GT_KEY',
challenge
})))
.then((solution) => console.log(solution))
.catch(console.error);
.then(({ challenge }) => {
// STEP-03: Submit a task that uses the fresh challenge returned by the target site.
return client.solve(new Tasks.GeeTestProxyless({
websiteURL: 'https://example.com/login',
gt: 'YOUR_GT_KEY',
challenge
}));
})
.then((solution) => {
// STEP-04: Print only the useful field returned for this CAPTCHA type.
console.log(solution);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
45 changes: 35 additions & 10 deletions examples/geetest_v3_proxy.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import 'dotenv/config';
import { CaptchaClient, Tasks } from '@captcha-solver-api/javascript-sdk';

/**
* Solve GeeTest v3 with a challenge fetched from the target site and a customer proxy.
* It creates Tasks.GeeTest from the shown parameters, submits it with
* CaptchaClient.solve(), and prints the relevant returned value. Applying that value to a
* target page is site-specific. Replace all target-specific placeholders before running.
*
* How it works:
* STEP-01 - Configure the SDK client.
* STEP-02 - Fetch the current challenge from the target site's GeeTest endpoint.
* STEP-03 - Create and submit the proxied task, then wait for CaptchaClient.solve().
* STEP-04 - Print the relevant solution value or report an error.
*/


// STEP-01: Configure the SDK client with the API key.
const client = new CaptchaClient({ clientKey: process.env.CAPTCHA_API_KEY || 'YOUR_API_KEY', timeout: 300000 });

// STEP-02: Fetch the dynamic challenge immediately before creating the task.
fetch('https://target-site.com/path/to/geetest/init')
.then((response) => response.json())
.then(({ challenge }) => client.solve(new Tasks.GeeTest({
websiteURL: 'https://example.com/login',
gt: 'YOUR_GT_KEY',
challenge,
proxyType: 'http',
proxyAddress: '1.2.3.4',
proxyPort: 8080
})))
.then((solution) => console.log(solution))
.catch(console.error);
.then(({ challenge }) => {
// STEP-03: Submit a proxied task with the fresh challenge returned by the target site.
return client.solve(new Tasks.GeeTest({
websiteURL: 'https://example.com/login',
gt: 'YOUR_GT_KEY',
challenge,
proxyType: 'http',
proxyAddress: '1.2.3.4',
proxyPort: 8080
}));
})
.then((solution) => {
// STEP-04: Print only the useful field returned for this CAPTCHA type.
console.log(solution);
})
.catch((error) => {
// Report SDK or transport failures without hiding the rejected Promise.
console.error(error);
});
Loading