npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

extenshi-collector

v0.7.0

Published

A small JavaScript library that collects runtime metrics from browser extensions

Downloads

13

Readme

extenshi-collector

A production-ready JavaScript library that collects runtime metrics from browser extensions with advanced batching, offline queue management, and automatic retry capabilities. The library is written in TypeScript and can be used either as an npm dependency or via a direct script tag.

Installation

Using npm

npm install extenshi-collector

Using yarn

yarn add extenshi-collector

Usage

As an npm package

import { startCollector } from 'extenshi-collector'
startCollector({ endpoint: 'https://example.com/log' })

Via script tag

Build the project and include dist/index.js in your extension:

<script type="module" src="./dist/index.js"></script>
<script type="module">
  import { startCollector } from './dist/index.js'
  const collector = startCollector({ endpoint: 'https://example.com/log' })
  collector.logCustomEvent('my-event', { foo: 'bar' })
</script>

Or install it through npm:

import { startCollector } from 'collector'
const collector = startCollector({ 
  endpoint: 'https://example.com/log',
  batchSize: 25,
  flushInterval: 3000
})
collector.logCustomEvent('my-event', { foo: 'bar' })

Features

  • Automatic Event Collection: Page loads, clicks, errors, and network requests
  • Batch Processing: Groups events for efficient network usage (default: 50 events per batch)
  • Offline Support: Persists events in IndexedDB when offline, syncs when back online
  • Retry Logic: Automatic retry with exponential backoff for failed requests
  • Data Sanitization: Automatically redacts sensitive information (emails, tokens, passwords)
  • Browser Extension Support: Special handling for Chrome extension environments
  • TypeScript Support: Full type definitions included

Configuration Options

interface CollectorConfig {
  endpoint: string           // Required: API endpoint for sending events
  captureConsole?: boolean   // Capture console logs (default: false)
  batchSize?: number         // Events per batch (default: 50)
  flushInterval?: number     // Auto-flush interval in ms (default: 5000)
  maxRetries?: number        // Max retry attempts (default: 3)
  queueConfig?: {
    maxQueueSize?: number    // Max events in queue (default: 1000)
    eventTTL?: number        // Event expiry time (default: 24 hours)
    persistence?: 'memory' | 'localStorage' | 'indexedDB'
  }
}

API Reference

startCollector(config)

Initializes the collector and returns an API object.

const collector = startCollector({
  endpoint: 'https://api.example.com/analytics',
  batchSize: 25,
  flushInterval: 3000
})

collector.logCustomEvent(name, data)

Logs a custom event with optional data.

collector.logCustomEvent('button_click', { 
  buttonId: 'submit',
  page: 'checkout' 
})

collector.flush()

Manually flush all queued events.

await collector.flush()

collector.queueSize()

Returns the current number of queued events.

const pending = collector.queueSize()
console.log(`${pending} events pending`)

Automatic Event Types

The collector automatically captures these events:

  • init: When the collector starts (includes browser fingerprint)
  • pageload: Page load timing
  • click: User clicks (includes target element tag)
  • error: JavaScript errors and unhandled promise rejections
  • request: Fetch API calls (sanitized request/response data)
  • log: Console output (when captureConsole: true)

The collector spawns a worker that listens for initialization, click events, network requests and runtime errors. All events are sanitised before being sent to the provided logging endpoint.

Development

  1. Install dependencies with npm install.
  2. Build the library using npm run build -w collector.