Zero-latency AI bot detection — runs at the edge, before your origin.
Zero latency
Fire-and-forget — never slows your users
Global edge
Runs in 300+ Cloudflare data centers
Server-side detection
Bot logic stays private on BotWatcher servers
Go to Workers & Pages → Create in your Cloudflare dashboard, then choose Create Worker.
Replace the default “Hello World” code with the snippet below, then click Save & Deploy.
export default {
async fetch(request, env, ctx) {
// Forward the request to your origin unchanged
const response = await fetch(request);
// Fire-and-forget: report the hit to BotWatcher
ctx.waitUntil((async () => {
try {
const url = new URL(request.url);
await fetch("https://api.botwatcher.pro/edge", {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": env.BOTWATCHER_API_KEY,
},
body: JSON.stringify({
site: env.BOTWATCHER_DOMAIN,
path: url.pathname,
method: request.method,
ua: request.headers.get("user-agent") || "",
ip: request.headers.get("cf-connecting-ip") || "",
country: request.headers.get("cf-ipcountry") || "",
city: request.cf?.city || "",
region: request.cf?.region || "",
referer: request.headers.get("referer") || "",
}),
});
} catch {
// Never block your traffic — silently swallow errors
}
})());
return response;
},
};jsIn your Worker settings, go to Settings → Variables & Secrets and add:
BOTWATCHER_API_KEY
Your API key (from the Setup tab in your dashboard)
Store as SecretBOTWATCHER_DOMAIN
yourdomain.com
Never put your API key in plain-text code — always use a Worker Secret so it stays encrypted at rest.
Go to Websites → your domain → Workers Routes and add a route matching yourdomain.com/* pointing to your new Worker. This means every request your visitors make passes through the Worker first.
Set up? Head to your dashboard to see bot traffic roll in.