JavaScript SDK – Quick Start
Integrate BlockBots into any website in under 5 minutes using the JavaScript SDK.
Overview
The BlockBots JavaScript SDK runs in the browser and detects bots from canvas fingerprints, user agent, automation signals, pointer activity and IP address. It talks to the BlockBots API and tells you whether the visitor is a human or a bot.
Installation
The SDK ships in two builds:
| Build | File | Usage |
|---|---|---|
| ES module | blockbots.esm.js | import inside <script type="module"> or a bundler |
| IIFE | blockbots.min.js | classic <script> tag, exposes the global BlockBots |
<!-- ES module -->
<script type="module">
import { BlockBots } from 'https://cdn.jsdelivr.net/gh/blockbots-org/blockbots-js@latest/blockbots.esm.js'
</script>
Basic usage
<script type="module">
import { BlockBots } from 'https://cdn.jsdelivr.net/gh/blockbots-org/blockbots-js@latest/blockbots.esm.js'
const bb = new BlockBots({
apiKey: 'YOUR_API_KEY',
retries: 1,
delay: 1000,
ui: true // built-in loading / blocked overlay
})
bb.onVerified(() => {
// Human verified — allow the user to proceed
console.log('Verified as human')
})
bb.onBlocked((reason) => {
// Bot detected or verification failed
console.log('Blocked:', reason)
})
await bb.verify()
</script>
Get your API key from the dashboard at panel.blockbots.org under Settings → API Keys.
How it works
bb.verify()is called — the SDK collects browser signals- Signals are sent to the BlockBots API (
POST /v1/js) - The API answers with one of three outcomes:
- pass — session cookies are returned and stored in the browser
- challenge — a captcha is shown (typical for VPN / low-confidence IPs); once solved, the signals are re-submitted with the captcha token
- forbidden — confirmed bot, the
__bb_decisioncookie is set
- Cookies are validated against the API
- Your
onVerifiedoronBlockedcallback fires
Full example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>My Site</title>
</head>
<body>
<div id="app" style="display:none;">
<!-- Protected content here -->
</div>
<script type="module">
import { BlockBots } from 'https://cdn.jsdelivr.net/gh/blockbots-org/blockbots-js@main/blockbots.esm.js'
const bb = new BlockBots({
apiKey: 'YOUR_API_KEY',
retries: 3,
delay: 1000,
ui: true
})
bb.onVerified(() => {
document.getElementById('app').style.display = 'block'
})
bb.onBlocked((reason) => {
console.log('Blocked:', reason)
})
bb.onError((error) => {
console.error('BlockBots error:', error)
// Fail open — show content even if detection fails
document.getElementById('app').style.display = 'block'
})
await bb.verify()
</script>
</body>
</html>
verify()never throws — errors are routed toonErrorand it resolves tofalse. The only exception is a missingapiKey, which throws from the constructor.
Next steps
- All options, methods and events → SDK Reference