AbuseZero browser SDK
Use the AbuseZero browser SDK, abusezero/browser, to connect your web pages to browser protection and the bot check.
The AbuseZero browser SDK, abusezero/browser, connects your pages to AbuseZero's device and automation intelligence, as described in Browser protection. On each claim it gathers browser evidence in the background, without blocking your page. It returns one value, the device token, which your server passes on with the evaluation. The SDK always resolves. When there's no browser data, such as when a visitor declines consent or a network blocks the request, the device token carries the reason instead. The evaluation still runs and reports exactly what it received.
import { init, observe, prepareBotObservation, forgetBrowser } from "abusezero/browser";Use your publishable key (pk_…) in the browser. It can only send browser data from the sites in your site list, so it is safe to ship in your pages. Keep secret keys and the AbuseZero Node.js SDK out of your browser bundle. For a step-by-step setup, see Set up browser protection.
How the browser SDK works
- Your page calls
observe()orprepareBotObservation()with the claim's ID. - It sends the returned
deviceTokento your server. - Your server sends the token in the evaluation as
identifiers.device_token.
Use the same claim ID in the browser and on your server. The browser's claimId is the evaluation's claim_id.
init
Call init once when your app starts.
init({ key: "pk_…" });It reports once per page load that browser protection is installed on this site. It sends only the site's address and the SDK version, never visitor data. Developers → Browser setup, also available through GET /v1/browser-collection, shows each site where it was seen and which version it runs.
| Option | Type | Required | Description |
|---|---|---|---|
key | string | Yes | Your publishable key. |
observe
Call observe when the person submits the claim, then send the token to your server with it.
const observation = await observe({ key: "pk_…", claimId });
await fetch("/api/start-trial", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ claimId, deviceToken: observation.deviceToken }),
});| Option | Type | Required | Description |
|---|---|---|---|
key | string | Yes | Your publishable key. |
claimId | string | Yes | The claim's ID, sent by your server as the evaluation's claim_id. |
consent | () => boolean | Promise<boolean> | No | Collection runs unless this resolves to false. See Consent. |
The observation
observe never throws or rejects. It resolves to one of two shapes, and both carry deviceToken.
| Field | Type | Description |
|---|---|---|
status | "available" or "unavailable" | Whether browser data was collected. |
deviceToken | string | Send this to your server and on to the evaluation as identifiers.device_token, whatever the status. The evaluation reports what it received as browser_data. |
token | string | With available. The same value as deviceToken. |
expiresIn | number | With available. Seconds until the token expires. Send it in an evaluation before then. |
reason | string | With unavailable. Why there is no browser data. See Unavailable reasons. |
Always send deviceToken, including when the status is unavailable. It tells AbuseZero why there is no
browser data, and the evaluation reports it as the browser_data status.
prepareBotObservation
Add a bot check by calling prepareBotObservation instead of observe when the person submits the form. A benefit's automation settings decide whether the bot check is required; see Bots and AI agents. It collects the same browser data and adds the bot check, with the same options and result.
form.addEventListener("submit", async event => {
event.preventDefault();
const { deviceToken } = await prepareBotObservation({ key: "pk_…", claimId });
await fetch("/api/start-trial", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ claimId, deviceToken }),
});
});Send its deviceToken in an evaluation within 2 minutes. AbuseZero verifies the bot check during that evaluation. When the token is too old, or a benefit that requires the bot check receives none, the evaluation returns a bot-check error, such as BOT_EVIDENCE_REQUIRED. See Add a bot check. Collect a fresh token and evaluate again. See Add a bot check.
Consent
Browser protection runs by default. Pass a consent callback to make it depend on your consent tool. See Respect consent.
const observation = await observe({
key: "pk_…",
claimId,
consent: () => consentManager.hasConsent("security"), // Your consent tool.
});- When
consentresolves tofalse, nothing is collected anddeviceTokenisunavailable:consent_declined. - When your consent tool keeps the SDK from loading at all, send
unavailable:not_loadedas the device token. - When a visitor withdraws consent, call
forgetBrowser(). It clears what browser protection stored in this browser. Claim history already recorded in your workspace stays.
Unavailable reasons
When there is no browser data, reason and the device token say why. The same values appear as the evaluation's browser data status, and Troubleshooting covers each one. The token has the form unavailable:<reason>.
| Reason | Meaning | What to do |
|---|---|---|
consent_declined | Your consent callback resolved to false. | Nothing. This is expected. |
not_loaded | Your consent tool kept the SDK from loading. You send this one yourself. | Nothing. This is expected. |
blocked | The browser couldn't reach AbuseZero, for example because of an extension or a network rule. | Nothing. This is expected. |
timed_out | Collection didn't finish in time. | Nothing. This is expected. |
failed | The publishable key is invalid, or the response couldn't be read. | Check that you use a publishable key (pk_…) from this workspace. |
site_not_listed | The page's site isn't in your site list, or doesn't use HTTPS. | Add the site in Developers → Browser setup. |
sdk_outdated | AbuseZero no longer accepts this SDK version. | Upgrade abusezero, or update the standalone script's address. |
Developers → Browser setup shows how often each status appears across recent evaluations, and flags the ones you can fix as issues.
Your sites
AbuseZero accepts browser data only from HTTPS sites in your site list. Manage the list in Developers → Browser setup or through the Browser setup API.
If your site sets a Content Security Policy, copy the sources shown in Developers → Browser setup into it, as in Set up browser protection.
Standalone browser script
For pages without a bundler, load the standalone script with your publishable key in its address. It runs init by itself.
<script type="module" src="https://abusezero.com/sdk/abusezero-browser-0.11.0.js?key=pk_…"></script>To collect for a claim, import from the same address in a module script:
<script type="module">
import { observe } from "https://abusezero.com/sdk/abusezero-browser-0.11.0.js?key=pk_…";
const claimId = document.querySelector("#claim-id").value;
const { deviceToken } = await observe({ key: "pk_…", claimId });
document.querySelector("#device-token").value = deviceToken;
</script>The address includes the version. When you upgrade, update every page to the new address.
Next steps
How is this guide?
Last updated on