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

@fx-labs/monitor

v1.0.2

Published

轻量级浏览器监控 SDK(TypeScript)。该包对 XHR、WebSocket 和静态资源加载进行埋点,允许用户通过回调钩子对请求/消息/资源加载做自定义校验。

Readme

说明

轻量级浏览器监控 SDK(TypeScript)。该包对 XHR、WebSocket 和静态资源加载进行埋点,允许用户通过回调钩子对请求/消息/资源加载做自定义校验。

快速开始

前置条件:Node.js (16+)、pnpm

安装并构建:

pnpm install
pnpm run dev

构建产物:dist/index.js(ESM 包)以及类型声明(dist/)。

功能概述

  • 将全局的 XMLHttpRequest 替换为带有回调的实现,在 JSON 响应时会触发用户回调。
  • 将全局的 WebSocket 包裹为验证器,拦截 message 事件并调用用户回调,同时支持重连钩子。
  • 对全局的静态资源加载错误进行监听,并调用用户回调。

类型总结

  • MonitorConfig
    • instance: MonitorInstance
    • onValidateWebSocketMessage?: (event: MessageEvent, instance: WebSocket) => Promise<boolean>
    • onWebSocketReconnect?: (options: { max: number; time?: number }) => Promise<boolean>
    • onValidateHttpRequest?: <T = unknown>(event: T, instance: XMLHttpRequest) => Promise<boolean>
    • onSourceValidator?: (event?: { url?: string; tag?: string }, instance?: MonitorInstance) => Promise<boolean>

WSSetupOptionsXHRHookOptions 为各自安装函数使用的窄化类型。

使用示例

import { Monitor } from '@fx-labs/monitor'

const monitor = new Monitor({
	instance: {},
	onValidateHttpRequest: async (data, xhr) => {
		// http请求校验逻辑
		return true
	},
	onValidateWebSocketMessage: async (event, ws) => {
		// wss 消息校验逻辑
		return true
	},
	onWebSocketReconnect: async ({ max, time }) => {
		// 最大重连次数和时间间隔
		return true
	},
	onSourceValidator: async ({ url, tag }, instance) => {
		// 处理静态资源加载失败
		return true
	}
})