Giter Club home page Giter Club logo

wx-monitor-sdk's Introduction

小程序错误收集skd

该skd可以收集到页面,组件,app.js中执行错误的内容,当发生错误的时候,可以拿到页面栈运行错误的方法执行参数执行时间当前路由系统信息

如:

Page({
  onLoad: function () {
       this.getName('wangzhenhoa')
  },
  getName(name) {
    console.log(a)
  }
})

可以拿到信息是(摘要):
{"type": "function","time": 1649834084377,"belong": "Page","method": "getName","route": "pages/index/index","arguments": "{\"0\":\"wangzhenhoa\"}"}
{ msg: 'MiniProgramError\na is not defined\nReferenceError: a is not defined' }
["pages/index/index"]

使用方法

1: app.js里面引入而且执行,注入url, key, tranceId参数拿到monitor对象
const sdk = require('./dist/wx-monitor-sdk')
const monitor = new sdk({
  url: 'http://172.16.0.166:8871',
  key: 'weapp-udream',
  traceId: String(+new Date())
})

2: 重写错误的回调方法
monitor['callback'] = function(res) {
    const parmas = {...}
    monitor.report.request('/api/monitor/report', parmas)
}

错误返回值有:
msg: js执行错误信息
breadcrumb:报错页面的明细:time时间戳,method执行方法,route当前路由,arguuments参数,type类型,belong隶属于(组件,页面,app.js)
pageStack:页面栈
systemInfo: 系统信息
accountInfo:自定义小程序发布信息

{
	"msg": "MiniProgramError\na is not defined\nReferenceError: a is not defined\n    at it.getName (http://127.0.0.1:29128/appservice/pages/index/index.js:12:17)\n    at it.page.<computed> [as getName] (http://127.0.0.1:29128/appservice/dist/wx-monitor-sdk.js:142:61)\n    at it.onLoad (http://127.0.0.1:29128/appservice/pages/index/index.js:9:10)\n    at it.page.<computed> [as onLoad] (http://127.0.0.1:29128/appservice/dist/wx-monitor-sdk.js:142:61)\n    at it.<anonymous> (http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2136311)\n    at it.l.__callPageLifeTime__ (http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2136056)\n    at xt (http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2151715)\n    at http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2155275\n    at Nt (http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2155804)\n    at Function.<anonymous> (http://127.0.0.1:29128/appservice/__dev__/WASubContext.js?t=wechat&s=1649818059414&v=2.14.0:2:2165481)",
	"breadcrumb": [{
		"type": "function",
		"time": 1649834084377,
		"belong": "Page",
		"method": "getName",
		"route": "pages/index/index",
		"arguments": "{\"0\":\"wangzhenhoa\"}"
	}],
	"pageStack": ["pages/index/index"],
	"systemInfo": {
		"errMsg": "getSystemInfo:ok",
		"model": "iPhone 6/7/8",
		"pixelRatio": 2,
		"windowWidth": 375,
		"windowHeight": 603,
		"system": "iOS 10.0.1",
		"language": "zh_CN",
		"version": "8.0.5",
		"deviceOrientation": "portrait",
		"screenWidth": 375,
		"screenHeight": 667,
		"SDKVersion": "2.14.0",
		"brand": "devtools",
		"fontSizeSetting": 16,
		"benchmarkLevel": 1,
		"batteryLevel": 100,
		"statusBarHeight": 20,
		"bluetoothEnabled": true,
		"locationEnabled": true,
		"wifiEnabled": true,
		"cameraAuthorized": true,
		"locationAuthorized": true,
		"microphoneAuthorized": true,
		"notificationAuthorized": true,
		"safeArea": {
			"top": 20,
			"left": 0,
			"right": 375,
			"bottom": 667,
			"width": 375,
			"height": 647
		},
		"platform": "devtools",
		"devicePixelRatio": 2
	},
	"accountInfo": {
		"miniProgram": {
			"appId": "wx00e80e8bf05d19c0",
			"envVersion": "develop",
			"version": ""
		}
	}
}


3:回调函数里面上报
monitor.report.request('/api/monitor/report', parmas)

运行


开发调试
npm run dev

构建发行
npm run build

wx-monitor-sdk'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.