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

@nexus-js/chrome

v0.3.1

Published

Chrome extension adapter for Nexus framework

Downloads

268

Readme

@nexus-js/chrome

Chrome extension adapter for the Nexus framework, providing seamless cross-context communication for Chrome extensions.

Installation

npm install @nexus-js/chrome @nexus-js/core

Quick Start

Background Script

import { Token } from "@nexus-js/core";
import { usingBackgroundScript } from "@nexus-js/chrome";

// Define service interface and token
interface IBackgroundService {
  getSettings(): Promise<Settings>;
  saveSettings(settings: Settings): Promise<void>;
}

const BackgroundServiceToken = new Token<IBackgroundService>(
  "background-service",
);

// Configure Nexus for background context
const backgroundNexus = usingBackgroundScript();

// Expose a class service on the configured background instance
@backgroundNexus.Expose(BackgroundServiceToken)
class BackgroundService implements IBackgroundService {
  async getSettings() {
    return await chrome.storage.sync.get("settings");
  }

  async saveSettings(settings: Settings) {
    await chrome.storage.sync.set({ settings });
  }
}

Content Script

import { nexus } from "@nexus-js/core";
import { usingContentScript } from "@nexus-js/chrome";
import { BackgroundServiceToken } from "./shared/tokens";

// Configure Nexus for content script context
usingContentScript();

// Use background service
async function main() {
  const backgroundService = await nexus.create(BackgroundServiceToken);

  const settings = await backgroundService.getSettings();
  console.log("Settings:", settings);
}

main();

Popup

import { nexus } from "@nexus-js/core";
import { usingPopup } from "@nexus-js/chrome";
import { BackgroundServiceToken } from "./shared/tokens";

// Configure Nexus for popup context
async function initPopup() {
  usingPopup();

  const backgroundService = await nexus.create(BackgroundServiceToken);

  // Use the service
  const settings = await backgroundService.getSettings();
  // Update UI...
}

initPopup();

Features

  • Type-safe communication between all Chrome extension contexts
  • Chrome runtime port integration for extension context messaging
  • Pre-configured matchers for common scenarios
  • Zero-configuration setup for standard use cases
  • Full TypeScript support with discriminated union types

Content scripts, popups, and options pages can usually call background services with nexus.create(Token) when the Token has a defaultTarget for the background or the adapter has a unique background connectTo fallback. Background-to-content-script calls usually need an explicit descriptor or matcher because there may be many content scripts. Application code owns tab/window discovery and decides when identity changes require new handles. Raw proxies and refs are session-bound: after disconnect, service worker restart, or other session replacement, application code should recreate handles and decide any retry or rebuild policy explicitly.

For object services, Nexus State stores, or Relay providers, configure the runtime and call provide(...) instead of using class decorators:

usingBackgroundScript().provide(BackgroundServiceToken, backgroundService);

API Reference

Config Factories And Runtime Helpers

Use createXConfig(...) helpers when you need pure config for composeNexusConfig([...]). Use usingX(...) helpers when you want the helper to configure the shared nexus instance immediately and return that instance.

Pure config factories:

  • createBackgroundScriptConfig(options?)
  • createContentScriptConfig(options?)
  • createPopupConfig(options?)
  • createOptionsPageConfig(options?)
  • createDevToolsPageConfig(options?)
  • createOffscreenDocumentConfig(options)
  • createExtensionPageConfig(meta)

Effectful runtime helpers:

  • usingBackgroundScript(options?) - Configure for background script/service worker
  • usingContentScript(options?) - Configure for content script, including visibility metadata updates
  • usingPopup(options?) - Configure for popup; pass caller-discovered tabId or windowId if your app needs them
  • usingOptionsPage(options?) - Configure for options page
  • usingDevToolsPage(options?) - Configure for devtools page
  • usingOffscreenDocument(options) - Configure for offscreen document
  • usingExtensionPage(meta) - Configure for a custom extension page connected to background

Pre-defined Matchers

  • any-content-script - Match any content script
  • any-popup - Match any popup
  • visible-content-script - Match visible content scripts
  • background - Match background script

Types

  • ChromeEndpointMeta - Discriminated union for built-in Chrome contexts plus custom contexts that include a context discriminator
  • ChromePlatformMeta - Chrome-specific platform metadata
  • Context-specific types: ChromeBackgroundMeta, ChromeContentScriptMeta, etc.

Advanced Usage

Custom Matchers

import { ChromeMatchers, type ChromeEndpointMeta } from "@nexus-js/chrome";

// Use built-in matchers
const githubContentScripts = await nexus.createMulticast(ServiceToken, {
  target: { matcher: ChromeMatchers.contentScriptByUrl("github.com") },
});

// Custom matcher
const customMatcher = (identity: ChromeEndpointMeta) =>
  identity.context === "content-script" &&
  identity.url.includes("special-page");

Dynamic Metadata Updates

// Content script automatically tracks visibility changes
// Manual updates are also supported:
nexus.updateIdentity({
  url: window.location.href, // Update URL for SPA navigation
  isVisible: true,
});

Testing Boundary

Use @nexus-js/testing and createMockNexus() for unit tests of application code that consumes Chrome-targeted services through a NexusInstance.

Do not use the mock to validate Chrome adapter behavior. It does not exercise Chrome runtime ports, tab or frame metadata collection, service worker lifecycle, extension context startup, runtime disconnect ordering, or Chrome permission behavior.

Use Chrome adapter tests or extension E2E tests for those platform behaviors.

New Context Support

// Options page
import { usingOptionsPage } from "@nexus-js/chrome";
usingOptionsPage();

// DevTools page
import { usingDevToolsPage } from "@nexus-js/chrome";
usingDevToolsPage();

// Offscreen document
import { usingOffscreenDocument } from "@nexus-js/chrome";
usingOffscreenDocument("audio-processing");

License

MIT