拼板印
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 lines
1.3 KiB

/**
* 微信小程序监控插件
* 1. 监听 js错误 网络资源加载错误 打印错误
* 2. 错误上报
*/
import { rewriteApp } from './rewriteApp'
import { rewriteRequest, rewriteUpload } from './rewriteRequest'
import { Error } from './Error'
export class Monitor {
static instance
constructor(options) {
this.options = options
this.behaviorQueue = []
this.instance = this
// this.init()
}
/**
* 初始化
*/
init() {
rewriteApp(this)
rewriteRequest(this)
rewriteUpload(this)
// rewritePage(this)
}
pushBehaviorItem(item) {
if (this.behaviorQueue.length >= 20) {
this.behaviorQueue.shift()
}
this.behaviorQueue.push(item)
}
handleErrorEvent(eventName, error, extraInfo) {
// 获取当前场景
const errorInfo = new Error(eventName, error)
extraInfo ? errorInfo.setExtraInfo(extraInfo) : ''
// 错误上报
wx.request({
url: this.options.url,
data: { errorMessage: JSON.stringify(errorInfo.getCurrentEnv()) },
timeout: this.options.timeout || 5000,
header: this.options.header || {},
method: this.options.method || 'POST',
monitorIgnore: this.options.monitorIgnore || true
})
console.log('reportData', errorInfo.getCurrentEnv())
}
}