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

web-watchtower

v1.0.0

Published

前端监控SDK,可收集并上报:代码报错、行为数据、性能数据等个性化指标...

Downloads

3

Readme

Web Monitor SDK

一个轻量级的前端监控 SDK,采用 OOP 与 FP 相结合的方式实现,支持错误监控、性能监控和用户行为监控。

特性

-[x] 🚀 轻量级,零依赖 -[x] 🎯 支持错误监控(JS异常、Promise异常、资源加载异常) -[x] 📊 支持性能监控(页面加载性能、绘制性能、核心性能指标) -[x] 🔍 支持用户行为监控(点击行为、页面跳转) -[x] 🔌 插件化架构,支持自定义扩展 -[ ] 🌊 支持采样率控制 -[ ] 💾 支持离线缓存 -[ ] 🔄 支持数据压缩

安装

npm install web-monitor-sdk
# 或
yarn add web-monitor-sdk

快速开始

import { Monitor } from 'web-monitor-sdk'

const monitor = new Monitor({
  reportUrl: 'https://your-report-url.com/collect',
  appId: 'your-app-id',
  userId: 'user-id',
  // 启用的监控类型
  enableError: true,
  enablePerformance: true,
  enableBehavior: true,
  // 采样率
  sampleRate: 1
})

// 初始化
monitor.init()

监控类型

错误监控

  • JS 运行时错误
  • Promise 未处理的 rejection
  • 资源加载错误(图片、脚本、样式表等)

性能监控

  • DNS 解析时间
  • TCP 连接时间
  • 首字节时间(TTFB)
  • DOM 解析时间
  • 页面加载完成时间
  • First Paint (FP)
  • Largest Contentful Paint (LCP)
  • First Input Delay (FID)

行为监控

  • 页面点击事件
  • 路由变化
  • Hash 变化

插件系统

SDK 支持通过插件进行功能扩展:

// 采样率插件示例
const samplingPlugin = {
  name: 'sampling',
  beforeSend(data) {
    return Math.random() < 0.1 ? data : false // 10% 采样率
  }
}

// 用户信息插件示例
const userPlugin = {
  name: 'user',
  beforeSend(data) {
    return {
      ...data,
      userId: localStorage.getItem('userId'),
      userInfo: {
        username: localStorage.getItem('username'),
        role: localStorage.getItem('role')
      }
    }
  }
}

// 使用插件
monitor.use(samplingPlugin)
monitor.use(userPlugin)

插件 API

插件可以实现以下生命周期方法:

interface Plugin {
  name: string;
  init?(monitor: Monitor): void;
  onEvent?(eventType: EVENTTYPES, data: any): void;
  beforeSend?(data: any): any | false;
  afterSend?(data: any): void;
  destroy?(): void;
}

数据上报格式

interface MonitorEvent {
  timestamp: number;
  type: 'error' | 'performance' | 'behavior';
  data: ErrorData | PerformanceData | BehaviorData;
}

注意事项

  1. 建议在页面早期初始化监控 SDK
  2. 合理设置采样率,避免产生过多数据
  3. 监控上报接口应该是高可用的
  4. 建议使用 navigator.sendBeacon 进行数据上报
  5. 注意防止监控代码影响业务代码的性能

License

MIT