@betterbugs/web-sdk

中文文档
0.0.47发布于 2026/09/21MITTypeScriptESM + CJS零依赖近 30 天下载 6516

A web sdk package for Betterbugs

原始使用文档
文档目录16 节
  1. Breaking it down
  2. Key features of the SDK
  3. Quick installation
  4. NPM install
  5. Yarn install
  6. BetterBugs Web SDK initialization: Usage example
  7. TypeScript
  8. Overview of the example code
  9. Configurable Options: Customize SDK behavior
  10. Screenshot accuracy
  11. Recording modes
  12. Leaving recordType unset (recommended)
  13. Setting recordType explicitly
  14. Programmatic Methods: Control SDK behavior
  15. Lifecycle Event Hooks: For deeper integrations
  16. Floating widget customization options

BetterBugs Web SDK

Simplify bug reporting within your web apps with the BetterBugs Web SDK.

The BetterBugs Web SDK allows you to include bug reporting capabilities in your application with minimal settings and effort.

Now, you can enhance your apps with user-friendly and easy-to-implement issue reporting capabilities, such as media capturing, log tracking, getting the two-minute Rewind session video, and real-time hooks to help you and your team report, diagnose, and fix issues effectively.

Breaking it down

Using the BetterBugs Web SDK, you can enhance your web apps with bug reporting features that allow you to capture useful data about the issues. Here's more on it.

Key features of the SDK

  • Seamless integration — Quick installation and easy to use with a few lines of code.
  • Configurable params — Tweak settings for the parameters, such as metaData, recordType, enableAnnotation, and many others.
  • Use Methods — Control the SDK with programmatic methods, such as show(), hide(), startRecording(), and many others.
  • Event hooks — For deeper integration, listen for specific lifecycle events with hooks, such as after a screenshot is captured (screenshot), a bug is submitted (bugSubmit), or a recording starts (recordingStop), and many others.
  • Session Rewind (coming soon) – Automatically records the last 2 minutes of a session to capture all user interactions. It's perfect for auto-capturing issues that just happened and helps trace actions that lead to the bug.
  • Floating widget customization – Control the widget's look and placement.

Quick installation

To install the SDK, use the following command:

NPM install

npm install @betterbugs/web-sdk

Yarn install

yarn add @betterbugs/web-sdk

BetterBugs Web SDK initialization: Usage example

After installation, here's how to initialize the SDK instance in your web app:

TypeScript

import { Betterbugs } from '@betterbugs/web-sdk';

new Betterbugs({
  apiKey: process.env.TEST_API_KEY || '',
  mode: 'production',
});

Overview of the example code

Here's what it does:

1 - Imports the Betterbugs SDK — Pulls in Betterbugs from the @betterbugs/web-sdk package.

2 - Creates a new instance — The configuration object sets options for:

  • apiKey: Get value from environment variable (process.env.PROJECT_API_KEY).
  • mode: Running in production environment for additional debugging features.

Configurable Options: Customize SDK behavior

You can customize the SDK behavior with the following parameters:

OptionTypeDescription
apiKeystringYour workspace API key (required)
projectIdstringThe project to report bugs to. Required with a workspace API key; omit it if you are using a legacy project-scoped key.
metaDataRecord<string | number, string | number | null>Custom metadata to attach to reports (e.g., { userId: 123 })
recordType"recordVideo" | "domRecord"The "recordVideo" type (recommended for SPAs) is the traditional media recording method for video and audio. The "domRecord" type (recommended for Multi Page Apps) is the DOM recording method and may not be as accurate as the "recordVideo" type. Leave it unset and the SDK picks the best mode the browser supports — see Recording modes.
disableScreenshotbooleanDisable screenshot capturing
disableRecordingbooleanDisable screen recording
mediaRequiredbooleanRequire a screenshot or screen recording before the report can be submitted. Ignored when both disableScreenshot and disableRecording are enabled. Default: false.
enableAnnotationbooleanEnable annotation tools for screenshots.
showActionButtonbooleanDisplay/Hide the floating action button.
position{ top? : string, left? : string, right? : string, bottom? : string }Control the widget's screen position.
mode"development" | "production"Set development or production mode (defaults to "production").

