---
title: "Google reCAPTCHA · Nuxt Scripts"
description: "Load score-based reCAPTCHA v3 or Enterprise and execute protected actions."
canonical_url: "https://scripts.nuxt.com/scripts/google-recaptcha"
meta:
  "og:description": "Load score-based reCAPTCHA v3 or Enterprise and execute protected actions."
  "og:image": "https://scripts.nuxt.com/_og/s/o_80d96eb72ac0048c.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Google reCAPTCHA · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_80d96eb72ac0048c.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Scripts**

# **Google reCAPTCHA**

[Copy for LLMs](https://scripts.nuxt.com/scripts/google-recaptcha.md)

[**Google reCAPTCHA**](https://cloud.google.com/security/products/recaptcha) scores requests for likely spam and abuse without showing a checkbox.

[`**useScriptGoogleRecaptcha()**`](https://scripts.nuxt.com/scripts/google-recaptcha) loads the selected client and exposes `**grecaptcha**`.

This registry integration supports score-based reCAPTCHA v3 and Enterprise flows. To render a v2 checkbox, load it separately with `**useScript()**` and follow Google's [**v2 display guide**](https://developers.google.com/recaptcha/docs/display).

**Google reCAPTCHA**

[**View source **](https://github.com/nuxt/scripts/blob/main/packages/script/src/runtime/registry/google-recaptcha.ts)

## Nuxt Config Setup

Add this to your `**nuxt.config.ts**` to load Google reCAPTCHA globally. Alternatively you can use the **useScriptGoogleRecaptcha** composable for more control.

```
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleRecaptcha: {
        siteKey: '6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI',
        trigger: 'onNuxtReady',
      }
    }
  }
})
```

## useScriptGoogleRecaptcha()

The `**useScriptGoogleRecaptcha**` composable lets you have fine-grain control over when and how Google reCAPTCHA is loaded on your site.

```
const { proxy } = useScriptGoogleRecaptcha()

const token = await proxy.grecaptcha.execute(siteKey, { action: 'submit' })
```

Please follow the [**Registry Scripts **](https://scripts.nuxt.com/docs/guides/registry-scripts) guide to learn more about advanced usage.

## Enterprise

For reCAPTCHA Enterprise, set the `**enterprise**` option to `**true**`:

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleRecaptcha: {
        siteKey: 'YOUR_SITE_KEY',
        enterprise: true
      }
    }
  }
})
```

Enterprise exposes its methods under `**grecaptcha.enterprise**`, so execute an action with that object rather than `**grecaptcha.execute**`:

```ts
const { onLoaded } = useScriptGoogleRecaptcha({
  siteKey: 'YOUR_SITE_KEY',
  enterprise: true,
})

onLoaded(({ grecaptcha }) => {
  grecaptcha.enterprise!.ready(async () => {
    const token = await grecaptcha.enterprise!.execute('YOUR_SITE_KEY', { action: 'submit' })
    // Send the token to your server for assessment.
  })
})
```

## Alternative domain

Set `**recaptchaNet: true**` where `**google.com**` is unavailable. Google documents `**recaptcha.net**` as its [**alternative domain for global access**](https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally):

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      googleRecaptcha: {
        siteKey: 'YOUR_SITE_KEY',
        recaptchaNet: true
      }
    }
  }
})
```

## Server-side verification

Verify every reCAPTCHA token on your server. Google recommends checking both the score and expected action, then tuning the score threshold against your own traffic rather than treating `**0.5**` as universal. See the [**reCAPTCHA v3 verification guide**](https://developers.google.com/recaptcha/docs/v3#site_verify_response).

```ts
export default defineEventHandler(async (event) => {
  const { token } = await readBody(event)
  const secretKey = process.env.RECAPTCHA_SECRET_KEY
  if (!secretKey)
    throw createError({ statusCode: 500, message: 'Missing reCAPTCHA secret key' })

  const response = await $fetch('https://www.google.com/recaptcha/api/siteverify', {
    method: 'POST',
    body: new URLSearchParams({
      secret: secretKey,
      response: token,
    }),
  })

  if (!response.success || response.action !== 'submit' || response.score < 0.5) {
    throw createError({
      statusCode: 400,
      message: 'reCAPTCHA verification failed',
    })
  }

  return { success: true, score: response.score }
})
```

Never expose your secret key on the client. Always verify tokens server-side.

Tokens expire after two minutes. Call `**execute**` when the user submits the protected action, not when the page loads. See Google's [**reCAPTCHA v3 placement guidance**](https://developers.google.com/recaptcha/docs/v3#placement_on_your_website).

## Hiding the badge

Google [**allows you to hide the reCAPTCHA badge**](https://developers.google.com/recaptcha/docs/faq#id-like-to-hide-the-recaptcha-badge.-what-is-allowed) if the required attribution remains visible in the user flow:

```css
.grecaptcha-badge { visibility: hidden; }
```

```html
<p>This site is protected by reCAPTCHA and the Google
  <a href="https://policies.google.com/privacy">Privacy Policy</a> and
  <a href="https://policies.google.com/terms">Terms of Service</a> apply.
</p>
```

## Testing

For reCAPTCHA v3, Google recommends a [**separate key for test environments**](https://developers.google.com/recaptcha/docs/faq#id-like-to-run-automated-tests-with-recaptcha.-what-should-i-do). Scores in development may differ from production because v3 learns from real traffic. Do not use Google's published always-pass keys here; they only work with reCAPTCHA v2.

`**siteKey**``string`** required **

Your reCAPTCHA site key.

`**enterprise**``boolean`

Use the Enterprise version of reCAPTCHA (enterprise.js instead of api.js).

`**recaptchaNet**``boolean`

Use recaptcha.net instead of google.com domain. Useful for regions where google.com is blocked.

`**hl**``string`

Language code for the reCAPTCHA widget.

## Example

This example scores a contact-form submission and verifies the token on the server:

```vue
<script setup lang="ts">
const { onLoaded, onError } = useScriptGoogleRecaptcha()

const name = ref('')
const email = ref('')
const message = ref('')
const status = ref<'idle' | 'loading' | 'success' | 'error'>('idle')

onError(() => {
  status.value = 'error'
})

function onSubmit() {
  status.value = 'loading'

  onLoaded(({ grecaptcha }) => {
    grecaptcha.ready(async () => {
      const token = await grecaptcha.execute('YOUR_SITE_KEY', { action: 'contact' })

      const result = await $fetch('/api/contact', {
        method: 'POST',
        body: {
          token,
          name: name.value,
          email: email.value,
          message: message.value
        }
      }).catch((error) => {
        console.error('Failed to submit contact form', error)
        return null
      })

      status.value = result ? 'success' : 'error'
    })
  })
}
</script>

<template>
  <form @submit.prevent="onSubmit">
    <input v-model="name" placeholder="Name" required>
    <input v-model="email" type="email" placeholder="Email" required>
    <textarea v-model="message" placeholder="Message" required />
    <button type="submit" :disabled="status === 'loading'">
      {{ status === 'loading' ? 'Sending...' : 'Submit' }}
    </button>
    <p v-if="status === 'success'">
      Message sent!
    </p>
    <p v-if="status === 'error'">
      Failed to send. Please try again.
    </p>
  </form>
</template>
```

::

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/google-recaptcha.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/google-recaptcha.md)

[**Google Maps** Load interactive maps, static maps, and location search on demand.](https://scripts.nuxt.com/scripts/google-maps) [**Google Sign-In** Add Google Sign-In to your Nuxt app with One Tap and personalized button support.](https://scripts.nuxt.com/scripts/google-sign-in)

**On this page **

- [Enterprise](#enterprise)
- [Alternative domain](#alternative-domain)
- [Server-side verification](#server-side-verification)
- [Hiding the badge](#hiding-the-badge)
- [Testing](#testing)
- [Example](#example)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/google-recaptcha#webpage","@type":"WebPage","description":"Load score-based reCAPTCHA v3 or Enterprise and execute protected actions.","name":"Google reCAPTCHA","url":"https://scripts.nuxt.com/scripts/google-recaptcha","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/google-recaptcha#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/google-recaptcha"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/google-recaptcha#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"Google reCAPTCHA","item":"https://scripts.nuxt.com/scripts/google-recaptcha","position":3}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
