@friendlycaptcha/sdk

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

In-browser SDK for Friendly Captcha v2

原始使用文档
文档目录10 节
  1. Installation
  2. CommonJS
  3. Documentation
  4. Development
  5. Browser compatibility
  6. sdktest
  7. Updating the docusaurus SDK reference docs
  8. Adding license headers
  9. License
  10. Contributing

Friendly Captcha SDK

NPM Version badge

The SDK that is used to integrate Friendly Captcha v2 into your website.

This is the code that runs on your website, inserting the captcha widget.

☝️ This is the SDK for Friendly Captcha v2 only. If you are looking for the v1 SDK, you can find that here.

Installation

# using npm
npm install @friendlycaptcha/sdk

# using yarn
yarn add @friendlycaptcha/sdk

You can then use it in your library.

import { FriendlyCaptchaSDK } from "@friendlycaptcha/sdk"

// Re-use this SDK if you are creating multiple widgets.
const sdk = new FriendlyCaptchaSDK();
// HTML element that you want to mount the widget under.
const mount = document.querySelector("#my-widget-mount");

// Create the widget
const widget = sdk.createWidget({
    element: mount,
    sitekey: "<your sitekey>"
});

CommonJS

You can also require the SDK if your environment uses CommonJS.

var { FriendlyCaptchaSDK } = require("@friendlycaptcha/sdk");

// Re-use this SDK if you are creating multiple widgets.
const sdk = new FriendlyCaptchaSDK();

Documentation

The documentation can be found in our Developer Hub, and the Getting Started guide.

Development

If you want to develop this SDK itself the following commands are useful

# install dependencies 
npm install

# minimal build
npm run build

# build for distribution (also builds docs)
npm run build:dist

# run the basic unit tests
npm run test

Browser compatibility

The SDK supports very old browsers (including IE11). The .compat bundles are transpiled with Babel and get the polyfills in src/polyfill/ (Promise, Map, Set, WeakMap and WeakSet), but Babel does not transpile generators or async functions and does not polyfill any other APIs. Run the compatibility linter to find language features and APIs to avoid:

npm run lint:compat

The rules live in lint-compat.config.mjs. Silence a deliberate use, for example one that is feature-checked, with a // compat-ignore: reason comment on the same or the previous line.

sdktest

We include more proper end-to-end tests in the sdktest tool folder.

Updating the docusaurus SDK reference docs

We automatically generate markdown docs and translate these into files that are in a format that works for Docusaurus. You will then need to update the docs manually by deleting the old files and adding the new ones. Something like this:

 rm -rf ../friendly-docs/docs/sdk/reference && mkdir ../friendly-docs/docs/sdk/reference && cp -r ./dist/docs/docusaurus/ ../friendly-docs/docs/sdk/reference/

Adding license headers

# print those files that would be changed
npm run license-check-and-add -- check

# add the headers
npm run license-check-and-add -- add

License

This is free software; you can redistribute it and/or modify it under the terms of the Mozilla Public License Version 2.0.

Contributing

Contributions are welcome.

Prior to us being able to accept your contribution you will need to sign our CLA (Contributor License Agreement).

版本与发布记录

@friendlycaptcha/sdk 共发布 52 个版本,首次发布于 2023/12/09;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.5latest2026/11/114 天前
1.1.42026/11/114 天前
1.1.32026/10/2917 天前
1.1.22026/10/2719 天前
1.1.12026/08/262 个月前
1.1.02026/08/262 个月前

关于 @friendlycaptcha/sdk 的常见问题

@friendlycaptcha/sdk 是什么?

In-browser SDK for Friendly Captcha v2

如何安装 @friendlycaptcha/sdk?

在项目目录运行 npm install @friendlycaptcha/sdk,或使用 pnpm add / yarn add / bun add。

@friendlycaptcha/sdk 支持 TypeScript 吗?

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

@friendlycaptcha/sdk 支持 ESM 还是 CommonJS?

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

@friendlycaptcha/sdk 可以商用吗?

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

@friendlycaptcha/sdk 的下载量有多少?

根据 npm 官方下载统计,@friendlycaptcha/sdk 在 2026/10/16 – 2026/11/14 这 30 天内被下载 242,197 次,日均约 8,073 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@friendlycaptcha/sdk 还在维护吗?

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