@enamul1/frontend-carbon-tracker
v1.0.1
Published
A zero-impact browser telemetry tracker for network bloat, CPU long tasks, and OLED display luminance.
Maintainers
Readme
@enamul1/frontend-carbon-tracker
A zero-impact telemetry tracker for web browsers. It measures proxy metrics for energy consumption (Network bloat, CPU long tasks, and OLED display luminance) without causing battery drain or blocking the main thread.
Features
- Strict Size Budget: Under 1KB gzipped.
- Zero Runtime Dependencies: B2B production-ready.
- Main Thread Safe: CPU execution is kept under 5ms; background calculations are deferred via
requestIdleCallback. - Browser-Safe Failover: Fails silently and gracefully if performance APIs are unsupported.
Installation
npm install @enamul1/frontend-carbon-trackerUsage
Initialize the tracker with your telemetry ingestion endpoint:
import CarbonTracker from '@enamul1/frontend-carbon-tracker';
// Initializes the tracker and registers hooks/observers
const tracker = new CarbonTracker('https://your-telemetry-endpoint.com/api');
// Retrieve current in-memory stats programmatically
console.log(tracker.getStats());
// Output: { totalBytes: 1024, longTaskTotalTime: 45, lightModeLuminance: 21 }How It Works
- Network Bloat: Listens to
'resource'entries viaPerformanceObserver. - CPU Long Tasks: Listens to
'longtask'entries viaPerformanceObserver. - OLED Display Luminance: Calculates root background color luminance (0–100%) on idle callback.
- Transmission: Buffers data in memory and automatically dispatches it using
navigator.sendBeaconwhen the page visibility changes tohidden.
