Skip to content

H5 SDK

The HealthGuard Web SDK captures errors, requests, and performance data in browser (H5) environments.

Installation

bash
npm install @healthguard/sdk-web

Basic Usage

js
import { createHealthGuardClient } from '@healthguard/sdk-web';

const client = createHealthGuardClient({
  appKey: 'your-app-key',
  endpoint: 'https://your-collector.com/api/events/batch',
  autoCapture: true
});

Configuration

OptionTypeRequiredDefaultDescription
appKeystringYes-Unique app identifier
endpointstringYes-Collector endpoint URL
releasestringNo-App version
environmentstringNo-Environment: development / test / production
userIdstringNo-Business user identifier
autoCaptureboolean | objectNofalseAuto-capture errors and requests
flushIntervalMsnumberNo5000Batch flush interval in milliseconds
maxBatchSizenumberNo10Max events per batch

autoCapture Options

When autoCapture is true, all auto-capture features are enabled:

js
autoCapture: {
  errors: true,           // window.onerror
  unhandledRejections: true,  // unhandledrejection
  fetch: true,            // Intercept fetch
  xhr: true               // Intercept XMLHttpRequest
}

Manual API

captureException(error)

Manually report an error:

js
try {
  riskyOperation();
} catch (err) {
  client.captureException(err);
}

captureHttp(input)

Manually report an HTTP request:

js
client.captureHttp({
  method: 'POST',
  url: '/api/users',
  status: 500,
  duration: 240,
  success: false,
  errorMessage: 'Internal Server Error'
});

addBreadcrumb(breadcrumb)

Add a breadcrumb:

js
client.addBreadcrumb({
  type: 'navigation',
  message: 'User navigated to /checkout',
  data: { from: '/cart' }
});

flush()

Immediately flush the queue and send all pending events:

js
await client.flush();

Privacy & Sanitization

The SDK sanitizes the following by default:

  • URL query parameters: authorization, password, token, secret, cookie, etc.
  • Request body and response body are not collected
  • Uses business-provided userId or anonymous ID; no real identity data is collected

Released under the MIT License.