@bugfender/capacitor

中文文档
5.0.0发布于 2026/07/27MITTypeScriptESM + CJS零依赖近 30 天下载 2700

Remote logging with Bugfender

原始使用文档
文档目录39 节
  1. Installation
  2. Usage
  3. Network logging
  4. API
  5. init(...)
  6. forceSendOnce()
  7. getDeviceURL()
  8. getSessionURL()
  9. getUserFeedback(...)
  10. log(...)
  11. log(...)
  12. warn(...)
  13. warn(...)
  14. error(...)
  15. error(...)
  16. trace(...)
  17. trace(...)
  18. info(...)
  19. info(...)
  20. fatal(...)
  21. fatal(...)
  22. removeDeviceKey(...)
  23. sendLog(...)
  24. sendIssue(...)
  25. sendCrash(...)
  26. sendUserFeedback(...)
  27. setDeviceKey(...)
  28. setForceEnabled(...)
  29. setSDKType(...)
  30. setNetworkLoggingEnabled(...)
  31. setNetworkLoggingCaptureBodies(...)
  32. setNetworkLoggingCaptureErrorResponseBodies(...)
  33. setNetworkLoggingRequestObfuscationHandler(...)
  34. setNetworkLoggingResponseObfuscationHandler(...)
  35. setNetworkLoggingURLFilter(...)
  36. setNetworkLoggingMaxRequestsPerMinute(...)
  37. Interfaces
  38. Type Aliases
  39. Enums

@bugfender/capacitor

Remote logging, crash reporting and in-app user feedback with Bugfender and Capacitor.

This module is a plugin for Capacitor since version 4. You can use @bugfender/capacitor in Ionic projects for iOS, Android, web and electron platforms.

Installation

npm install @bugfender/capacitor @bugfender/sdk @bugfender/common
npx cap sync

Usage

Import Bugfender like this:

import { Bugfender } from '@bugfender/capacitor';

Note: in an Ionic/Capacitor project, always import @bugfender/capacitor instead of @bugfender/sdk. This will enable the native features of the SDK that you wouldn't get otherwise.

Network logging

Network logging is opt-in and disabled by default. When enabled, HTTP requests appear in Bugfender as logs tagged bf_network.

Bugfender.setNetworkLoggingEnabled(true);
// Optional:
Bugfender.setNetworkLoggingCaptureBodies(false);
Bugfender.setNetworkLoggingCaptureErrorResponseBodies(true);
Bugfender.setNetworkLoggingURLFilter(
  ['https://api.example.com/*'],
  ['*/secrets/*']
);
Bugfender.setNetworkLoggingMaxRequestsPerMinute(60);

// Optional: redact sensitive headers/bodies before they are logged
Bugfender.setNetworkLoggingRequestObfuscationHandler((url, headers, body) => ({
  url,
  headers: { ...headers, authorization: '[REDACTED]' },
  body,
}));
Bugfender.setNetworkLoggingResponseObfuscationHandler((headers, body) => ({
  headers,
  body: body ? body.replace(/"token":"[^"]*"/g, '"token":"[REDACTED]"') : null,
}));

You can also enable it at init time with networkLoggingEnabled, networkLoggingCaptureBodies, and networkLoggingCaptureErrorResponseBodies.

Platform notes:

  • iOS: URLSession traffic is captured (including Capacitor HTTP when it uses URLSession). Requires Bugfender iOS SDK 3.0.1+.
  • Android: OkHttp traffic is captured via the android-okhttp adapter. Requires Bugfender Android SDK 4.x. Note: Capacitor's built-in CapacitorHttp uses HttpURLConnection on Android and is not observed; apps should use OkHttp (or the example's sendInstrumentedNetworkRequest helper) for network logs.
  • Web / Electron: Uses @bugfender/sdk (≥ 4.0.0), which intercepts fetch and XMLHttpRequest.

API

Please check the following URL for a complete API reference: https://js.bugfender.com.

init(...)

init(options: SDKOptions) => Promise<void>
ParamType
optionsSDKOptions

forceSendOnce()

forceSendOnce() => void

getDeviceURL()

getDeviceURL() => Promise<string>

Returns: Promise<string>


getSessionURL()

getSessionURL() => Promise<string>

Returns: Promise<string>


getUserFeedback(...)

getUserFeedback(options?: UserFeedbackOptions | undefined) => Promise<UserFeedbackResult>
ParamType
optionsUserFeedbackOptions

Returns: Promise<UserFeedbackResult>


log(...)

