@capgo/capacitor-recaptcha

中文文档
8.1.18发布于 2026/10/15MPL-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 4.2万

Capacitor plugin for generating reCAPTCHA and reCAPTCHA Enterprise tokens.

原始使用文档
文档目录17 节
  1. ➡️ Get started for free
  2. Key features
  3. Compatibility
  4. Install
  5. Configuration
  6. Usage
  7. Platform Setup
  8. Android
  9. iOS
  10. Web
  11. Notes
  12. Example App
  13. API
  14. load(...)
  15. execute(...)
  16. getPluginVersion()
  17. Interfaces

@capgo/capacitor-recaptcha

Protect sign-ups, logins and payments in your Capacitor app with reCAPTCHA tokens on web, Android and iOS, verified by your backend.

Capgo - Build Capacitor apps with AI, ship updates instantly

Capgo: push fixes to your Capacitor users in minutes, build signed iOS and Android apps without a Mac, and roll back in one click.

➡️ Get started for free

14-day unlimited free trial. No credit card required

🤖 Building with an AI coding agent? Install Capgo skills so Claude Code, Codex, Cursor, Copilot, or Gemini CLI know how to install and use @capgo/capacitor-recaptcha in your Capacitor app: npx skills add Cap-go/capgo-skills. Then ask your agent: "Add @capgo/capacitor-recaptcha to my Capacitor app and wire it up." Agent setup guides · Hosted MCP

@capgo/capacitor-recaptcha for Capacitor apps

Key features

  • Load: load() initializes and caches the reCAPTCHA client.
  • Execute: execute() returns a token for an action, ready for backend verification.
  • Mobile: reCAPTCHA Enterprise SDKs on Android and iOS.
  • Web: reCAPTCHA v3 with api.js, or reCAPTCHA Enterprise with enterprise.js.
  • Per-platform keys: androidSiteKey, iosSiteKey and webSiteKey win over the shared siteKey set at the same level.
  • Platforms: iOS, Android and Web.

Capacitor plugin for generating reCAPTCHA tokens on Web, Android, and iOS.

It supports:

  • Web reCAPTCHA v3 with api.js
  • Web reCAPTCHA Enterprise with enterprise.js
  • Android and iOS reCAPTCHA Enterprise/mobile SDKs

Use it before sensitive actions such as login, signup, checkout, password reset, or abuse-prone form submissions. The token must be sent to your backend and verified by creating a reCAPTCHA assessment.

Compatibility

Plugin versionCapacitor compatibilityMaintained
v8..v8..Yes
v7..v7..On demand
v6..v6..No
v5..v5..No

The major version of this plugin follows the major version of Capacitor.

Install

You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:

npx skills add https://github.com/cap-go/capacitor-skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `cap-go/capacitor-skills` to install the `@capgo/capacitor-recaptcha` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capgo/capacitor-recaptcha
npx cap sync

Configuration

import type { CapacitorConfig } from '@capacitor/cli';
import '@capgo/capacitor-recaptcha';

const config: CapacitorConfig = {
  appId: 'com.example.app',
  appName: 'Example',
  webDir: 'dist',
  plugins: {
    Recaptcha: {
      androidSiteKey: 'ANDROID_SITE_KEY',
      iosSiteKey: 'IOS_SITE_KEY',
      webSiteKey: 'WEB_SITE_KEY',
      enterprise: true,
    },
  },
};

export default config;

You can also pass siteKey directly to load() or execute() when the key is environment-specific.

Usage

import { Recaptcha } from '@capgo/capacitor-recaptcha';

await Recaptcha.load();

const { token } = await Recaptcha.execute({
  action: 'login',
});

await fetch('/api/recaptcha-assessment', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ token, action: 'login' }),
});

For regular Web reCAPTCHA v3:

const { token } = await Recaptcha.execute({
  siteKey: 'WEB_V3_SITE_KEY',
  enterprise: false,
  action: 'signup',
});

Platform Setup

Android

Create an Android mobile application key in Google Cloud reCAPTCHA and use it as androidSiteKey or siteKey.

Android uses Google's mobile reCAPTCHA SDK. Regular, non-Enterprise reCAPTCHA v3 is only available on Web in this plugin; enterprise: false is rejected on Android.

The plugin depends on:

com.google.android.recaptcha:recaptcha:18.8.0

Google's Android reCAPTCHA SDK requires core library desugaring in the consuming app. The plugin enables it automatically during npx cap sync android and adds:

com.android.tools:desugar_jdk_libs:2.1.5

You can override the version from your app Gradle config with recaptchaVersion. You can override the desugaring dependency with desugarJdkLibsVersion.

iOS

Create an iOS mobile application key in Google Cloud reCAPTCHA and use it as iosSiteKey or siteKey.

iOS uses Google's RecaptchaEnterprise mobile SDK. Regular, non-Enterprise reCAPTCHA v3 is only available on Web in this plugin; enterprise: false is rejected on iOS.

The plugin ships both Swift Package Manager and CocoaPods metadata and depends on Google's RecaptchaEnterprise iOS SDK.

Web

