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

browser-extension-toolkit

v0.5.0

Published

A comprehensive toolkit for building type-safe browser extensions with robust messaging patterns

Readme

Browser Extension Toolkit

A comprehensive toolkit for building type-safe browser extensions with robust messaging patterns.

Features

  • 🔒 Type-safe messaging system
  • 💾 Storage management system
  • 🔄 Background script proxy pattern
  • 🎯 Runtime validation
  • 📦 Modular handler system
  • 🚀 Built with Bun + Vite + TypeScript

Installation

bun add browser-extension-toolkit webextension-polyfill
# or
npm install browser-extension-toolkit webextension-polyfill

Project Structure

src/
├── lib/
│   ├── messaging/
│   │   ├── types.ts           # Core type definitions
│   │   ├── interfaces.ts      # Operation interfaces
│   │   ├── constants.ts       # Message type constants
│   │   └── messenger.ts       # MessagingProxy class
│   ├── storage/               # Storage system
│   │   ├── types.ts           # Storage type definitions
│   │   ├── storage.ts         # ExtensionStorage class
│   │   └── decorators.ts      # Storage decorators
│   ├── proxy/
│   │   ├── handlers/
│   │   │   ├── index.ts       # Handler exports
│   │   │   └── tabs.ts        # Tab operations
│   └── utils/
│       └── testing.ts         # Test utilities
├── tests/
│   ├── setup.ts               # Test configuration
│   ├── messenger.test.ts      # Core tests
│   └── handlers.test.ts       # Handler tests
└── examples/
    ├── popup/
    │   └── messaging.ts       # Popup usage example
    └── background/
        └── setup.ts           # Background setup example

Quick Start

Messaging

In your popup script:

import type { MessageTypes } from "browser-extension-toolkit";
import { MESSAGE_TYPES, MessagingProxy } from "browser-extension-toolkit";

const backgroundProxy = new MessagingProxy<MessageTypes>("popup");

// Open a new tab
const response = await proxy.sendProxyMessage(MESSAGE_TYPES.TAB.OPEN, {
  url: "https://example.com",
});

In your background script:

import type { MessageTypes } from "browser-extension-toolkit";
import {
  MESSAGE_TYPES,
  MessagingProxy,
  tabProxyHandlers,
} from "browser-extension-toolkit";

const backgroundProxy = new MessagingProxy<MessageTypes>("background");

// Register handlers
backgroundProxy.registerProxyHandler(
  MESSAGE_TYPES.TAB.OPEN,
  tabProxyHandlers.openTab,
);

Handlers

The toolkit includes pre-built handlers for common operations:

// Tab operations
tabProxyHandlers.openTab;
tabProxyHandlers.closeTab;
tabProxyHandlers.updateTab;

// Extension page operations
extensionProxyHandlers.openOptionsPage;
extensionProxyHandlers.openPopup;

Custom Handlers

Create your own handlers with full type safety:

import type { MessageHandler } from "browser-extension-toolkit";

const customHandler: MessageHandler<InputType, OutputType> = async (
  data,
  source,
  sender,
) => {
  // Implementation
  return result;
};

Storage

// Define your storage schema
interface UserPreferences {
  theme: "light" | "dark";
  fontSize: number;
  notifications: boolean;
}

// Using ExtensionStorage class
const storage = new ExtensionStorage<UserPreferences>({
  area: "sync",
  prefix: "prefs",
});

// Set multiple values in storage at once
await storage.bulkSet({ theme: "light", fontSize: 12, notifications: true });

// Set multiple values and remove others atomically
await store.bulkUpdate({
  set: {
    theme: "dark",
    fontSize: 16,
  },
  remove: ["notifications"],
});

// Set and get values with type safety
await storage.set("theme", "dark");
const theme = await storage.get("theme");

// Listen for changes
storage.addChangeListener((changes) => {
  if ("theme" in changes) {
    console.log("Theme changed:", changes.theme.newValue);
  }
});

// Using decorators
class Settings {
  @persist({ area: "sync", prefix: "settings" })
  public theme!: "light" | "dark";

  @persist({ area: "local", prefix: "settings" })
  public fontSize!: number;
}

Advanced Storage Usage

// Namespace isolation
const userStorage = new ExtensionStorage<UserData>({ prefix: "user" });
const settingsStorage = new ExtensionStorage<Settings>({ prefix: "settings" });

// Batch operations
const allSettings = await settingsStorage.getAll();

// Area-specific storage
const syncStorage = new ExtensionStorage<SyncData>({ area: "sync" });
const localStorage = new ExtensionStorage<LocalData>({ area: "local" });

// With serialization control
const rawStorage = new ExtensionStorage<RawData>({
  serialize: false,
});

// Change detection
storage.addChangeListener(async (changes, area) => {
  for (const [key, { oldValue, newValue }] of Object.entries(changes)) {
    console.log(`${key} changed in ${area}:`, { oldValue, newValue });
  }
});

Documentation

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT License. See LICENSE for details.