A professional-grade, lightweight JavaScript library for capturing and reporting client-side errors.
https://www.npmjs.com/package/js-global-error-handler
- 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.
npm install js-global-error-handlerimport { 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
});<!-- 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>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. |
npm run dev: Start development server with demo dashboard.npm run build: Build the library and demo files for production.
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.
MIT