log(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

log(...)

log(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

warn(...)

warn(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

warn(...)

warn(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

error(...)

error(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

error(...)

error(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

trace(...)

trace(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

trace(...)

trace(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

info(...)

info(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

info(...)

info(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

fatal(...)

fatal(obj: unknown, ...objs: unknown[]) => void
ParamType
objunknown
objsunknown[]

fatal(...)

fatal(msg: string, ...subst: unknown[]) => void
ParamType
msgstring
substunknown[]

removeDeviceKey(...)

removeDeviceKey(key: string) => void
ParamType
keystring

sendLog(...)

sendLog(log: LogEntry) => void
ParamType
logLogEntry

sendIssue(...)

sendIssue(title: string, text: string) => Promise<string>
ParamType
titlestring
textstring

Returns: Promise<string>


sendCrash(...)

sendCrash(title: string, text: string) => Promise<string>
ParamType
titlestring
textstring

Returns: Promise<string>


sendUserFeedback(...)

sendUserFeedback(title: string, text: string) => Promise<string>
ParamType
titlestring
textstring

Returns: Promise<string>


setDeviceKey(...)

setDeviceKey(key: string, value: DeviceKeyValue) => void
ParamType
keystring
valueDeviceKeyValue

setForceEnabled(...)

setForceEnabled(state: boolean) => void
ParamType
stateboolean

setSDKType(...)

setSDKType(sdkType: string, version: number) => void
ParamType
sdkTypestring
versionnumber

setNetworkLoggingEnabled(...)

setNetworkLoggingEnabled(enabled: boolean) => void

Enable or disable network logging (default: false).

ParamType
enabledboolean

setNetworkLoggingCaptureBodies(...)

setNetworkLoggingCaptureBodies(capture: boolean) => void

Full mode: capture request/response bodies (default: false).

ParamType
captureboolean

setNetworkLoggingCaptureErrorResponseBodies(...)

setNetworkLoggingCaptureErrorResponseBodies(capture: boolean) => void

Error-only body mode: capture response body only for HTTP status >= 400 (default: false).

ParamType
captureboolean

setNetworkLoggingRequestObfuscationHandler(...)

setNetworkLoggingRequestObfuscationHandler(handler: ((url: string, headers: Record<string, string>, body: string | null) => { url: string; headers: Record<string, string>; body: string | null; }) | null) => void

Request obfuscation — (url, headers, body) => { url, headers, body }.

ParamType
handler((url: string, headers: Record<string, string>, body: string | null) => { url: string; headers: Record<string, string>; body: string | null; }) | null

setNetworkLoggingResponseObfuscationHandler(...)

setNetworkLoggingResponseObfuscationHandler(handler: ((headers: Record<string, string>, body: string | null) => { headers: Record<string, string>; body: string | null; }) | null) => void

Response obfuscation — (headers, body) => { headers, body }.

ParamType
handler((headers: Record<string, string>, body: string | null) => { headers: Record<string, string>; body: string | null; }) | null

setNetworkLoggingURLFilter(...)

setNetworkLoggingURLFilter(allowlist: string[] | null, denylist: string[] | null) => void

URL filtering: allowlist / denylist. Null = no filter.

ParamType
allowliststring[] | null
denyliststring[] | null

setNetworkLoggingMaxRequestsPerMinute(...)

setNetworkLoggingMaxRequestsPerMinute(count: number | null) => void

Rate limit. Null = no limit.

ParamType
countnumber | null

Interfaces

SDKOptions

PropTypeDescription
appKeystringThe app key to log into
apiURLstringBase URL to Bugfender API
buildstringApp build identifier
baseURLstringBase URL to Bugfender web dashboard
debugbooleanSet SDK in debug mode
deviceNamestringDevice name, this will be shown on the dashboard devices list. Defaults to browser + OS.
overrideConsoleMethodsbooleanOverride default window.console so it also logs to Bugfender. Defaults to true.
printToConsolebooleanPrint also with window.console when Bugfender logging methods are called. Defaults to true.
logBrowserEventsbooleanRegister a handler for most common browser events to report them to Bugfender. Defaults to true.
logUIEventsbooleanRegister a handler for most common UI events to report them to Bugfender. Defaults to true.
registerErrorHandlerbooleanRegister error handler for uncaught errors that reports a crash to Bugfender. Defaults to true.
ignoreExceptionExceptionFilterConfigure exception filtering to ignore certain exceptions from being reported as crashes. Can be: - A function: (info) =&gt; info.message.includes('Script error') - An array of patterns: ['Script error', /^ResizeObserver/i] - An object with both: { filter: (info) =&gt; ..., patterns: [...] }
versionstringApp version identifier
networkLoggingEnabledbooleanEnable network request/response capture. Defaults to false. Web/JS: requires init before use.
networkLoggingCaptureBodiesbooleanWhen network logging is enabled, capture request/response bodies (full mode). Defaults to false.
networkLoggingCaptureErrorResponseBodiesbooleanCapture only error response bodies for HTTP status >= 400 (without full body capture). Defaults to false.
maximumLocalStorageSizenumberSet the maximum size to store local log files in bytes. Range accepted is from 1MB to 50MB. Defaults to 5MB. iOS & Android only.
enableLogcatLoggingbooleanLogs all logs written via Logcat. Defaults to false. Android only.

ExceptionInfo

Information about an exception that can be used to determine if it should be ignored

PropTypeDescription
messagestringThe error message
errorErrorThe error object, if available
stackstringThe stack trace, if available
filenamestringThe filename/URL where the error occurred
linenumberThe line number where the error occurred
handlerstringThe type of handler that caught the error (e.g., 'Error', 'UnhandledRejection')

Error

PropType
namestring
messagestring
stackstring

RegExp

PropTypeDescription
sourcestringReturns a copy of the text of the regular expression pattern. Read-only. The regExp argument is a Regular expression object. It can be a variable name or a literal.
globalbooleanReturns a Boolean value indicating the state of the global flag (g) used with a regular expression. Default is false. Read-only.
ignoreCasebooleanReturns a Boolean value indicating the state of the ignoreCase flag (i) used with a regular expression. Default is false. Read-only.
multilinebooleanReturns a Boolean value indicating the state of the multiline flag (m) used with a regular expression. Default is false. Read-only.
lastIndexnumber
MethodSignatureDescription
exec(string: string) => RegExpExecArray | nullExecutes a search on a string using a regular expression pattern, and returns an array containing the results of that search.
test(string: string) => booleanReturns a Boolean value that indicates whether or not a pattern exists in a searched string.
compile() => this

RegExpExecArray

PropType
indexnumber
inputstring

UserFeedbackResultSuccess

PropTypeDescription
isSenttrueThe user has sent the feedback.
feedbackURLstringBugfender URL for the feedback.

UserFeedbackResultCancel

PropTypeDescription
isSentfalseThe user has closed the modal without sending it.

UserFeedbackOptions

Options object for Bugfender.getUserFeedback with customised modal strings.

PropTypeDescription
titlestringDefault: Feedback.
hintstringDefault: Please insert your feedback here and click send.
subjectPlaceholderstringDefault: Subject….
feedbackPlaceholderstringDefault: Your feedback….
submitLabelstringDefault: Send.
closeLabelstringDefault: Close. iOS only.

LogEntry

Log Entry object interface

PropTypeDescription
linenumberThe line number where the log was triggered from
levelLogLevelThe log's level based on LogLevel constant
tagstringThe log's tag
methodstringThe method name where the log was triggered from
filestringThe file name where the log was triggered from
textstring | unknown[]Text can be either: - string with the content - unknown[] array compatible with console.* signature
urlstringThe log's origin URL. This attribute is ignored on Android & iOS

Type Aliases

ExceptionFilter

Configuration for ignoring exceptions. Can be:

  • A function that receives exception info and returns boolean
  • An array of patterns (strings or RegExp) to match against the error message
  • A combination of both (function and patterns)

ExceptionFilterFunction | ExceptionPattern[] | { /** Function to determine if exception should be ignored / filter?: ExceptionFilterFunction; /* Patterns to match against error message */ patterns?: ExceptionPattern[]; }

ExceptionFilterFunction

A function that determines whether an exception should be ignored. Return true to ignore the exception, false to report it.

(info: ExceptionInfo): boolean

ExceptionPattern

A pattern that can be used to match exception messages. Can be a string (exact or substring match) or a RegExp.

string | RegExp

UserFeedbackResult

UserFeedbackResultSuccess | UserFeedbackResultCancel

DeviceKeyValue

string | number | boolean

Record

Construct a type with a set of properties K of type T

{ [P in K]: T; }

Enums

LogLevel

MembersValue
Debug0
Warning1
Error2
Trace3
Info4
Fatal5

版本与发布记录

@bugfender/capacitor 共发布 14 个版本,首次发布于 2022/08/15;过去 12 个月发布了 2 个版本。

版本发布日期距今
5.0.0latest2026/07/273 个月前
4.0.02026/01/169 个月前
3.2.12025/03/071.7 年前
3.2.02025/03/061.7 年前
3.1.02024/09/192 年前
3.0.02024/07/172 年前

其他发布通道:next → 1.0.0-rc.1。

关于 @bugfender/capacitor 的常见问题

@bugfender/capacitor 是什么?

Remote logging with Bugfender

如何安装 @bugfender/capacitor?

在项目目录运行 npm install @bugfender/capacitor,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bugfender/common(^2.0.0)、@bugfender/sdk(^4.0.1)、@capacitor/core(^8.4.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bugfender/capacitor 支持 TypeScript 吗?

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

@bugfender/capacitor 支持 ESM 还是 CommonJS?

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

@bugfender/capacitor 可以商用吗?

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

@bugfender/capacitor 的下载量有多少?

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

@bugfender/capacitor 还在维护吗?

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