The "development" mode can be set when the app is under development: the report form drops the Email field and instead shows Reporter (required) and Assignee (optional) pickers, populated with your workspace's members. The "production" mode is for end-users, meaning the app's customers can report a bug in the live environment via the Email field.
emailstringThe user's email address who is reporting the bug. Works only in "production" mode.
styles{ theme?: 'light' | 'dark', primaryColor?: string, primaryTextColor?: string, secondaryColor?: string, secondaryTextColor?: string, textColor?: string, mutedTextColor?: string, inputBgColor?: string, fontFamily?: string, fontFamilyUrl?: string (optional) }Set the styles of the widget
actionButtonComponentReact.ReactNode | stringComponent for the action button (React component or HTML string accepted).
successMessageHeaderTextstringMain heading text of the success message.
mainHeadingstringMain heading text of the widget
successMessageSubHeaderTextstringSub heading text of the success message.
maxRecordingMinutesnumberSet maximum recording length
emailFieldLabelstringSet label of email field
emailFieldPlaceholderstringSet placeholder of email field
emailFieldReadOnlybooleanShow the prefilled email but stop the reporter from editing it. Applies only while the address from the email option or setEmail() is a valid one — if it is missing or malformed the field stays editable, so the reporter can supply the address the form requires. Production mode only. Defaults to false.
titleFieldLabelstringSet label of title field
titleFieldPlaceholderstringSet placeholder of title field
descriptionFieldLabelstringSet label of description field
descriptionFieldPlaceholderstringSet placeholder of description field
issueTypesstring[]Options for the Issue Type dropdown in the report form. A list given here replaces the built-in options (General Enquiry, Give Feedback, Report a Bug) instead of adding to them. Entries are trimmed and de-duplicated; if none are usable the SDK warns and keeps the built-in options.
preferNativeCapturebooleanCapture screenshots from the browser's rendered pixels instead of re-rendering the DOM. Defaults to true. See Screenshot accuracy below.

Screenshot accuracy

Screenshots are captured with one of two engines, chosen automatically by what the browser supports.

Native capture (default, all desktop browsers). The SDK asks the browser for the actual rendered pixels via getDisplayMedia. The result matches what the user saw, including cross-origin iframes, <video>, WebGL and canvas content, and modern CSS such as backdrop-filter and blend modes. Region ("Crop") captures are cropped from the same frame, so both modes look identical.

The cost is one browser permission prompt per capture. What the user sees in that prompt depends on the engine:

BrowserPromptNotes
Chrome, Edge, Opera, BraveThis tab, pre-selectedOne click to confirm
Safari (macOS), FirefoxScreen or window pickerWebKit and Gecko expose no "this tab" surface, so the user shares a screen or window and the SDK crops the page's viewport out of the frame
Mobile (iOS + Android)—No browser on mobile implements screen capture; DOM rendering is always used

On Safari and Firefox the SDK falls back to DOM rendering automatically if it cannot locate the viewport in the shared frame reliably, or if the frame comes back at a lower resolution than a DOM render would produce — a sharp approximation beats a blurry photograph of the real thing.

If the user dismisses the prompt entirely, no screenshot is taken. Declining is treated as "don't capture me", not as a request for a lower-fidelity capture.

DOM rendering (fallback). Used on mobile browsers, when preferNativeCapture: false, and whenever native capture is unavailable or declined per the rules above. The page is re-rendered from the DOM by html2canvas-pro, which reimplements CSS layout in JavaScript and therefore will be inaccurate on some sites. Known limitations:

