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

browsermesh-pod

v0.2.0

Published

Pod base class for browser execution contexts with Ed25519 identity, BroadcastChannel discovery, and peer messaging

Downloads

243

Readme

browsermesh-pod

Pod base class for browser execution contexts with Ed25519 identity, BroadcastChannel discovery, and peer messaging.

A Pod is any browser execution context (window, iframe, worker, service worker) that can execute code, receive messages, and be discovered/addressed. This package provides the standalone base class with zero framework dependencies.

Pods automatically generate an Ed25519 cryptographic identity, detect their execution context, discover same-origin peers via BroadcastChannel, and establish roles (autonomous, child, peer).

Install

npm install browsermesh-pod browsermesh-primitives

browsermesh-primitives is a peer dependency (provides Ed25519 identity generation).

Quick Start

import { Pod } from 'browsermesh-pod'

const pod = new Pod()
await pod.boot()

console.log(pod.podId)      // base64url Ed25519 public key hash
console.log(pod.kind)        // 'window', 'worker', 'iframe', etc.
console.log(pod.role)        // 'autonomous', 'peer', or 'child'
console.log(pod.peers.size)  // number of discovered peers

pod.on('message', (msg) => {
  console.log('Received:', msg.payload)
})

// Send to a specific peer
pod.send(otherPodId, { text: 'hello' })

// Broadcast to all peers
pod.broadcast({ text: 'hello everyone' })

await pod.shutdown()

Boot Sequence

The 6-phase boot sequence runs automatically when you call pod.boot():

| Phase | Name | Action | |-------|------|--------| | 0 | Install Runtime | Generate Ed25519 identity, detect kind & capabilities | | 1 | Install Listeners | Attach message handlers, call _onInstallListeners() hook | | 2 | Self-Classification | Detect parent/opener relationships | | 3 | Parent Handshake | Send POD_HELLO to parent/opener, wait for POD_HELLO_ACK | | 4 | Peer Discovery | Announce on BroadcastChannel, collect peer responses | | 5 | Role Finalization | Determine role, call _onReady() hook, emit 'ready' event |

State transitions: idle -> booting -> ready -> shutdown

Boot Options

await pod.boot({
  identity,           // PodIdentity — skip generation, reuse existing
  discoveryChannel,   // string — BroadcastChannel name (default: 'pod-discovery')
  handshakeTimeout,   // number — ms to wait for parent ACK (default: 1000)
  discoveryTimeout,   // number — ms to wait for peer responses (default: 2000)
  globalThis,         // object — override globalThis (for testing)
})

API

Getters

| Getter | Type | Description | |--------|------|-------------| | podId | string \| null | Base64url Ed25519 public key hash | | identity | PodIdentity \| null | Ed25519 key pair wrapper | | capabilities | PodCapabilities \| null | Detected runtime capabilities | | kind | PodKind \| null | Execution context classification | | role | PodRole | 'autonomous', 'child', or 'peer' | | state | PodState | 'idle', 'booting', 'ready', or 'shutdown' | | peers | Map<string, object> | Copy of known peers (podId -> info) |

Methods

| Method | Signature | Description | |--------|-----------|-------------| | boot | async boot(opts?) | Run 6-phase boot sequence | | shutdown | async shutdown(opts?) | Broadcast goodbye, close channels, clear peers | | send | send(targetPodId, payload) | Send message to a specific peer | | broadcast | broadcast(payload) | Send message to all peers (address: '*') | | on | on(event, cb) | Register event listener | | off | off(event, cb) | Remove event listener | | toJSON | toJSON() | Serializable snapshot of pod state |

Events

| Event | Data | When | |-------|------|------| | phase | { phase, name } | Each boot phase starts | | ready | { podId, kind, role } | Boot completes | | shutdown | { podId } | Pod shuts down | | error | { phase, error } | Boot phase fails | | peer:found | { podId, kind } | New peer discovered | | peer:lost | { podId } | Peer departed | | message | { type, from, to, payload, ts } | Incoming message |

Subclass Hooks

| Hook | Phase | Description | |------|-------|-------------| | _onInstallListeners(g) | 1 | Install additional message handlers | | _onReady() | 5 | Boot complete callback | | _onMessage(msg) | -- | Handle incoming targeted message |

Runtime Convenience Functions

import { installPodRuntime, createRuntime, createClient, createServer } from 'browsermesh-pod'

// Create and boot a pod (createRuntime is an alias)
const pod = await installPodRuntime({ context: globalThis })

// Lightweight client with short discovery timeout
const client = await createClient({ discoveryTimeout: 500 })

// Server-oriented pod with longer timeouts
const server = await createServer({ discoveryTimeout: 5000 })

Pod Kinds

detectPodKind(globalThis) returns one of:

| Kind | Detection | |------|-----------| | service-worker | instanceof ServiceWorkerGlobalScope | | shared-worker | instanceof SharedWorkerGlobalScope | | worker | instanceof WorkerGlobalScope | | worklet | instanceof AudioWorkletGlobalScope | | server | No window or document | | iframe | window !== window.parent | | spawned | window.opener is set | | window | Default (top-level window) |

Capabilities

detectCapabilities(globalThis) returns:

{
  messaging: { postMessage, messageChannel, broadcastChannel, sharedWorker, serviceWorker },
  network:   { fetch, webSocket, webTransport, webRTC },
  storage:   { indexedDB, cacheAPI, opfs },
  compute:   { wasm, sharedArrayBuffer, offscreenCanvas },
}

Wire Protocol

| Constant | Value | Purpose | |----------|-------|---------| | POD_HELLO | 'pod:hello' | Discovery announcement | | POD_HELLO_ACK | 'pod:hello-ack' | Discovery response | | POD_GOODBYE | 'pod:goodbye' | Graceful departure | | POD_MESSAGE | 'pod:message' | Inter-pod message | | POD_RPC_REQUEST | 'pod:rpc-request' | RPC call | | POD_RPC_RESPONSE | 'pod:rpc-response' | RPC result |

Message factories: createHello(), createHelloAck(), createGoodbye(), createMessage(), createRpcRequest(), createRpcResponse().

InjectedPod

Lightweight subclass for Chrome extension injection or bookmarklet use. Adds page text extraction, structured data extraction, and a visual overlay indicator.

import { InjectedPod } from 'browsermesh-pod'

const pod = new InjectedPod({ extensionBridge: chrome.runtime.connect() })
await pod.boot()

console.log(pod.pageContext)    // { url, title, origin, favicon }
console.log(pod.extractText())  // visible page text

Peer Dependency

This package requires browsermesh-primitives as a peer dependency for Ed25519 identity generation (PodIdentity). Install it alongside:

npm install browsermesh-pod browsermesh-primitives

License

MIT