Use a website key. Set enterprise: true for reCAPTCHA Enterprise or enterprise: false for regular reCAPTCHA v3.

Notes

  • Tokens are single-use and should be generated immediately before the protected backend request.
  • Validate every token on your backend by creating a reCAPTCHA assessment.
  • The old Cordova sitekeyAndroid and sitekeyWeb option names are accepted as migration aliases in call options and Capacitor config.
  • sitekeyIos and sitekeyIOS are accepted as iOS migration aliases in call options and Capacitor config.

Example App

The example-app/ folder links to the local plugin with file:...

cd example-app
npm install
npm run start

API

reCAPTCHA plugin API.

load(...)

load(options?: LoadOptions | undefined) => Promise<LoadResult>

Load and cache the reCAPTCHA client for the current platform.

execute() loads the client automatically when needed, so calling this method is optional.

ParamType
optionsLoadOptions

Returns: Promise<LoadResult>

Since: 8.0.0


execute(...)

execute(options: ExecuteOptions) => Promise<ExecuteResult>

Execute reCAPTCHA for an action and return a token for backend assessment.

ParamType
optionsExecuteOptions

Returns: Promise<ExecuteResult>

Since: 8.0.0


getPluginVersion()

getPluginVersion() => Promise<PluginVersionResult>

Returns the platform implementation version marker.

Returns: Promise<PluginVersionResult>

Since: 8.0.0


Interfaces

LoadResult

Result returned after the client is loaded.

PropTypeDescriptionSince
loadedbooleanWhether the platform client is ready.8.0.0
siteKeystringSite key used to load the client.8.0.0
enterprisebooleanWhether Enterprise mode was requested.8.0.0
platform'web' | 'ios' | 'android'Platform that loaded the client.8.0.0

LoadOptions

Options used to load the reCAPTCHA client.

PropTypeDescriptionDefaultSince
siteKeystringSite key to use for this call. If omitted, the plugin reads the platform-specific key from Capacitor config.8.0.0
androidSiteKeystringAndroid site key.8.0.0
iosSiteKeystringiOS site key.8.0.0
webSiteKeystringWeb site key.8.0.0
sitekeyAndroidstringLegacy Cordova Android site key alias.8.1.1
sitekeyIosstringLegacy-style iOS site key alias.8.1.1
sitekeyIOSstringLegacy-style iOS site key alias.8.1.1
sitekeyWebstringLegacy Cordova Web site key alias.8.1.1
enterprisebooleanWeb mode switch. Web uses enterprise.js when true and regular reCAPTCHA v3 api.js when false. Android and iOS use Google's mobile reCAPTCHA SDK, which is Enterprise/mobile only. Passing enterprise: false on Android or iOS is rejected.true8.0.0
languagestringOptional language code for the Web reCAPTCHA script.8.0.0

ExecuteResult

Result returned after executing a protected action.

PropTypeDescriptionSince
tokenstringToken generated by reCAPTCHA. Send this to your backend and create an assessment there.8.0.0
actionstringAction name used to generate the token.8.0.0
siteKeystringSite key used to generate the token.8.0.0
enterprisebooleanWhether Enterprise mode was requested.8.0.0
platform'web' | 'ios' | 'android'Platform that generated the token.8.0.0

ExecuteOptions

Options used to execute a protected action.

PropTypeDescriptionSince
actionstringAction name to protect. Use meaningful names such as login, signup, checkout, or password_reset.8.0.0
timeoutnumberOptional native execution timeout in milliseconds. Android and iOS enforce a minimum timeout of 5000ms when provided. This value is ignored on Web.8.0.0

PluginVersionResult

Plugin version payload.

PropTypeDescriptionSince
versionstringVersion identifier returned by the platform implementation.8.0.0

版本与发布记录

@capgo/capacitor-recaptcha 共发布 19 个版本,首次发布于 2026/05/12;过去 12 个月发布了 19 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.1.18latest2026/10/1525 天前
8.1.172026/10/1327 天前
8.1.162026/10/1030 天前
8.1.152026/10/091 个月前
8.1.142026/10/081 个月前
8.1.132026/10/081 个月前

关于 @capgo/capacitor-recaptcha 的常见问题

@capgo/capacitor-recaptcha 是什么?

Capacitor plugin for generating reCAPTCHA and reCAPTCHA Enterprise tokens.

如何安装 @capgo/capacitor-recaptcha?

在项目目录运行 npm install @capgo/capacitor-recaptcha,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capgo/capacitor-recaptcha 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capgo/capacitor-recaptcha 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capgo/capacitor-recaptcha 可以商用吗?

@capgo/capacitor-recaptcha 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@capgo/capacitor-recaptcha 的下载量有多少?

根据 npm 官方下载统计,@capgo/capacitor-recaptcha 在 2026/10/09 – 2026/11/07 这 30 天内被下载 41,729 次,日均约 1,391 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capgo/capacitor-recaptcha 还在维护吗?

最新版本 8.1.18 发布于 2026/10/15(25 天前);至今共发布 19 个版本,其中过去 12 个月发布了 19 个;首次发布于 2026/05/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。