Everything the front end can do: the script tag, the <aloscaptcha-widget> element, its
attributes, the verified event, and how the token reaches your form.
There is no hosted file to include. You paste the widget code directly into your page once. The full copy-paste snippet is in Getting Started. It defines the <aloscaptcha-widget> element and fetches the encrypted challenge itself via a POST to /api/aloscaptcha/challenge.
Nothing to configure. The snippet already points at the fixed API endpoint:
var ALOSCAPTCHA_API = "https://alos.gg";
Paste the widget code once per page (for example just before </body>) and set your site key on each <aloscaptcha-widget>. They render automatically.
Place the element wherever the challenge should appear, inside the <form> you want to protect:
<aloscaptcha-widget data-sitekey="aloscap_pub_XXXXXXXX"></aloscaptcha-widget>
The widget renders inside a closed shadow root, so its markup and styles never collide with your page’s CSS.
| Attribute | Default | Description |
|---|---|---|
data-sitekey | required | Your public site key (aloscap_pub_…). |
data-input-name | aloscaptcha-token | Name of the hidden input the token is written into. |
data-callback | none | Name of a global function called with the token on success. |
When the user solves the challenge, the widget looks for the nearest <form> and adds (or fills) a hidden input:
<input type="hidden" name="aloscaptcha-token" value="<token>">
On a normal form submit, the token is sent with your other fields, with nothing else to wire up. Pass it to siteverify on your server.
For custom flows (AJAX submits, SPAs), react to the token directly. Use a named callback:
<aloscaptcha-widget data-sitekey="aloscap_pub_XXXX" data-callback="onCaptcha"></aloscaptcha-widget> <script> function onCaptcha(token) { fetch("/login", { method: "POST", body: JSON.stringify({ token: token }) }); } </script>
Or listen for the aloscaptcha-verified event, which bubbles and is composed:
document.addEventListener("aloscaptcha-verified", function (e) { console.log("token:", e.detail.token); });
A token is single-use: siteverify consumes it. If your request fails for another reason (wrong password, validation error), the token is already spent and the widget still shows “verified”. Call reset() on the element to clear it and load a fresh challenge:
fetch("/login", { method: "POST", body: formData }) .then(function (r) { return r.json(); }) .then(function (data) { if (!data.success) { document.querySelector("aloscaptcha-widget").reset(); } });
reset() clears the hidden input, fires an aloscaptcha-reset event (bubbles and is composed; use it to drop any token you captured in JS), and renders a fresh challenge in place.
Because the element auto-renders on connect, adding it to the DOM is enough. React, Vue, Svelte, or plain JS all work:
const w = document.createElement("aloscaptcha-widget"); w.setAttribute("data-sitekey", "aloscap_pub_XXXX"); w.setAttribute("data-callback", "onCaptcha"); form.appendChild(w);
One token verifies one action. After any submit the token is spent, so call reset() on the widget (see Resetting) before the next attempt.