Files
cap/docs/guide/cli.md
T

78 lines
2.1 KiB
Markdown
Raw Normal View History

2025-04-22 19:48:04 +01:00
# @cap.js/cli
`cli` is a simple command-line interface for solving CAPTCHAs made with Cap. It's mainly designed for testing and when you need to solve these CAPTCHAs in a browser without JavaScript support.
```bash
bunx @cap.js/cli
```
```
@cap.js/cli cli solver for cap challenges
Usage:
2025-04-22 20:21:35 +01:00
$ bunx '@cap.js/cli' <challenges>
2025-04-22 19:48:04 +01:00
Options:
<challenges> The challenges to solve in
format `salt:target`
```
2025-04-22 20:21:35 +01:00
> [!NOTE]
> We recommend using `bunx '@cap.js/cli'` instead of `bunx @cap.js/cli` to avoid issues with the `@` symbol in the package name in some shells.
2025-04-22 19:48:04 +01:00
## Usage
To use `cli`, you need to pass the challenges to solve in the format `salt:target`, separated by a space. For example:
```bash
2025-04-22 20:21:35 +01:00
bunx '@cap.js/cli' e455cea65e98b:dceb fb8d25f6abac:93f1 ...
2025-04-22 19:48:04 +01:00
```
```
@cap.js/cli 2 challenges
e455cea65e98b:dceb:9100
fb8d25f6abac:93f1:76570
...
```
The output format is `salt:target:nonce`, where `nonce` is the solution nonce. You can then turn this into JSON to send to the Cap server helper:
```js
const input = "e455cea65e98b:dceb:9100\nfb8d25f6abac:93f1:76570";
console.log(input.split("\n").map((l) => l.split(":")));
```
```json
[
["e455cea65e98b", "dceb", "9100"],
["fb8d25f6abac", "93f1", "76570"]
]
```
## Generating the command
You can generate code to call `cap.js/cli` from the challenges using this:
```js
const response = {
"challenge": [
[ "e455cea65e98b", "dceb" ],
[ "fb8d25f6abac", "93f1" ],
...
],
"token": "...",
"expires": 1745343553913
};
const challenges = response.challenge.map((c) => c.join(":")).join(" ");
2025-04-22 20:21:35 +01:00
const command = `bunx '@cap.js/cli' ${challenges}`;
2025-04-22 19:48:04 +01:00
2025-04-22 20:21:35 +01:00
console.log(command); // bunx '@cap.js/cli' e455cea65e98b:dceb fb8d25f6abac:93f1 ...
2025-04-22 19:48:04 +01:00
```
> [!NOTE]
2025-04-22 20:15:06 +01:00
> The code above doesn't validate if the challenges are valid and not potentially malicious. If you're getting the challenge list from an untrusted source, make sure to validate it before giving them to the user.
Here's a simple <a href="https://cap-cli-challenges.glitch.me/" target="_blank">Glitch app</a> that generates and validats challenges for you. You can use it to test the CLI and see how it works.