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

cosmic-eye

v0.6.0

Published

RUM metrics toolkit for SPAs: duplicate request detection and route transition timing

Downloads

798

Readme

CosmicEye

RUM metrics toolkit for SPAs: duplicate request detection and route transition timing.
Two independent modules + extensions:

  • RDR (RUM Duplicate Requests) — detects and logs duplicate API requests.
  • RT (Route Transition Metrics) — measures route transition timing (render + TTI).
  • ExtensionsobserveHistory, RouteRenderObserver, mobxSpy.

Installation

npm install cosmic-eye

Chrome DevTools Extension

Quick start

RDR

import { rdr, initRDR } from 'cosmic-eye';

const ok = initRDR({ samplingRate: 0.05, send: (p) => analytics.send('rdr', p) });

// RPC-style
rdr.reqHandlerRpc({ s: 'UserService', m: 'getProfile', p: { id: 42 }, b: {} });
// HTTP-style
rdr.reqHandlerHttp({ httpMethod: 'GET', endpoint: '/api/users/42' });

RT + observeHistory + RouteRenderObserver

import { initRT, rt, observeHistory } from 'cosmic-eye';
import { createBrowserHistory } from 'history';

const history = createBrowserHistory();
initRT({ send: (p) => analytics.send('rt', p), includePathname: true });

const observer = observeHistory(history);
observer.subscribe(({ pathname, search }) => {
  rt.startTransition(pathname, search);
});
import { RouteRenderObserver } from 'cosmic-eye/react';

<RouteRenderObserver
  onRouteChange={[(pathname) => { rt.markRendered(pathname); }]}
>
  {children}
</RouteRenderObserver>

How duplicate detection works

  1. Each incoming payload is hashed into a reqHash (FNV-1a of endpoint + params + body)
  2. If the same reqHash was seen within duplicateThresholdMs (default 1 000 ms), a log entry is created
  3. Log entries accumulate in a buffer and are flushed:
    • Every flushIntervalMs (15 s)
    • When buffer reaches flushMaxEvents (50)
    • On visibilitychange (tab hidden)
    • On pagehide (page close)
    • On destroy() or flush()

How route transition tracking works

  1. On navigation, call startTransition(pathname, search?) — RT creates a transition ID, stores the start time, and normalizes routeName.
  2. After route commit, call markRendered(pathname) — RT records render completion time.
  3. If there is critical async work, use trackCritical() — RT waits until all critical tasks are finished.
  4. RT marks the transition as interactive after rafCount frames + idle wait (idleTimeoutMs), then sends a transition event.
  5. The event includes routeRenderMs and routeTtiMs (and optional pathname / search if enabled in config).
  6. If interactive state is not reached before criticalTimeoutMs (default 20 s), RT still sends the event with timedOut: true.
  7. abortPending(reason?) sends an abort event; destroy() stops tracking and clears timers.

Sampling

Sampling is config-driven via samplingRate (0..1). Default is 0.05 (5%). The decision is deterministic when a stable client ID is available (clientId from config or persisted localStorage). If storage is unavailable and no explicit clientId is provided, fallback ID generation may produce non-deterministic results between calls.

API

RDR

| Function | Returns | Description | |----------|---------|-------------| | initRDR(config?) | boolean | Initialize with optional config. | | rdr.isInitialized() | boolean | Check if active. | | rdr.reqHandlerRpc(payload) | RdrReqHandlerResult | Process RPC request. | | rdr.reqHandlerHttp(payload) | RdrReqHandlerResult | Process HTTP request. | | rdr.flush(trigger?, meta?) | RdrFlushResult | Manual flush. | | rdr.resetTiming() | RdrResetTimingResult | Reset page load timestamp. | | rdr.resetActions() | RdrResetActionsResult | Clear action buffer. | | rdr.destroy() | RdrDestroyResult | Stop, flush, clean up. |

RT

| Function | Returns | Description | |----------|---------|-------------| | initRT(config?) | boolean | Initialize with optional config. | | rt.isInitialized() | boolean | Check if active. | | rt.startTransition(pathname, search?) | RtStartTransitionResult | Start transition timing. | | rt.markRendered(pathname) | RtMarkRenderedResult | Mark render completion. | | rt.trackCritical(promise?) | RtTrackCriticalResult | Track critical operation. | | rt.abortPending(reason?) | RtAbortPendingResult | Abort active transition. | | rt.destroy() | RtDestroyResult | Clean up. |

observeHistory

| Function | Description | |----------|-------------| | observeHistory(history) | Create observer (idempotent via WeakMap) | | observer.subscribe(listener) | Subscribe to INIT/PUSH/REPLACE/POP. Returns unsubscribe | | observer.unpatch() | Remove patch, clean up |

RouteRenderObserver (cosmic-eye/react)

| Prop | Type | Description | |------|------|-------------| | children | ReactNode | Child elements | | onRouteChange | Array<(pathname, search) => void> | Callbacks on route change |

Project structure

src/
  index.ts              — public API (re-exports only, no React)
  react.ts              — React extensions entry point (cosmic-eye/react)
  shared/               — shared utilities (time, hash, sampling, enrichers, env)
  rdr/                  — RDR module: duplicate request detection
  rt/                   — RT module: route transition metrics
  extensions/
    history-route-observer/ — navigation observer (pre-render)
    route-render-observer/  — RouteRenderObserver React component (post-render)
    mobx-spy/              — MobX spy extension (DI-only via `mobxSpy.init({ spy })`)
tests/
  rdr/                  — RDR tests
  rt/                   — RT tests
  extensions/           — extension tests (observer, route-render, mobx-spy)

Test commands

| Command | Scope | |---------|-------| | npm run test | all tests | | npm run test:rdr | RDR only | | npm run test:rt | RT only | | npm run test:extensions | extensions only | | npm run test:watch | all, watch mode |

Documentation

Each module has its own README with integration guide, configuration reference, and event schema:

License

MIT