@formbricks/js

中文文档
5.3.0发布于 2026/11/13MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 14.9万

Formbricks-js allows you to connect your index to Formbricks, display surveys and trigger events.

原始使用文档
文档目录4 节
  1. What is Formbricks
  2. How to use this library
  3. Renderer prefetching and Content Security Policy
  4. Dark mode

Formbricks Browser JS Library

npm package MIT License

Please see Formbricks Docs. Specifically, Quickstart/Implementation details.

What is Formbricks

Formbricks is your go-to solution for in-product micro-surveys that will supercharge your product experience! 🚀 For more information please check out formbricks.com.

How to use this library

  1. Install the Formbricks package inside your project using npm:
npm install @formbricks/js
  1. Import Formbricks and initialize the widget in your main component (e.g., App.tsx or App.js):
import formbricks from "@formbricks/js";

if (typeof window !== "undefined") {
  formbricks.setup({
    workspaceId: "your-workspace-id",
    appUrl: "https://app.formbricks.com",
  });
}

Replace your-workspace-id with your actual workspace ID. You can find your workspace ID in the Setup Checklist in the Formbricks settings. If you want to use the user identification feature, please check out our docs for details.

environmentId is still accepted for backward compatibility but is deprecated and will be removed in a future version. Prefer workspaceId.

Renderer prefetching and Content Security Policy

The SDK prefetches the survey renderer by default. If your host application's Content Security Policy blocks these prefetch requests, disable them during setup:

formbricks.setup({
  workspaceId: "your-workspace-id",
  appUrl: "https://app.formbricks.com",
  prefetch: false,
});

The renderer still loads when a survey is triggered. Omitting prefetch preserves the default; prefetch: true explicitly enables prefetching. This requires a Formbricks instance serving js-core with prefetch support. Older instances ignore the option, so upgrading this npm package alone does not disable their prefetch requests.

Dark mode

Surveys render light by default. Pass appearance to setup(), or change it at any time with setAppearance(): "light", "dark", or "system" to follow the visitor's browser setting. An open survey switches in place. Requires Formbricks 6.1 or later.

formbricks.setup({
  workspaceId: "your-workspace-id",
  appUrl: "https://app.formbricks.com",
  appearance: "system",
});

formbricks.setAppearance("dark");

For more detailed guides for different frameworks, check out our Framework Guides.

版本与发布记录

@formbricks/js 共发布 85 个版本,首次发布于 2023/03/30;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.3.0latest2026/11/132 天前
5.2.02026/11/123 天前
5.1.02026/09/211 个月前
5.0.02026/05/275 个月前
4.4.02026/04/286 个月前
4.3.02025/12/1211 个月前

其他发布通道:beta → 4.0.0-beta.1。

关于 @formbricks/js 的常见问题

@formbricks/js 是什么?

Formbricks-js allows you to connect your index to Formbricks, display surveys and trigger events.

如何安装 @formbricks/js?

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

@formbricks/js 支持 TypeScript 吗?

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

@formbricks/js 支持 ESM 还是 CommonJS?

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

@formbricks/js 可以商用吗?

@formbricks/js 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@formbricks/js 的下载量有多少?

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

@formbricks/js 还在维护吗?

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