add custom fetch and docs improvements
This commit is contained in:
@@ -108,6 +108,7 @@ export default defineConfig({
|
||||
{ text: "Quickstart", link: "/guide/index.md" },
|
||||
{ text: "Effectiveness", link: "/guide/effectiveness.md" },
|
||||
{ text: "Alternatives", link: "/guide/alternatives.md" },
|
||||
{ text: "Philosophy", link: "/guide/philosophy.md" },
|
||||
{
|
||||
text: "Modes",
|
||||
items: [
|
||||
@@ -124,6 +125,7 @@ export default defineConfig({
|
||||
{ text: "@cap.js/solver", link: "/guide/solver.md" },
|
||||
],
|
||||
},
|
||||
{ text: "Benchmark", link: "/guide/benchmark.md" },
|
||||
{ text: "Demo", link: "https://cap-starter.glitch.me/" },
|
||||
],
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
# Benchmark
|
||||
|
||||
Coming soon!
|
||||
|
||||
<!--
|
||||
Press the button below to run a simple benchmark.
|
||||
|
||||
<style>
|
||||
.benchmark-form {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 1rem;
|
||||
max-width: 300px;
|
||||
padding: 16px;
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
.benchmark-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.benchmark-field label {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
margin-bottom: 0.2rem;
|
||||
opacity: .9;
|
||||
}
|
||||
.benchmark-field input {
|
||||
padding: 0.5rem .8rem;
|
||||
border-radius: 6px;
|
||||
background-color: var(--vp-sidebar-bg-color);
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
font-size: 16px;
|
||||
font-family: inherit;
|
||||
}
|
||||
.benchmark-field input:focus {
|
||||
border-color: var(--vp-c-brand-1);
|
||||
outline: none;
|
||||
}
|
||||
.benchmark-form button {
|
||||
background-color: var(--vp-c-brand-1);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: white;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 6px;
|
||||
transition: background-color 0.2s ease;
|
||||
}
|
||||
|
||||
.benchmark-form button:hover {
|
||||
background-color: var(--vp-c-brand-2);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="benchmark-form">
|
||||
<div class="benchmark-field">
|
||||
<label for="difficulty">Challenge difficulty</label>
|
||||
<input type="number" id="difficulty" name="difficulty" min="1" max="10" value="4">
|
||||
</div>
|
||||
<div class="benchmark-field">
|
||||
<label for="challenges">Number of challenges</label>
|
||||
<input type="number" id="challenges" name="challenges" min="1" max="100" value="5">
|
||||
</div>
|
||||
<div class="benchmark-field">
|
||||
<label for="workers">Number of workers</label>
|
||||
<input type="number" id="workers" name="workers" min="1" max="28" value="8">
|
||||
</div>
|
||||
<button>Run</button>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.window.CAP_CUSTOM_FETCH = function (a, b) {
|
||||
console.log({ a, b});
|
||||
|
||||
return fetch(a, b);
|
||||
}
|
||||
|
||||
console.log("hi");
|
||||
</script>
|
||||
-->
|
||||
@@ -0,0 +1,15 @@
|
||||
# Philosophy
|
||||
|
||||
Most CAPTCHA systems today are built around surveillance — tracking users, fingerprinting browsers, and collecting data in exchange for access. Cap rejects that model.
|
||||
|
||||
Cap is designed around a few core ideas:
|
||||
|
||||
- **Privacy by default** — no trackers, no third-party requests, no hidden profiling.
|
||||
- **Simplicity over complexity** — no image labeling, no click-the-fire-hydrant puzzles.
|
||||
- **Speed matters** — fast to render, fast to solve, fast to validate.
|
||||
- **User-first** — designed to be unintrusive and accessible, with invisible and floating modes.
|
||||
- **Self-hostable, not centralized** — you control the infra, tokens, and behavior.
|
||||
|
||||
By using proof-of-work instead of user behavior analysis, Cap shifts the burden from identity to computation. That means anyone can prove they’re human — no cookies, no accounts, no friction.
|
||||
|
||||
Cap is what a CAPTCHA should’ve been all along: **simple, honest, and yours.**
|
||||
@@ -59,3 +59,13 @@ The following custom events are supported:
|
||||
- `error`: Triggered when an error occurs.
|
||||
- `reset`: Triggered when the widget is reset.
|
||||
- `progress`: Triggered when the there's a progress update while in verification.
|
||||
|
||||
## Custom fetch
|
||||
You can override the default fetch implementation by setting `window.CAP_CUSTOM_FETCH` to a custom function. This function will receive the URL and options as arguments and should return a promise that resolves to the response.
|
||||
|
||||
```js
|
||||
window.CAP_CUSTOM_FETCH = function (url, options) {
|
||||
// Custom fetch implementation
|
||||
return fetch(url, options);
|
||||
};
|
||||
```
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@cap.js/widget",
|
||||
"version": "0.0.21",
|
||||
"version": "0.0.22",
|
||||
"description": "Client-side widget for Cap. Cap is a lightweight, modern open-source CAPTCHA alternative designed using SHA-256 PoW.",
|
||||
"keywords": [
|
||||
"account security",
|
||||
|
||||
+10
-3
@@ -1,6 +1,13 @@
|
||||
(function () {
|
||||
let workerScript;
|
||||
|
||||
const capFetch = function () {
|
||||
if (window?.CAP_CUSTOM_FETCH) {
|
||||
return window.CAP_CUSTOM_FETCH(...arguments);
|
||||
}
|
||||
return fetch(...arguments);
|
||||
};
|
||||
|
||||
const until = (predFn, timeout = 10000) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeoutId = setTimeout(() => {
|
||||
@@ -124,14 +131,14 @@
|
||||
if (!apiEndpoint) throw new Error("Missing API endpoint");
|
||||
|
||||
const { challenge, token } = await (
|
||||
await fetch(`${apiEndpoint}challenge`, {
|
||||
await capFetch(`${apiEndpoint}challenge`, {
|
||||
method: "POST",
|
||||
})
|
||||
).json();
|
||||
const solutions = await this.solveChallenges(challenge);
|
||||
|
||||
const resp = await (
|
||||
await fetch(`${apiEndpoint}redeem`, {
|
||||
await capFetch(`${apiEndpoint}redeem`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ token, solutions }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
@@ -527,7 +534,7 @@
|
||||
setTimeout(async function () {
|
||||
workerScript =
|
||||
(await (
|
||||
await fetch(
|
||||
await capFetch(
|
||||
"https://cdn.jsdelivr.net/npm/@cap.js/widget/wasm-hashes.min.js"
|
||||
)
|
||||
).text()) +
|
||||
|
||||
Reference in New Issue
Block a user