Web

JavaScript

Verify visitors in the browser with the BlockBots SDK — one script tag, no build step.

Overview

This guide adds the BlockBots SDK to a web page. It collects browser signals — canvas fingerprint, user agent, automation traces, pointer activity — sends them to the API, and tells you whether the visitor is a person or a bot.

It takes about five minutes. No build step required; a bundler works too.

This guide protects what happens in the browser. To stop bots before your server renders anything, add the PHP guide as well. The two work together.

Prerequisites

  • A page you can add a <script> tag to
  • An API key — create one at panel.blockbots.org under Settings → API Keys
  • The domain registered on that key, exactly as visitors reach it

Step 1 — Load the SDK

The SDK ships in two builds. Pick one.

BuildFileWhen to use
ES moduleblockbots.esm.js<script type="module"> or a bundler
IIFEblockbots.min.jsclassic <script> tag, exposes a global BlockBots
index.html
<script type="module">
  import { BlockBots } from 'https://cdn.jsdelivr.net/gh/blockbots-org/blockbots-js@latest/blockbots.esm.js'
</script>

Step 2 — Verify the visitor

Create the client, attach your callbacks, and call verify().

index.html
<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 and blocked screens
  })

  bb.onVerified(() => {
    console.log('Verified as human')
  })

  bb.onBlocked((reason) => {
    console.log('Blocked:', reason)
  })

  await bb.verify()
</script>

verify() never throws. Errors go to onError and it resolves to false. The one exception is a missing apiKey, which throws from the constructor so you catch it in development rather than in production.

Step 3 — Reveal your content

Keep protected content hidden until verification succeeds, and show it anyway if detection itself fails — a bot check should never be the reason a real visitor sees nothing.

index.html
<!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@latest/blockbots.esm.js'

    const show = () => { document.getElementById('app').style.display = 'block' }

    const bb = new BlockBots({ apiKey: 'YOUR_API_KEY', ui: true })

    bb.onVerified(show)
    bb.onBlocked((reason) => console.log('Blocked:', reason))
    bb.onError((error) => {
      console.error('BlockBots error:', error)
      show()          // fail open
    })

    await bb.verify()
  </script>

</body>
</html>

Step 4 — Check it works

Open the page in a private window with the console visible. A healthy run logs:

browser console
Verified as human

In DevTools → Application → Cookies you should now see __bbst, __bbts and, if you asked for it, __bbjwt.

If no cookies appear, check the page is served over HTTPS — session cookies are marked Secure there, and a browser silently drops those on a plain http:// page.

How it works

  1. verify() collects browser signals.
  2. They go to the API as POST /v1/js.
  3. The API answers one of three ways:
    • pass — session cookies come back and are stored
    • challenge — a proof-of-work captcha appears, typical for VPN or datacentre addresses; solving it re-submits the signals
    • forbidden — confirmed bot
  4. Your onVerified or onBlocked callback fires.

Cookies last four minutes. A returning visitor is re-checked quietly on the next navigation.

Next steps

  • PHP — stop bots before your server renders a page
  • Node.js — the same protection for an Express or Fastify app
  • WordPress Plugin — the same protection, installed from the admin panel