H5 SDK
The HealthGuard Web SDK captures errors, requests, and performance data in browser (H5) environments.
Installation
bash
npm install @healthguard/sdk-webBasic 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
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
appKey | string | Yes | - | Unique app identifier |
endpoint | string | Yes | - | Collector endpoint URL |
release | string | No | - | App version |
environment | string | No | - | Environment: development / test / production |
userId | string | No | - | Business user identifier |
autoCapture | boolean | object | No | false | Auto-capture errors and requests |
flushIntervalMs | number | No | 5000 | Batch flush interval in milliseconds |
maxBatchSize | number | No | 10 | Max 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
userIdor anonymous ID; no real identity data is collected