tessl install tessl/npm-isbot@5.1.0Recognise bots/crawlers/spiders using the user agent string.
Agent Success
Agent success rate when using this tile
82%
Improvement
Agent success rate improvement when using this tile compared to baseline
0.94x
Baseline
Agent success rate without this tile
87%
Build a small module that reports whether a user agent is a bot and labels which detection engine was used. It must rely on the dependency's automatic downgrade to a naive detector when advanced regex features (such as lookbehind) are unavailable, rather than reimplementing bot matching yourself.
{ isBot: true, engine: "full" } for a crawler-style user agent such as "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)". @test{ isBot: false, engine: "full" } for a modern browser user agent such as "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36". @test{ forceLegacy: true }), the crawler user agent still yields { isBot: true, engine: "fallback" }, using the dependency's built-in downgrade instead of custom regex logic. @test{ isBot: false, engine: "fallback" } without throwing. @test@generates
export interface ClassifyOptions {
forceLegacy?: boolean;
}
export interface ClassificationResult {
isBot: boolean;
engine: "full" | "fallback";
}
export function classifyUserAgent(
userAgent?: string | null,
options?: ClassifyOptions
): ClassificationResult;
export function summarizeUserAgents(
userAgents: Array<string | null | undefined>,
options?: ClassifyOptions
): {
total: number;
bots: number;
engine: "full" | "fallback";
};Both exports should share the same detection path: default behavior uses the compiled pattern and reports engine: "full", while forceLegacy: true (or any automatic downgrade when advanced regex is missing) must lean on the dependency's internal fallback and surface engine: "fallback" in the result.
Bot detection library that compiles a comprehensive regex and automatically falls back to a naive heuristic when advanced regex features (like lookbehind) are unsupported.