Git Product home page Git Product logo

edith-script's Introduction

Edith 监控平台script

上报前端错误到Edith后台


安装

npm install @inke-design/edith-script -save

或者CDN引用

<script src="https://webcdn.inke.cn/edith.cn/edith.0.1.11.min.js"></script>

使用方式

** npm方式 **

// entry.js

import Edith from '@inke-design/edith-script'

Edith.init({
  apiKey: 'apikey', // 用于区分不同项目
  silentDev: true, // 开发环境下不上报,根据域名是否为ip或者localhost来判断
  plugins: [ // 内置插件
    'breadcrumbs', // 记录用户行为堆栈
    'redo', // 记录录屏
    'network', // 记录网络信息
  ]
})

其他参数

Edith.init({
  apiKey: 'apikey', // 用于区分不同项目,根据域名是否为ip或者localhost来判断
  silentDev: true, // 开发环境下不上报
  plugins: [ // 内置插件,选择引入
    'breadcrumbs', // 记录用户行为堆栈
    'redo', // 记录录屏
    'network', // 记录网络信息
  ],
  resourceWhiteList: ['www.baidu.com', /^((?!(a\.com|b\.com)).)*$/], // 资源加载监听的白名单(支持正则,字符串会忽略判断协议和query参数)
  ajaxWhiteList: ['//example.com/search'], // 网络请求监听的白名单(支持正则,字符串会忽略判断协议和query参数)
  setHttpBody: true, // 是否上报http请求里的body,默认为false
  silentPromise: true, // 是否不监听Promise错误
  silentResource: true, // 是否不监听资源加载错误
  silentWebsocket: true, // 是否不监听Websocket错误
  filters: err => { // 过滤错误函数,参数为带有name, title, url, message, ajax, target的错误信息字段, 返回值为真值,则不上报错误(自定义上报不拦截)
    if(err.message === 'Script error.') return true
  }
})

filters示例

  1. 过滤name为 TypeError 的错误
Edith.filters = err => {
  if(err.name === 'TypeError') return true
}
  1. 过滤 method 为 GET,且 status 为 403 的错误
Edith.filters = err => {
  if(err.ajax.method === 'GET' && err.ajax.stutus === 403) return true
}
  1. 过滤指定域名的资源加载错误
Edith.filters = err => {
  return err.message.match(/example.com/)
}
  1. 过滤url为空字符串的图片加载错误
Edith.filters = err => {
  const { target: { tagName = '' }, message } = err
  return tagName.match(/img/g) && message === ''
}

edith-script's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.