ContentResult
Cross-origin <iframe> (payment forms, embedded maps, third-party widgets)Renders blank — the browser gives no page any way to read those pixels
<video>Blank or poster frame
WebGL / 3D canvasCaptured only for canvases created after the SDK loaded; otherwise blank
backdrop-filter, blend modes, masks, color-mix()May render differently from the screen
Cross-origin images without CORS headersOmitted

When the SDK falls back to DOM rendering and detects any of the first three in the captured area, it shows the reporter a warning at capture time so an inaccurate screenshot is not submitted unnoticed.

Set preferNativeCapture: false to always use DOM rendering and never show a permission prompt — appropriate if the prompt is disruptive in your product and your pages do not contain the content listed above.

Recording modes

recordType controls how screen recordings are captured.

  • recordVideo — real video via the browser's MediaRecorder. Highest fidelity: it records exactly what was on screen, with audio.
  • domRecord — records DOM mutations and replays them. No video file, works on every device including mobile, and stays accurate through page navigations.

The SDK detects what the visitor's browser can actually deliver and picks the optimal mode for it — real video wherever the browser supports screen capture, DOM recording everywhere else. Recording formats differ between browser engines; the SDK handles that internally, so playback and upload work the same either way and there is nothing for you to configure.

Setting recordType explicitly

Your choice is honoured as given, with no capability substitution — useful when you want one consistent recording format across all your users. If the browser cannot support what you asked for, the SDK logs a console warning rather than silently overriding you.

The one exception is Electron, which does not support DOM recording: domRecord there is overridden to recordVideo with a warning.

Programmatic Methods: Control SDK behavior

Available methods for controlling the BetterBugs SDK behavior;

MethodDescription
setEmail()Update the email of the bug reporter.
setStyles()Update the styles of the widget.
getStyles()Get the styles of the widget.
show()Show the floating widget
hide()Hide the floating widget.
openWidget()Open the bug report widget.
closeWidget()Close the bug report widget.
setMetadata()Update the attached metadata.
captureScreenshot()Trigger screenshot capture.
startRecording()Start session recording.
stopRecording()Stop the ongoing recording.
on()Register an event listener.
off()Unregister an event listener.
destroy()Destroy the BetterBugs instance.

Lifecycle Event Hooks: For deeper integrations

Available hooks to listen to the lifecycle events:

EventTrigger description
emailUpdateTriggered when the email is updated.
screenshotTriggered after the screenshot is captured.
recordingStartTriggered when the recording starts.
recordingStopTriggered when the recording stops.
bugSubmitTriggered after the bug is submitted
metaDataUpdateTriggered when the metadata is updated
positionUpdateTriggered when the widget position changes.
widgetOpenTriggered when the widget is opened.
widgetCloseTriggered when the widget is closed.
showActionButtonTriggered when the action button is shown.
hideActionButtonTriggered when the action button is hidden.
sessionCreatedTriggered when a new session is created.

Floating widget customization options

The floating widget can be customized in various ways:

  • Positioning — Define widget position using { top, left, right, bottom }.
  • UI Customization — Modify button styles, background, and primary colors.

版本与发布记录

@betterbugs/web-sdk 共发布 55 个版本,首次发布于 2025/06/05;过去 12 个月发布了 13 个版本。

版本发布日期距今
0.0.47latest2026/09/211 个月前
0.0.462026/09/141 个月前
0.0.452026/09/022 个月前
0.0.442026/07/213 个月前
0.0.432026/07/173 个月前
0.0.422026/07/173 个月前

关于 @betterbugs/web-sdk 的常见问题

@betterbugs/web-sdk 是什么?

A web sdk package for Betterbugs

如何安装 @betterbugs/web-sdk?

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

@betterbugs/web-sdk 支持 TypeScript 吗?

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

@betterbugs/web-sdk 支持 ESM 还是 CommonJS?

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

@betterbugs/web-sdk 可以商用吗?

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

@betterbugs/web-sdk 的下载量有多少?

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

@betterbugs/web-sdk 还在维护吗?

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