@bugfender/capacitor

July 24, 2026 · View on GitHub

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