2025-01-18 13:46:25 +00:00
# Invisible mode
You can use `new Cap({ ... })` in your client-side JavaScript to create a new Cap instance and use the `solve()` method to solve the challenge. This is helpful for situations where you don't want the Cap widget to be visible but still want security, e.g. on a social media app when posting something.
```js
const cap = new Cap ({
apiEndpoint : "/api/"
});
2025-04-12 13:39:56 +01:00
const solution = await cap . solve ();
console . log ( solution . token );
2025-01-18 13:46:25 +00:00
```
2025-04-12 13:39:56 +01:00
You can also set up [event listeners ](widget.md#supported-events ):
```js
const cap = new Cap ({
apiEndpoint : "/api/"
});
cap . addEventListener ( "progress" , ( event ) => { // [!code focus]
console . log ( `Solving... ${ event . detail . progress } % done` ); // [!code focus]
}); // [!code focus]
```
Behind the scenes, Cap creates a hidden `cap-widget` element and uses it to solve the challenge.
2025-01-18 13:46:25 +00:00
## Supported methods and arguments
The following methods are supported:
#### `new Cap({ ... })`
2025-01-18 14:36:36 +00:00
Creates a new Cap instance. If a 2nd argument is provided, it will use that element instead of creating a new one in memory.
2025-01-18 13:46:25 +00:00
**Arguments**
```json
{
apiEndpoint: ..., // api endpoint, similiar to the widget `data-cap-api-endpoint` attribute
workers: navigator.hardwareConcurrency || 8 // number of worker threads to use
}
```
#### `cap.solve()`
Requests and solves a challenge.
**Output:** `{ token }`
#### `cap.token`
Returns the token from the latest solve
#### `cap.reset()`
Resets `cap.token`
#### `cap.addEventListener(..., function () { ... })`
2025-04-12 13:39:56 +01:00
Listens for an event for the cap widget. See [supported events ](widget.md#supported-events )