useBotDetection() · Nuxt Robots · Nuxt SEO

[NuxtSEO](https://nuxtseo.com/ "Home")

- [Modules](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [Tools](https://nuxtseo.com/tools)
- [Pro](https://nuxtseo.com/pro)
- [Learn SEO](https://nuxtseo.com/learn-seo/nuxt) [Releases](https://nuxtseo.com/releases)

[1.4K](https://github.com/harlan-zw/nuxt-seo)

[Nuxt SEO on GitHub](https://github.com/harlan-zw/nuxt-seo)

[User Guides](https://nuxtseo.com/docs/robots/getting-started/introduction)

[API](https://nuxtseo.com/docs/robots/api/use-robots-rule)

[Releases](https://nuxtseo.com/docs/robots/releases/v6)

Robots

- [Switch to Robots](https://nuxtseo.com/docs/robots/getting-started/introduction)
- [Switch to Nuxt SEO](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [Switch to Sitemap](https://nuxtseo.com/docs/sitemap/getting-started/introduction)
- [Switch to OG Image](https://nuxtseo.com/docs/og-image/getting-started/introduction)
- [Switch to Schema.org](https://nuxtseo.com/docs/schema-org/getting-started/introduction)
- [Switch to Link Checker](https://nuxtseo.com/docs/link-checker/getting-started/introduction)
- [Switch to SEO Utils](https://nuxtseo.com/docs/seo-utils/getting-started/introduction)
- [Switch to Site Config](https://nuxtseo.com/docs/site-config/getting-started/introduction)
- [Switch to Skew Protection](https://nuxtseo.com/docs/skew-protection/getting-started/introduction)
- [Switch to AI Ready](https://nuxtseo.com/docs/ai-ready/getting-started/introduction)

Search…```k`` /`

v6.0.7

- Playgrounds
- [Discord Support](https://discord.com/invite/275MBUBvgP)

### Nuxt API

- [`useRobotsRule()`](https://nuxtseo.com/docs/robots/api/use-robots-rule)
- [`useBotDetection()`](https://nuxtseo.com/docs/robots/api/use-bot-detection)
- [nuxt.config.ts](https://nuxtseo.com/docs/robots/api/config)
- [Nuxt Hooks](https://nuxtseo.com/docs/robots/api/nuxt-hooks)

### Nitro API

- [`getPathRobotConfig()`](https://nuxtseo.com/docs/robots/nitro-api/get-path-robot-config)
- [`getSiteRobotConfig()`](https://nuxtseo.com/docs/robots/nitro-api/get-site-robot-config)
- [`getBotDetection()`](https://nuxtseo.com/docs/robots/nitro-api/get-bot-detection)
- [Nitro Hooks](https://nuxtseo.com/docs/robots/nitro-api/nitro-hooks)

Nuxt API

# useBotDetection()

[Copy for LLMs](https://nuxtseo.com/docs/robots/api/use-bot-detection.md)

## [Introduction](#introduction)

**Type:** `function useBotDetection(options?: UseBotDetectionOptions): UseBotDetectionReturn`

Types are auto-imported when using the composable.

Detect and classify bots using server-side header analysis and optional client-side browser fingerprinting.

The composable provides reactive access to bot detection results with automatic caching. Client-side fingerprinting is opt-in due to performance costs.

**🔔 Important:** Bot detection only runs when you use this composable. No automatic bot detection occurs - it's entirely opt-in based on your usage of this composable.

## [Usage](#usage)

**Basic detection:**

```
import { useBotDetection } from '#robots/app/composables/useBotDetection'

const { isBot, botName, botCategory, trusted } = useBotDetection()
// isBot: ComputedRef<boolean>
// botName: ComputedRef<BotName | undefined> // 'googlebot', 'facebook', etc.
// botCategory: ComputedRef<BotCategory | undefined> // 'search-engine', 'social', etc.
// trusted: ComputedRef<boolean | undefined>
```

**With fingerprinting:**

```
import { useBotDetection } from '#robots/app/composables/useBotDetection'

const { isBot, botName, botCategory, trusted, reset } = useBotDetection({
  fingerprint: true,
  onFingerprintError: (error) => {
    console.error('Fingerprint error:', error)
  },
  onFingerprintResult: (result) => {
    console.log('Fingerprinting completed:', result)
  }
})
```

**Watching for changes:**

```
import { useBotDetection } from '#robots/app/composables/useBotDetection'
import { watch } from 'vue'

const { isBot, botName, botCategory } = useBotDetection()

watch(isBot, (detected) => {
  if (detected) {
    console.log(\`Bot: ${botName.value} (${botCategory.value})\`)
  }
})
```

## [Options](#options)

```
interface UseBotDetectionOptions {
  fingerprint?: boolean
  onFingerprintError?: (error: Error) => void
  onFingerprintResult?: (result: BotDetectionContext | null) => void
}
```

### [`fingerprint`](#fingerprint)

**Type:** `boolean`**Default:** `false`

Enable automatic client-side fingerprinting when no bot is detected server-side.

### [`onFingerprintError`](#onfingerprinterror)

**Type:** `(error: Error) => void`

Error handler for fingerprinting failures.

### [`onFingerprintResult`](#onfingerprintresult)

**Type:** `(result: BotDetectionContext | null) => void`

Callback that fires when fingerprinting completes, providing the final detection result.

## [Return Type](#return-type)

```
interface UseBotDetectionReturn {
  isBot: ComputedRef<boolean>
  botName: ComputedRef<BotName | undefined>
  botCategory: ComputedRef<BotCategory | undefined>
  trusted: ComputedRef<boolean | undefined>
  reset: () => void
}
```

## [Return Value](#return-value)

### [`isBot`](#isbot)

**Type:** `ComputedRef<boolean>`

Reactive boolean indicating whether a bot was detected.

### [`botName`](#botname)

**Type:** `ComputedRef<BotName | undefined>`

The specific bot identity (e.g., 'googlebot', 'facebook', 'claude', 'selenium'). `undefined` if no bot detected.

### [`botCategory`](#botcategory)

**Type:** `ComputedRef<BotCategory | undefined>`

The bot category/purpose (e.g., 'search-engine', 'social', 'ai', 'automation'). `undefined` if no bot detected.

### [`trusted`](#trusted)

**Type:** `ComputedRef<boolean | undefined>`

Whether the detected bot is considered trusted. `undefined` if no bot detected.

### [`reset()`](#reset)

**Type:** `() => void`

Clear all detection state and cached results.

## [Server Side Behavior](#server-side-behavior)

On the server, bot detection runs when you use the composable:

```
import { useBotDetection } from '#robots/app/composables/useBotDetection'

// Only runs when composable is used
const { isBot, botName, botCategory } = useBotDetection()

if (isBot.value) {
  // Bot detected via server-side analysis
  console.log('Bot:', botName.value, 'Category:', botCategory.value)
}
```

## [Client Side Behavior](#client-side-behavior)

If the server-side detection is unavailable (e.g. SPA mode), it will fallback to using `navigator.userAgent`.

Client-side fingerprinting is automatic when enabled:

```
import { useBotDetection } from '#robots/app/composables/useBotDetection'

const { isBot, botName, botCategory } = useBotDetection({
  fingerprint: true,
  onFingerprintError: (error) => {
    console.error('Fingerprinting failed:', error)
  }
})

// Fingerprinting runs automatically if no server detection occurred
```

## [Configuration](#configuration)

### [Disabling Bot Detection](#disabling-bot-detection)

You can disable the entire bot detection plugin:

```
// nuxt.config.ts
import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
  robots: {
    botDetection: false
  }
})
```

When disabled, the `useBotDetection` composable will return a mock implementation with default values (e.g., `isBot: false`).

## [Bot Categories](#bot-categories)

The following bot types are detected:

- **search-engine**: Google, Bing, Yandex crawlers
- **social**: Twitter, Facebook, LinkedIn bots
- **seo**: Ahrefs, SEMrush, Majestic tools
- **ai**: GPT, Claude, Perplexity crawlers
- **generic**: Generic bot, spider, crawler patterns
- **automation**: Selenium, Puppeteer, WebDriver
- **http-tool**: curl, wget, Python requests
- **security-scanner**: nmap, Nikto, ZGrab
- **scraping**: Scrapy and dedicated scraping tools

[Edit this page](https://github.com/nuxt-modules/robots/edit/main/docs/content/3.api/2.use-bot-detection.md)

[Markdown For LLMs](https://nuxtseo.com/docs/robots/api/use-bot-detection.md)

Did this page help you?

[Nuxt Hooks Learn how to use Nuxt hooks to modify the robots config.](https://nuxtseo.com/docs/robots/api/nuxt-hooks) [getPathRobotConfig() See if the Site is indexable within Nitro.](https://nuxtseo.com/docs/robots/nitro-api/get-path-robot-config)

On this page

- [Introduction](#introduction)
- [Usage](#usage)
- [Options](#options)
- [Return Type](#return-type)
- [Return Value](#return-value)
- [Server Side Behavior](#server-side-behavior)
- [Client Side Behavior](#client-side-behavior)
- [Configuration](#configuration)
- [Bot Categories](#bot-categories)

[GitHub](https://github.com/harlan-zw/nuxt-seo) [ Discord](https://discord.com/invite/275MBUBvgP)

### [NuxtSEO](https://nuxtseo.com/ "Home")

- [Getting Started](https://nuxtseo.com/docs/nuxt-seo/getting-started/introduction)
- [MCP](https://nuxtseo.com/docs/nuxt-seo/guides/mcp)

Modules

- [Robots](https://nuxtseo.com/docs/robots/getting-started/introduction)
- [Sitemap](https://nuxtseo.com/docs/sitemap/getting-started/introduction)
- [OG Image](https://nuxtseo.com/docs/og-image/getting-started/introduction)
- [Schema.org](https://nuxtseo.com/docs/schema-org/getting-started/introduction)
- [Link Checker](https://nuxtseo.com/docs/link-checker/getting-started/introduction)
- [SEO Utils](https://nuxtseo.com/docs/seo-utils/getting-started/introduction)
- [Site Config](https://nuxtseo.com/docs/site-config/getting-started/introduction)
- [Skew Protection](https://nuxtseo.com/docs/skew-protection/getting-started/introduction)
- [AI Ready](https://nuxtseo.com/docs/ai-ready/getting-started/introduction)

### [NuxtSEO Pro](https://nuxtseo.com/pro "Home")

- [Getting Started](https://nuxtseo.com/pro)
- [Dashboard](https://nuxtseo.com/pro/dashboard)
- [Pro MCP](https://nuxtseo.com/docs/nuxt-seo-pro/mcp/installation)

### [Learn SEO](https://nuxtseo.com/learn-seo "Learn SEO")

Nuxt

- [Mastering Meta](https://nuxtseo.com/learn-seo/nuxt/mastering-meta)
- [Controlling Crawlers](https://nuxtseo.com/learn-seo/nuxt/controlling-crawlers)
- [Launch & Listen](https://nuxtseo.com/learn-seo/nuxt/launch-and-listen)
- [Routes & Rendering](https://nuxtseo.com/learn-seo/nuxt/routes-and-rendering)
- [Staying Secure](https://nuxtseo.com/learn-seo/nuxt/routes-and-rendering/security)

Vue

- [Vue SEO Guide](https://nuxtseo.com/learn-seo/vue)
- [Mastering Meta](https://nuxtseo.com/learn-seo/vue/mastering-meta)
- [Controlling Crawlers](https://nuxtseo.com/learn-seo/vue/controlling-crawlers)
- [SPA SEO](https://nuxtseo.com/learn-seo/vue/spa)
- [SSR Frameworks](https://nuxtseo.com/learn-seo/vue/ssr-frameworks)
- [SEO Checklist](https://nuxtseo.com/learn-seo/checklist)
- [Pre-Launch Warmup](https://nuxtseo.com/learn-seo/pre-launch-warmup)
- [Backlinks & Authority](https://nuxtseo.com/learn-seo/backlinks)

### [Tools](https://nuxtseo.com/tools "SEO Tools")

- [Social Share Debugger](https://nuxtseo.com/tools/social-share-debugger)
- [Robots.txt Generator](https://nuxtseo.com/tools/robots-txt-generator)
- [Meta Tag Checker](https://nuxtseo.com/tools/meta-tag-checker)
- [HTML to Markdown](https://nuxtseo.com/tools/html-to-markdown)
- [XML Sitemap Validator](https://nuxtseo.com/tools/xml-sitemap-validator)
- [Schema.org Validator](https://nuxtseo.com/tools/schema-validator)
- [Keyword Idea Generator](https://nuxtseo.com/tools/keyword-generator)
- [Keyword Research](https://nuxtseo.com/tools/keyword-research)
- [SERP Analyzer](https://nuxtseo.com/tools/serp-analyzer)
- [Domain Rankings](https://nuxtseo.com/tools/domain-rankings)

Copyright © 2023-2026 Harlan Wilton - [MIT License](https://github.com/harlan-zw/nuxt-seo/blob/main/license) · [mdream](https://mdream.dev)