Skip to content

@heimdallr-sdk/wx

微信小程序监控基座,内置错误捕获sdk

默认使用 get 上报,允许修改 wx.request 配置项(不可修改 data、dataType)

Options

配置名称类型描述可选值默认值
dsnObject上报接口配置信息DSN-
appObject应用信息APPInfo-
enabledBoolean是否向后台发送事件true/falsetrue
pluginsArray插件集合--
debugBoolean控制台是否显示报错true/falsefalse
reqOptionRequestOption请求配置项(最高优先级)--
userStoreKeyString用户信息存储key--

DSN

名称类型描述可选值
hostString上报接口域名地址-
initString应用初始化接口地址-
reportString信息上报接口地址-

APPInfo

名称类型描述可选值
nameString应用名称-
leaderString负责人-
descString应用描述-

RequestOption

名称类型描述可选值
urlString接口地址-
enableCacheBoolean开启 cachefalse/true
enableHttp2Boolean开启 http2false/true
enableQuicBoolean开启 quicfalse/true
failFunction接口失败回调-
headerObject请求头(不可设置Referer)-
methodString请求方法OPTIONS/GET/HEAD/POST/PUT/DELETE/TRACE/CONNECT
responseTypeString响应的数据类型text/arraybuffer
successFunction接口成功回调-
timeoutNumber超时时间,单位为毫秒-

Usage

Init

js
import heimdallr from "@heimdallr-sdk/wx";
const heimdallrInstance = heimdallr({
    dsn: {
        host: 'http://localhost:8888',
        init: '/project/init',
        report: '/log/report'
    },
    app: {
        name: 'playgroundWx',
        leader: 'test',
        desc: 'test wx proj'
    }
});

Lifecycle

提供两种方式监听页面显示、隐藏方式

1. Overwrite Page

js
const { heimdallrPage } = heimdallrInstance;
heimdallrPage({
  data: {
    text: "This is page data."
  },
  onLoad: function(options) {
    // Do some initialize when page load.
  },
  onShow: function() {
    // Do something when page show.
  },
  onReady: function() {
    // Do something when page ready.
  },
  onHide: function() {
    // Do something when page hide.
  },
  onUnload: function() {
    // Do something when page close.
  }
});

2. Add the track function to the lifecycle function

js
const { track } = heimdallrInstance;
Page({
  data: {
    text: "This is page data."
  },
  onLoad: function(options) {
    // Do some initialize when page load.
  },
  onShow: function() {
    track('show', this.route);
    // Do something when page show.
  },
  onReady: function() {
    // Do something when page ready.
  },
  onHide: function() {
    track('hide', this.route);
    // Do something when page hide.
  },
  onUnload: function() {
    // Do something when page close.
  }
})