Files
cap/docs/guide/cli.md
T
2025-05-30 19:57:40 +01:00

76 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# @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:
$ bunx '@cap.js/cli' <challenges>
Options:
<challenges> The challenges to solve in
format `salt:target`
```
If you're on Windows, you might need to use `bunx '@cap.js/cli'` (with quotes) instead of `bunx @cap.js/cli` to avoid issues with the `@` symbol.
## Usage
To use `cli`, you need to pass the challenges to solve in the format `salt:target`, separated by a space. For example:
```bash
bunx '@cap.js/cli' e455cea65e98b:dceb fb8d25f6abac:93f1 ...
```
```
@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(" ");
const command = `bunx '@cap.js/cli' ${challenges}`;
console.log(command); // bunx '@cap.js/cli' e455cea65e98b:dceb fb8d25f6abac:93f1 ...
```
::: warning
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.
:::