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

@webblackbox/recorder

v0.2.0

Published

Browser event recorder and normalization engine for WebBlackbox capture pipelines.

Downloads

347

Readme


The event recording engine for WebBlackbox. Collects raw events from multiple sources (Chrome DevTools Protocol, content scripts, system), normalizes them into the unified WebBlackboxEvent format, and manages a time-windowed ring buffer for memory-efficient session recording.

Overview

  • WebBlackboxRecorder — Main entry point for ingesting and processing raw events
  • EventRingBuffer — Time-windowed circular buffer with configurable duration
  • DefaultEventNormalizer — Maps CDP and content script events to normalized payloads
  • ActionSpanTracker — Links related events within user action time windows
  • FreezePolicy — Evaluates auto-freeze conditions (errors, network failures, long tasks)
  • Redaction — Privacy-preserving payload scrubbing with pattern matching and hashing
  • Plugin System — Extensible event processing pipeline

Usage

Basic Recording

import { WebBlackboxRecorder } from "@webblackbox/recorder";
import { DEFAULT_RECORDER_CONFIG } from "@webblackbox/protocol";

const recorder = new WebBlackboxRecorder(DEFAULT_RECORDER_CONFIG, {
  onEvent: (event) => {
    // Forward normalized events to pipeline
    pipeline.ingest(event);
  },
  onFreeze: (reason, event) => {
    // Handle freeze (e.g., export ring buffer)
    console.log(`Session frozen: ${reason}`);
  }
});

// Ingest raw events from various sources
const result = recorder.ingest({
  source: "cdp",
  rawType: "Network.requestWillBeSent",
  tabId: 123,
  sid: "S-1706000000000-abc",
  t: Date.now(),
  mono: performance.now(),
  payload: {
    /* CDP event params */
  }
});

if (result.event) {
  console.log("Normalized event:", result.event.type);
}

if (result.freezeReason) {
  console.log("Freeze triggered:", result.freezeReason);
}

Ring Buffer

// Snapshot all buffered events
const events = recorder.snapshotRingBuffer();

// Get count of buffered events
const count = recorder.getBufferedEventCount();

// Clear the ring buffer
recorder.clearRingBuffer();

Using the Ring Buffer Directly

import { EventRingBuffer } from "@webblackbox/recorder";

const buffer = new EventRingBuffer(10); // 10-minute window

buffer.push(event);
const snapshot = buffer.snapshot(); // Returns events within the window
const size = buffer.size();
buffer.clear();

Event Normalization

The DefaultEventNormalizer handles mapping from raw source events to WebBlackboxEvent types:

CDP Events

| CDP Method | WebBlackbox Event | | --------------------------------------------------------------- | ------------------ | | Network.requestWillBeSent | network.request | | Network.responseReceived | network.response | | Network.loadingFinished | network.finished | | Network.loadingFailed | network.failed | | Network.webSocketCreated | network.ws.open | | Network.webSocketFrameReceived / Network.webSocketFrameSent | network.ws.frame | | Network.webSocketClosed | network.ws.close | | Runtime.exceptionThrown | error.exception | | Runtime.consoleAPICalled | console.entry | | Log.entryAdded | console.entry | | Page.frameNavigated | nav.commit | | Page.navigatedWithinDocument | nav.hash |

Content Script Events

| Raw Type | WebBlackbox Event | | ---------------------------------------------------- | ----------------------------------------------------------------- | | click / dblclick | user.click / user.dblclick | | keydown | user.keydown | | input | user.input | | submit | user.submit | | scroll | user.scroll | | mousemove | user.mousemove | | focus / blur | user.focus / user.blur | | resize | user.resize | | marker | user.marker | | visibilitychange | user.visibility | | mutation | dom.mutation.batch | | snapshot | dom.snapshot | | screenshot | screen.screenshot | | console | console.entry | | fetch / xhr | network.request / network.response | | fetchError | network.failed | | pageError / unhandledrejection / resourceError | error.exception / error.unhandledrejection / error.resource | | localStorageOp / localStorageSnapshot | storage.local.op / storage.local.snapshot | | sessionStorageOp | storage.session.op | | indexedDbOp / indexedDbSnapshot | storage.idb.op / storage.idb.snapshot | | cookieSnapshot | storage.cookie.snapshot | | longtask / vitals | perf.longtask / perf.vitals |

dom.rrweb.event is emitted when raw rrweb payloads are ingested (for example, lite mutation-summary events produced by the webblackbox capture agent).

Action Span Tracking

The ActionSpanTracker groups related events into action spans:

import { ActionSpanTracker } from "@webblackbox/recorder";

const tracker = new ActionSpanTracker(1500); // 1500ms action window

// Track user actions (click, submit, marker, nav)
// Related events within the time window are linked via ref.act

Action types: click, submit, marker, nav

Events within the action window receive a ref.act reference linking them to the action span. Network requests initiated during an action are also tracked.

Freeze Policy

The FreezePolicy evaluates conditions that should pause recording:

import { FreezePolicy } from "@webblackbox/recorder";

const policy = new FreezePolicy({
  freezeOnError: true,
  freezeOnNetworkFailure: true,
  freezeOnLongTaskSpike: true
});

const reason = policy.evaluate(event);
// Returns: "error" | "network" | "marker" | "perf" | null

Freeze conditions:

  • Error — Uncaught exceptions or unhandled rejections (error.resource is recorded but does not auto-freeze)
  • Network failure — Network request failures exceeding threshold (emits freeze reason "network")
  • Performance — Long tasks exceeding 200ms
  • Marker — User-triggered markers

Redaction

import { redactPayload } from "@webblackbox/recorder";

const redacted = redactPayload(payload, {
  redactHeaders: ["authorization", "cookie", "set-cookie"],
  redactCookieNames: ["token", "session"],
  redactBodyPatterns: ["password", "secret"],
  blockedSelectors: [".secret", "input[type='password']"],
  hashSensitiveValues: true // SHA-256 hash instead of [REDACTED]
});

Redaction is applied recursively through nested objects and supports:

  • HTTP header value masking by header name
  • Cookie value masking by cookie name
  • Body content masking by regex pattern
  • DOM element masking by CSS selector
  • Optional SHA-256 hashing for value correlation

Plugins

Extend the recorder with custom plugins:

import type { RecorderPlugin, RecorderPluginContext } from "@webblackbox/recorder";

const myPlugin: RecorderPlugin = {
  name: "my-plugin",

  onRawEvent(raw, ctx: RecorderPluginContext) {
    // Process raw events before normalization
    // Return modified raw event or null to drop
    return raw;
  },

  onEvent(event, ctx: RecorderPluginContext) {
    // Process normalized events after recording
    // Can annotate, transform, or filter events
    return event;
  }
};

const recorder = new WebBlackboxRecorder(config, hooks, normalizer, [myPlugin]);

Built-in Plugins

import {
  createRouteContextPlugin,
  createErrorFingerprintPlugin,
  createAiRootCausePlugin,
  createDefaultRecorderPlugins
} from "@webblackbox/recorder";

// Route context tracking per stream
const routePlugin = createRouteContextPlugin();

// Error fingerprint generation
const errorPlugin = createErrorFingerprintPlugin();

// AI-assisted root cause analysis
const aiPlugin = createAiRootCausePlugin(5000); // 5s analysis window

// Bundle of all default plugins
const plugins = createDefaultRecorderPlugins();

License

MIT