js-global-error-handler
v1.0.2
Published
A professional-grade, lightweight JavaScript library for capturing and reporting client-side errors.
Downloads
33
Maintainers
Readme
JS Global Error Handler SDK
A professional-grade, lightweight JavaScript library for capturing and reporting client-side errors.
https://www.npmjs.com/package/js-global-error-handler
Features
- Multi-Source Capture: Catch errors from
window.onerror, Promise rejections, Fetch/XHR failures, and manualconsole.errorcalls. - Normalization: Automatically formats various error types into a consistent JSON payload.
- Fingerprinting: Built-in deduplication to prevent flooding your servers with the same error.
- Aggressive Tracking: Monkey-patches core APIs in development/QA environments for deep visibility.
- Zero Dependencies: Lightweight and vanilla JavaScript.
Getting Started
Installation
npm install js-global-error-handlerUsage
Option 1: NPM (React, Vue, Angular, etc.)
import { init } from 'js-global-error-handler';
// Initialize at the very top of your app
init({
endpoint: 'https://api.yourdomain.com/errors',
method: 'POST',
env: 'production',
reportingEnabled: true
});Option 2: CDN / Script Tag (Legacy, Vanilla JS)
<!-- Load the library -->
<script src="https://cdn.jsdelivr.net/npm/js-global-error-handler/dist/tracker.umd.js"></script>
<script>
ErrorTracker.init({
endpoint: 'https://api.yourdomain.com/errors',
method: 'POST',
env: 'production'
});
</script>Configuration Options
Pass these options to the init() function:
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| endpoint | string | '/api/error/add' | API URL where errors will be sent. |
| method | string | 'POST' | HTTP method (POST, PUT, GET). |
| env | string | 'development' | Environment mode. production enables sending reports. |
| reportingEnabled | boolean | false | Master switch to enable/disable network reporting. |
| maxSameError | number | 5 | Prevents flooding by limiting duplicate error reports. |
| aggressiveTracking | boolean | true | Monkey-patches console.error, fetch, and XMLHttpRequest for deeper visibility. |
Development commands
npm run dev: Start development server with demo dashboard.npm run build: Build the library and demo files for production.
Directory Structure
src/js/tracker.js: Main entry point.src/js/utils.js: Error normalization and logic.src/js/transports.js: Network transmission.src/js/config.js: Centralized settings.
License
MIT
