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 🙏

© 2024 – Pkg Stats / Ryan Hefner

report-err-plugin

v1.0.1

Published

front error capture and report

Downloads

6

Readme

report-err-plugin

report-err-plugin 是一个用于捕获和上报错误信息的 JavaScript 插件。它可以捕获全局的资源加载错误、JS 错误和未捕获的 Promise 错误,并上报。

安装

使用 npm 安装:

npm install report-err-plugin

使用

在你的项目中引入 report-err-plugin,并创建一个新的实例:

import reportErrPlugin from 'report-err-plugin'

const reportErrInstance = new reportErrPlugin({
  maxSize: 1,
  reportFunc (data) {
    console.log(data);
  }
})

vue 项目中:

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import reportErrPlugin from 'report-err-plugin'

const app = createApp(App)

const reportErrInstance = new reportErrPlugin({
  maxSize: 1,
  reportFunc (data) {
    // 将错误信息通过 ajax 传输到服务端
    axios.post('/url', data)
  }
})

app.use(reportErrInstance).use(router).mount('#app')

然后,你可以使用 reportErrInstance 来捕获和上报错误信息。

配置

reportErrPlugin 的构造函数接收一个配置对象,包含以下的属性:

  • maxSize: 需要上报的信息累计到多少条才进行上报,一般不会产生一条错误就马上进行上报,而是累积到一定量再一次性上报。

  • reportFunc: 一般在此函数中将得到的错误信息通过 ajax 传输到服务器

API

reportErrPlugin 类提供了以下的方法:

  • report(err): 手动上报错误,将错误信息添加到 waitReportList,并在达到最大数量时调用 _report() 方法上报。

  • _report(): 调用用户传入的 reportFunc 方法上报错误信息,然后清空 waitReportList

  • forceReport(): 调用此方法将进行强制上报错误,而不用等待错误信息累积达到 maxSize

  • clearReportList(): 清空 waitReportList

  • install(app): 用于 Vue 插件的安装,注册 errorHandler 事件。