@zyf2e/mitojs
Version:
A SDK for monitoring browser errors
2 lines (1 loc) • 34.4 kB
JavaScript
var MITO=function(){"use strict";var e,t,n,r,o=function(){return(o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function a(e,t,n,r){return new(n||(n=Promise))((function(o,a){function i(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,s)}c((r=r.apply(e,t||[])).next())}))}function i(e,t){var n,r,o,a,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;i;)try{if(n=1,r&&(o=2&a[0]?r.return:a[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,a[1])).done)return o;switch(r=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return i.label++,{value:a[1],done:!1};case 5:i.label++,r=a[1],a=[0];continue;case 7:a=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){i=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){i.label=a[1];break}if(6===a[0]&&i.label<o[1]){i.label=o[1],o=a;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(a);break}o[2]&&i.ops.pop(),i.trys.pop();continue}a=t.call(e,i)}catch(e){a=[6,e],r=0}finally{n=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}function s(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)r[o]=a[i];return r}!function(e){e.UNKNOWN="UNKNOWN",e.UNKNOWN_FUNCTION="UNKNOWN_FUNCTION",e.JAVASCRIPT_ERROR="JAVASCRIPT_ERROR",e.LOG_ERROR="LOG_ERROR",e.FETCH_ERROR="HTTP_ERROR",e.VUE_ERROR="VUE_ERROR",e.REACT_ERROR="REACT_ERROR",e.RESOURCE_ERROR="RESOURCE_ERROR",e.PROMISE_ERROR="PROMISE_ERROR",e.ROUTE_ERROR="ROUTE_ERROR"}(e||(e={})),function(e){e.AppOnLaunch="AppOnLaunch",e.AppOnShow="AppOnShow",e.AppOnHide="AppOnHide",e.AppOnError="AppOnError",e.AppOnPageNotFound="AppOnPageNotFound",e.AppOnUnhandledRejection="AppOnUnhandledRejection"}(t||(t={})),function(e){e.PageOnShow="PageOnShow",e.PageOnHide="PageOnHide",e.PageOnShareAppMessage="PageOnShareAppMessage",e.PageOnShareTimeline="PageOnShareTimeline",e.PageOnTabItemTap="PageOnTabItemTap"}(n||(n={})),function(e){e.SwitchTab="switchTab",e.ReLaunch="reLaunch",e.RedirectTo="redirectTo",e.NavigateTo="navigateTo",e.NavigateBack="navigateBack",e.RouteFail="routeFail"}(r||(r={}));var c,u,l,p,f;o(o(o({},t),n),e);!function(e){e.ROUTE="Route",e.CLICK="UI.Click",e.CONSOLE="Console",e.XHR="Xhr",e.FETCH="Fetch",e.UNHANDLEDREJECTION="Unhandledrejection",e.VUE="Vue",e.REACT="React",e.RESOURCE="Resource",e.CODE_ERROR="Code Error",e.CUSTOMER="Customer",e.APP_ON_SHOW="App On Show",e.APP_ON_LAUNCH="App On Launch",e.APP_ON_HIDE="App On Hide",e.PAGE_ON_SHOW="Page On Show",e.PAGE_ON_HIDE="Page On Hide",e.PAGE_ON_SHARE_APP_MESSAGE="Page On Share App Message",e.PAGE_ON_SHARE_TIMELINE="Page On Share Timeline",e.PAGE_ON_TAB_ITEM_TAP="Page On Tab Item Tap",e.TAP="UI.Tap",e.TOUCHMOVE="UI.Touchmove"}(c||(c={})),function(e){e.HTTP="http",e.USER="user",e.DEBUG="debug",e.EXCEPTION="exception",e.LIFECYCLE="lifecycle"}(u||(u={})),function(e){e.XHR="xhr",e.FETCH="fetch",e.CONSOLE="console",e.DOM="dom",e.HISTORY="history",e.ERROR="error",e.HASHCHANGE="hashchange",e.UNHANDLEDREJECTION="unhandledrejection",e.MITO="mito",e.VUE="Vue",e.MINI_ROUTE="miniRoute"}(l||(l={})),function(e){e.XHR="xhr",e.FETCH="fetch"}(p||(p={})),function(e){e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.UNAUTHORIZED=401]="UNAUTHORIZED",e[e.INTERNAL_EXCEPTION=500]="INTERNAL_EXCEPTION"}(f||(f={}));var d=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/,h={isLogAddBreadcrumb:!0,crossOriginThreshold:1e3},g=Object.prototype.toString;function E(e){return function(t){return g.call(t)==="[object "+e+"]"}}var O={isNumber:E("Number"),isString:E("String"),isBoolean:E("Boolean"),isNull:E("Null"),isUndefined:E("Undefined"),isSymbol:E("Symbol"),isFunction:E("Function"),isObject:E("Object"),isArray:E("Array"),isProcess:E("process"),isWindow:E("Window")};function R(e){switch(g.call(e)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return function(e,t){try{return e instanceof t}catch(e){return!1}}(e,Error)}}function y(e){return O.isObject(e)&&0===Object.keys(e).length}var v=O.isProcess("undefined"!=typeof process?process:0),m=O.isObject("undefined"!=typeof wx?wx:0)&&O.isFunction("undefined"!=typeof App?App:0),T=O.isWindow("undefined"!=typeof window?window:0);var N=T?window:m?wx:v?process:void 0,b=(N.__MITO__=N.__MITO__||{},N.__MITO__);b.replaceFlag=b.replaceFlag||{};var A=b.replaceFlag;function _(e,t){A[e]||(A[e]=t)}function C(e){return!!A[e]}var I="MITO Logger",P=function(){function e(){var e=this;if(this.enabled=!1,this._console={},N.console=console||N.console,console||N.console){["log","debug","info","warn","error","assert"].forEach((function(t){t in N.console&&(e._console[t]=N.console[t])}))}}return e.prototype.disable=function(){this.enabled=!1},e.prototype.bindOptions=function(e){this.enabled=!!e},e.prototype.enable=function(){this.enabled=!0},e.prototype.getEnableStatus=function(){return this.enabled},e.prototype.log=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.enabled&&(e=this._console).log.apply(e,s([I+"[Log]:"],t))},e.prototype.warn=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.enabled&&(e=this._console).warn.apply(e,s([I+"[Warn]:"],t))},e.prototype.error=function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.enabled&&(e=this._console).error.apply(e,s([I+"[Error]:"],t))},e}(),S=b.logger||(b.logger=new P);function U(){return"undefined"==typeof document||null==document.location?"":document.location.href}function H(e,t,n,r){void 0===r&&(r=!1),e.addEventListener(t,n,r)}function x(e,t,n,r){if(void 0===r&&(r=!1),t in e||r){var o=n(e[t]);"function"==typeof o&&(e[t]=o)}}var k=function(e,t){var n=!0;return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n&&(e.apply(this,r),n=!1,setTimeout((function(){n=!0}),t))}};function w(){return Date.now()}function D(e,t,n){return!!function(e,t){return typeof e===t}(e,n)||(void 0!==e&&S.error(t+"期望传入"+n+"类型,目前是"+typeof e+"类型"),!1)}function L(e,t,n){return!!function(e,t){return g.call(e)===t}(e,n)||(void 0!==e&&S.error(t+"期望传入"+n+"类型,目前是"+g.call(e)+"类型"),!1)}function F(e){h.isLogAddBreadcrumb=!1,e(),h.isLogAddBreadcrumb=!0}function M(e){return O.isString(e)?e:O.isUndefined(e)?"undefined":JSON.stringify(e)}function j(e){return Number(e.split(".")[0])}function G(e,t){var n=[];return Object.keys(t).forEach((function(e){n.push(e+"="+t[e])})),e=-1!==e.indexOf("?")?e+"&"+n.join("&"):e+"?"+n.join("&")}function X(e){if(!e)return{};var t=e.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!t)return{};var n=t[6]||"",r=t[8]||"";return{host:t[4],path:t[5],protocol:t[2],relative:t[5]+n+r}}function B(t,n){var r={time:w(),url:U(),name:t.name,level:n,message:t.message};if(void 0===t.stack||!t.stack)return r;for(var a,i,s,c=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,u=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,l=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,p=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,f=/\((\S*)(?::(\d+))(?::(\d+))\)/,d=t.stack.split("\n"),h=[],g=0,E=d.length;g<E;++g){if(i=c.exec(d[g])){var O=i[2]&&0===i[2].indexOf("native");i[2]&&0===i[2].indexOf("eval")&&(a=f.exec(i[2]))&&(i[2]=a[1],i[3]=a[2],i[4]=a[3]),s={url:O?null:i[2],func:i[1]||e.UNKNOWN_FUNCTION,args:O?[i[2]]:[],line:i[3]?+i[3]:null,column:i[4]?+i[4]:null}}else if(i=l.exec(d[g]))s={url:i[2],func:i[1]||e.UNKNOWN_FUNCTION,args:[],line:+i[3],column:i[4]?+i[4]:null};else{if(!(i=u.exec(d[g])))continue;i[3]&&i[3].indexOf(" > eval")>-1&&(a=p.exec(i[3]))?(i[3]=a[1],i[4]=a[2],i[5]=null):0!==g||i[5]||void 0===t.columnNumber||(h[0].column=t.columnNumber+1),s={url:i[3],func:i[1]||e.UNKNOWN_FUNCTION,args:i[2]?i[2].split(","):[],line:i[4]?+i[4]:null,column:i[5]?+i[5]:null}}!s.func&&s.line&&(s.func=e.UNKNOWN_FUNCTION),h.push(s)}return h.length?o(o({},r),{stack:h}):null}var W,q=function(){function e(){this.stack=[],this.isFlushing=!1,"Promise"in N&&(this.micro=Promise.resolve())}return e.prototype.addFn=function(e){var t=this;"function"==typeof e&&("Promise"in N?(this.stack.push(e),this.isFlushing||(this.isFlushing=!0,this.micro.then((function(){return t.flushStack()})))):e())},e.prototype.clear=function(){this.stack=[]},e.prototype.getStack=function(){return this.stack},e.prototype.flushStack=function(){var e=this.stack.slice(0);this.stack.length=0,this.isFlushing=!1;for(var t=0;t<e.length;t++)e[t]()},e}(),V=function(){function e(){this.maxBreadcrumbs=10,this.beforePushBreadcrumb=null,this.stack=[]}return e.prototype.push=function(e){var t=this;if("function"!=typeof this.beforePushBreadcrumb)this.immediatePush(e);else{var n=null,r=this.beforePushBreadcrumb;if(F((function(){n=r(t,e)})),!n)return;this.immediatePush(n)}},e.prototype.immediatePush=function(e){e.time=w(),this.stack.length>=this.maxBreadcrumbs&&this.shift(),this.stack.push(e),S.log(this.stack)},e.prototype.shift=function(){return void 0!==this.stack.shift()},e.prototype.clear=function(){this.stack=[]},e.prototype.getStack=function(){return this.stack},e.prototype.getCategory=function(e){switch(e){case c.XHR:case c.FETCH:return u.HTTP;case c.CLICK:case c.ROUTE:case c.TAP:case c.TOUCHMOVE:return u.USER;case c.CUSTOMER:case c.CONSOLE:return u.DEBUG;case c.APP_ON_LAUNCH:case c.APP_ON_SHOW:case c.APP_ON_HIDE:case c.PAGE_ON_SHOW:case c.PAGE_ON_HIDE:case c.PAGE_ON_SHARE_APP_MESSAGE:case c.PAGE_ON_SHARE_TIMELINE:case c.PAGE_ON_TAB_ITEM_TAP:return u.LIFECYCLE;case c.UNHANDLEDREJECTION:case c.CODE_ERROR:case c.RESOURCE:case c.VUE:case c.REACT:default:return u.EXCEPTION}},e.prototype.bindOptions=function(e){void 0===e&&(e={});var t=e.maxBreadcrumbs,n=e.beforePushBreadcrumb;D(t,"maxBreadcrumbs","number")&&(this.maxBreadcrumbs=t),D(n,"beforePushBreadcrumb","function")&&(this.beforePushBreadcrumb=n)},e}(),$=b.breadcrumb||(b.breadcrumb=new V);!function(e){e.Touchmove="touchmove",e.Tap="tap"}(W||(W={}));var J={};function K(t,n){var r;switch(t.type){case e.FETCH_ERROR:r=t.type+t.request.method+t.response.status+Z(t.request.url)+n;break;case e.JAVASCRIPT_ERROR:case e.VUE_ERROR:case e.REACT_ERROR:r=t.type+t.name+t.message+n;break;case e.LOG_ERROR:r=t.customTag+t.type+t.name+n;break;case e.PROMISE_ERROR:r=function(e,t){var n=Z(e.url);if(e.name===l.UNHANDLEDREJECTION)return e.type+Y(e.message)+t;return e.type+e.name+Y(e.message)+n}(t,n);break;default:r=t.type+t.message+n}return r=function(e){var t=0;if(0==e.length)return t;for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return t}(r),J[r]>1?null:("number"==typeof J[r]?J[r]++:J[r]=1,r)}function Y(e){var t=function(e){return Object.keys(e).sort().reduce((function(n,r){return O.isObject(e[r])?n[r]=t(e[r]):n[r]=e[r],n}),{})};try{if(/\{.*\}/.test(e)){var n=JSON.parse(e);return n=t(n),JSON.stringify(n)}}catch(t){return e}}function Z(e){return e.replace(/[\?#].*$/,"").replace(/\/\d+([\/]*$)/,"{param}$1")}var Q;!function(e){e.Get="GET",e.Post="POST",e.Put="PUT",e.Delete="DELETE"}(Q||(Q={}));var z,ee,te=function(){function e(e){this.url=e,this.beforeDataReport=null,this.backTrackerId=null,this.configReportXhr=null,this.apikey="",this.queue=new q}return e.prototype.getRecord=function(){var e=b.record;return e&&O.isArray(e)&&e.length>2?e:[]},e.prototype.beforePost=function(e){return a(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return(t=K(e,this.apikey))?(e.errorId=t,n=this.getTransportData(e),"function"!=typeof this.beforeDataReport?[3,2]:[4,this.beforeDataReport(n)]):[2,!1];case 1:if(!(n=r.sent()))return[2,!1];r.label=2;case 2:return[2,JSON.stringify(n)]}}))}))},e.prototype.xhrPost=function(e){return a(this,void 0,void 0,(function(){var t,n,r=this;return i(this,(function(o){switch(o.label){case 0:return[4,this.beforePost(e)];case 1:return(t=o.sent())?(n=function(){var e=new XMLHttpRequest;e.open(Q.Post,r.url),e.setRequestHeader("Content-Type","application/json;charset=UTF-8"),e.withCredentials=!0,"function"==typeof r.configReportXhr&&r.configReportXhr(e),e.send(t)},this.queue.addFn(n),[2]):[2]}}))}))},e.prototype.wxPost=function(e){return a(this,void 0,void 0,(function(){var t,n,r=this;return i(this,(function(o){switch(o.label){case 0:return[4,this.beforePost(e)];case 1:return(t=o.sent())?(n=function(){wx.request({method:"POST",header:{"Content-Type":"application/json;charset=UTF-8"},url:r.url,data:t})},this.queue.addFn(n),[2]):[2]}}))}))},e.prototype.getAuthInfo=function(){var e=this.getTrackerId();return{trackerId:String(e),sdkVersion:"1.2.7",sdkName:"@zyf2e/mitojs",apikey:this.apikey}},e.prototype.getApikey=function(){return this.apikey},e.prototype.getTrackerId=function(){if("function"==typeof this.backTrackerId){var e=this.backTrackerId();if("string"==typeof e||"number"==typeof e)return e;S.error("trackerId:"+e+" 期望 string 或 number 类型,但是传入 "+typeof e)}return""},e.prototype.getTransportData=function(e){return{authInfo:this.getAuthInfo(),breadcrumb:$.getStack(),data:e,record:this.getRecord()}},e.prototype.isSdkTransportUrl=function(e){return-1!==e.indexOf(this.url)},e.prototype.bindOptions=function(e){void 0===e&&(e={});var t=e.dsn,n=e.beforeDataReport,r=e.apikey,o=e.configReportXhr,a=e.backTrackerId;D(r,"apikey","string")&&(this.apikey=r),D(t,"dsn","string")&&(this.url=t),D(n,"beforeDataReport","function")&&(this.beforeDataReport=n),D(o,"configReportXhr","function")&&(this.configReportXhr=o),D(a,"backTrackerId","function")&&(this.backTrackerId=a)},e.prototype.send=function(e){return T?this.xhrPost(e):m?this.wxPost(e):void 0},e}(),ne=b.transportData||(b.transportData=new te("//localhost:3000/api/error/upload"));function re(){if(!O.isFunction(getCurrentPages))return"";var e=getCurrentPages();if(!e.length)return"App";var t=e.pop();return G(t.route,t.options)}function oe(e){var t,n;return"<element "+((null===(t=e.currentTarget)||void 0===t?void 0:t.id)?' id="'+(null===(n=e.currentTarget)||void 0===n?void 0:n.id)+'"':"")+" "+Object.keys(e.currentTarget.dataset).map((function(t){return"data-"+t+"="+e.currentTarget.dataset[t]})).join(" ")+"/>"}function ae(t){var n=t.message,r=void 0===n?"emptyMsg":n,a=t.tag,i=void 0===a?"":a,s=t.level,u=void 0===s?z.Critical:s,l=t.ex,p=void 0===l?"":l,f={};R(p)&&(f=B(p,u));var d=o({type:e.LOG_ERROR,level:u,message:M(r),name:"MITO.log",customTag:M(i),time:w(),url:m?re():U()},f);$.push({type:c.CUSTOMER,category:$.getCategory(c.CUSTOMER),data:r,level:z.fromString(u.toString())}),ne.send(d)}function ie(t){var n="",r=t.elapsedTime,o=t.time,a=t.method,i=t.traceId,s=t.type,c=t.status,u=s+"--"+a;return n=(n=0===c?r<=h.crossOriginThreshold?"http请求失败,失败原因:跨域限制或域名不存在":"http请求失败,失败原因:超时":function(e){if(e<400)return ee.Ok;if(e>=400&&e<500)switch(e){case 401:return ee.Unauthenticated;case 403:return ee.PermissionDenied;case 404:return ee.NotFound;case 409:return ee.AlreadyExists;case 413:return ee.FailedPrecondition;case 429:return ee.ResourceExhausted;default:return ee.InvalidArgument}if(e>=500&&e<600)switch(e){case 501:return ee.Unimplemented;case 503:return ee.Unavailable;case 504:return ee.DeadlineExceeded;default:return ee.InternalError}return ee.UnknownError}(c))===ee.Ok?n:n+" "+Z(t.url),{type:e.FETCH_ERROR,url:U(),time:o,elapsedTime:r,level:z.Low,message:n,name:u,request:{httpType:s,traceId:i,method:a,url:t.url,data:t.reqData||""},response:{status:c,data:t.responseText}}}!function(e){e.Else="else",e.Error="error",e.Warning="warning",e.Info="info",e.Debug="debug",e.Low="low",e.Normal="normal",e.High="high",e.Critical="critical"}(z||(z={})),function(e){e.fromString=function(t){switch(t){case"debug":return e.Debug;case"info":case"log":case"assert":return e.Info;case"warn":case"warning":return e.Warning;case e.Low:case e.Normal:case e.High:case e.Critical:case"error":return e.Error;default:return e.Else}}}(z||(z={})),function(e){e.Ok="ok",e.DeadlineExceeded="deadline_exceeded",e.Unauthenticated="unauthenticated",e.PermissionDenied="permission_denied",e.NotFound="not_found",e.ResourceExhausted="resource_exhausted",e.InvalidArgument="invalid_argument",e.Unimplemented="unimplemented",e.Unavailable="unavailable",e.InternalError="internal_error",e.UnknownError="unknown_error",e.Cancelled="cancelled",e.AlreadyExists="already_exists",e.FailedPrecondition="failed_precondition",e.Aborted="aborted",e.OutOfRange="out_of_range",e.DataLoss="data_loss"}(ee||(ee={}));var se={img:"图片",script:"js脚本"};var ce=function(){function e(){this.traceIdFieldName="Trace-Id",this.enableTraceId=!1}return e.prototype.bindOptions=function(e){void 0===e&&(e={});var t=e.beforeAppAjaxSend,n=e.enableTraceId,r=e.filterXhrUrlRegExp,o=e.traceIdFieldName,a=e.includeHttpUrlTraceIdRegExp;D(t,"beforeAppAjaxSend","function")&&(this.beforeAppAjaxSend=t),D(n,"enableTraceId","boolean")&&(this.enableTraceId=n),D(o,"traceIdFieldName","string")&&(this.traceIdFieldName=o),L(r,"filterXhrUrlRegExp","[object RegExp]")&&(this.filterXhrUrlRegExp=r),L(a,"includeHttpUrlTraceIdRegExp","[object RegExp]")&&(this.includeHttpUrlTraceIdRegExp=a)},e}(),ue=b.options||(b.options=new ce);function le(e,t){var n,r=ue.includeHttpUrlTraceIdRegExp;if(ue.enableTraceId&&r&&r.test(e)){var o=(n=(new Date).getTime(),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"==e?t:3&t|8).toString(16)})));t(ue.traceIdFieldName,o)}}function pe(t,n,r,a,i,s){var u=null==s?void 0:s.version,l={type:e.VUE_ERROR,message:t.message+"("+r+")",level:a,url:U(),name:t.name,stack:t.stack||[],time:w()};if(O.isString(u))switch(console.log("getBigVersion",j(u)),j(u)){case 2:l=o(o({},l),function(e){var t="";if(e.$root===e)t="root";else{var n=e._isVue?e.$options&&e.$options.name||e.$options&&e.$options._componentTag:e.name;t=(n?"component <"+n+">":"anonymous component")+(e._isVue&&e.$options&&e.$options.__file?" at "+(e.$options&&e.$options.__file):"")}return{componentName:t,propsData:e.$options&&e.$options.propsData}}(n));break;case 3:l=o(o({},l),function(e){var t="";if(e.$root===e)t="root";else{console.log(e.$options);var n=e.$options&&e.$options.name;t=n?"component <"+n+">":"anonymous component"}return{componentName:t,propsData:e.$props}}(n));break;default:return}$.push({type:c.VUE,category:$.getCategory(c.VUE),data:l,level:i}),ne.send(l)}var fe="undefined"!=typeof console,de={install:function(e){!C(l.VUE)&&e&&e.config&&(_(l.VUE,!0),e.config.errorHandler=function(t,n,r){pe.apply(null,[t,n,r,z.Normal,z.Error,e]),fe&&!e.config.silent&&F((function(){console.error("Error in "+r+': "'+t.toString()+'"',n),console.error(t)}))})}},he={handleHttp:function(e,t){var n=0===e.status||e.status===f.BAD_REQUEST||e.status>f.UNAUTHORIZED,r=ie(e);$.push({type:t,category:$.getCategory(t),data:o({},r),level:z.Info}),n&&($.push({type:t,category:$.getCategory(c.CODE_ERROR),data:o({},r),level:z.Error}),ne.send(r))},handleError:function(t){if(t.target.localName){var n=function(t){return{type:e.RESOURCE_ERROR,url:U(),message:"资源地址: "+(t.src.slice(0,100)||t.href.slice(0,100)),level:z.Low,time:w(),name:(se[t.localName]||t.localName)+"加载失败"}}(t.target);return $.push({type:c.RESOURCE,category:$.getCategory(c.RESOURCE),data:n,level:z.Error}),ne.send(n)}var r,a=t.message,i=t.filename,s=t.lineno,u=t.colno,l=t.error;l&&R(l)&&(r=B(l,z.Normal)),r||(r=he.handleNotErrorInstance(a,i,s,u)),r.type=e.JAVASCRIPT_ERROR,$.push({type:c.CODE_ERROR,category:$.getCategory(c.CODE_ERROR),data:o({},r),level:z.Error}),ne.send(r)},handleNotErrorInstance:function(t,n,r,o){var a=e.UNKNOWN,i=n||U(),s=t,c=t.match(d);c[1]&&(a=c[1],s=c[2]);var u={url:i,func:e.UNKNOWN_FUNCTION,args:e.UNKNOWN,line:r,col:o};return{url:i,name:a,message:s,level:z.Normal,time:w(),stack:[u]}},handleHistory:function(e){var t=e.from,n=e.to,r=X(t).relative,o=X(n).relative;$.push({type:c.ROUTE,category:$.getCategory(c.ROUTE),data:{from:r||"/",to:o||"/"},level:z.Info})},handleHashchange:function(e){var t=e.oldURL,n=e.newURL,r=X(t).relative,o=X(n).relative;$.push({type:c.ROUTE,category:$.getCategory(c.ROUTE),data:{from:r,to:o},level:z.Info})},handleUnhandleRejection:function(t){var n={type:e.PROMISE_ERROR,message:M(t.reason),url:U(),name:t.type,time:w(),level:z.Low};R(t.reason)&&(n=o(o({},n),B(t.reason,z.Low))),$.push({type:c.UNHANDLEDREJECTION,category:$.getCategory(c.UNHANDLEDREJECTION),data:o({},n),level:z.Error}),ne.send(n)},handleConsole:function(e){h.isLogAddBreadcrumb&&$.push({type:c.CONSOLE,category:$.getCategory(c.CONSOLE),data:e,level:z.fromString(e.level)})}},ge={};function Ee(e){return!(!e||C(e.type))&&(_(e.type,!0),ge[e.type]=ge[e.type]||[],ge[e.type].push(e.callback),!0)}function Oe(e,t){e&&ge[e]&&ge[e].forEach((function(n){!function(e,t){try{e()}catch(e){console.log("err",e),t&&t(e)}}((function(){n(t)}),(function(t){var r;S.error("重写事件triggerHandlers的回调函数发生错误\nType:"+e+"\nName: "+(((r=n)&&"function"==typeof r&&r.name||"<anonymous>")+"\nError: ")+t)}))}))}var Re,ye=k(Oe,600);function ve(e){return ue.filterXhrUrlRegExp&&ue.filterXhrUrlRegExp.test(e)}function me(e){switch(e){case l.XHR:!function(){if(!("XMLHttpRequest"in N))return;var e=XMLHttpRequest.prototype;x(e,"open",(function(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];this.mito_xhr={method:O.isString(t[0])?t[0].toUpperCase():t[0],url:t[1],sTime:w(),type:p.XHR},e.apply(this,t)}})),x(e,"send",(function(e){return function(){for(var t=this,n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=this.mito_xhr,a=o.method,i=o.url;le(i,(function(e,n){t.mito_xhr.traceId=n,t.setRequestHeader(e,n)})),ue.beforeAppAjaxSend&&ue.beforeAppAjaxSend({method:a,url:i},this),H(this,"loadend",(function(){if(!(a===Q.Post&&ne.isSdkTransportUrl(i)||ve(i))){var e=this.responseType,t=this.response,r=this.status;this.mito_xhr.reqData=n[0];var o=w();this.mito_xhr.time=o,this.mito_xhr.status=r,-1!==["","json","text"].indexOf(e)&&(this.mito_xhr.responseText="object"==typeof t?JSON.stringify(t):t),this.mito_xhr.elapsedTime=o-this.mito_xhr.sTime,Oe(l.XHR,this.mito_xhr)}})),e.apply(this,n)}}))}();break;case l.FETCH:!function(){if(!("fetch"in N))return;x(N,l.FETCH,(function(e){return function(t,n){void 0===n&&(n={});var r=w(),a=n&&n.method||"GET",i={type:p.FETCH,method:a,reqData:n&&n.body,url:t},s=new Headers(n.headers||{});return Object.assign(s,{setRequestHeader:s.set}),le(t,(function(e,t){i.traceId=t,s.set(e,t)})),ue.beforeAppAjaxSend&&ue.beforeAppAjaxSend({method:a,url:t},s),n=o(o({},n),{headers:s}),e.apply(N,[t,n]).then((function(e){var n=e.clone(),s=w();return i=o(o({},i),{elapsedTime:s-r,status:n.status,time:s}),n.text().then((function(e){a===Q.Post&&ne.isSdkTransportUrl(t)||ve(t)||(i.responseText=n.status>f.UNAUTHORIZED&&e,Oe(l.FETCH,i))})),e}),(function(e){var n=w();if(!(a===Q.Post&&ne.isSdkTransportUrl(t)||ve(t)))throw i=o(o({},i),{elapsedTime:n-r,status:0,time:n}),Oe(l.FETCH,i),e}))}}))}();break;case l.ERROR:H(N,"error",(function(e){Oe(l.ERROR,e)}),!0);break;case l.CONSOLE:!function(){if(!("console"in N))return;["log","debug","info","warn","error","assert"].forEach((function(e){e in N.console&&x(N.console,e,(function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];t&&(Oe(l.CONSOLE,{args:n,level:e}),t.apply(N.console,n))}}))}))}();break;case l.HISTORY:!function(){if(e=N.chrome,t=e&&e.app&&e.app.runtime,n="history"in N&&!!N.history.pushState&&!!N.history.replaceState,t||!n)return;var e,t,n;var r=N.onpopstate;function o(e){return function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=t.length>2?t[2]:void 0;if(r){var o=Re,a=String(r);Re=a,Oe(l.HISTORY,{from:o,to:a})}return e.apply(this,t)}}N.onpopstate=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=U(),o=Re;Oe(l.HISTORY,{from:o,to:n}),r&&r.apply(this,e)},x(N.history,"pushState",o),x(N.history,"replaceState",o)}();break;case l.UNHANDLEDREJECTION:H(N,l.UNHANDLEDREJECTION,(function(e){Oe(l.UNHANDLEDREJECTION,e)}));break;case l.DOM:!function(){if(!("document"in N))return;H(N.document,"click",(function(){ye(l.DOM,{category:"click",data:this})}),!0)}();break;case l.HASHCHANGE:t="onpopstate",N.hasOwnProperty(t)||H(N,l.HASHCHANGE,(function(e){Oe(l.HASHCHANGE,e)}))}var t}function Te(e){Ee(e)&&me(e.type)}function Ne(e){var r;void 0===e&&(e={}),void 0===(r=e)&&(r={}),_(l.XHR,!!r.silentXhr),_(l.FETCH,!!r.silentFetch),_(l.CONSOLE,!!r.silentConsole),_(l.DOM,!!r.silentDom),_(l.HISTORY,!!r.silentHistory),_(l.ERROR,!!r.silentError),_(l.HASHCHANGE,!!r.silentHashchange),_(l.UNHANDLEDREJECTION,!!r.silentUnhandledrejection),_(l.VUE,!!r.silentVue),_(t.AppOnError,!!r.silentWxOnError),_(t.AppOnUnhandledRejection,!!r.silentUnhandledrejection),_(t.AppOnPageNotFound,!!r.silentWxOnPageNotFound),_(n.PageOnShareAppMessage,!!r.silentWxOnShareAppMessage),_(l.MINI_ROUTE,!!r.silentMiniRoute),$.bindOptions(e),S.bindOptions(e.debug),ne.bindOptions(e),ue.bindOptions(e)}Re=U();var be={onLaunch:function(e){var t={path:e.path,query:e.query};$.push({category:$.getCategory(c.APP_ON_LAUNCH),type:c.APP_ON_LAUNCH,data:t,level:z.Info})},onShow:function(e){var t={path:e.path,query:e.query};$.push({category:$.getCategory(c.APP_ON_SHOW),type:c.APP_ON_SHOW,data:t,level:z.Info})},onHide:function(){$.push({category:$.getCategory(c.APP_ON_HIDE),type:c.APP_ON_HIDE,data:null,level:z.Info})},onError:function(t){var n=function(t){var n=t.split("\n");if(n.length<2)return null;-1!==n[0].indexOf("MiniProgramError")&&n.splice(0,1);var r=n.splice(0,1)[0],o=n.splice(0,1)[0].split(":")[0],a=[];return n.forEach((function(t){var n=/at\s+([\S]+)\s+\(/.exec(t),r=/\(([^)]+)\)/.exec(t);r||(r=/\s+at\s+(\S+)/.exec(t));var o=Array.isArray(n)&&n.length>0?n[1].trim():"",i=(Array.isArray(r)&&r.length>0?r[1]:"").split(":");a.push({args:[],func:o||e.UNKNOWN_FUNCTION,column:Number(i.pop()),line:Number(i.pop()),url:i.join(":")})})),{message:r,name:o,stacks:a}}(t),r=o(o({},n),{time:w(),level:z.Normal,url:re(),type:e.JAVASCRIPT_ERROR});$.push({category:$.getCategory(c.CODE_ERROR),type:c.CODE_ERROR,level:z.Error,data:o({},r)}),ne.send(r)},onUnhandledRejection:function(t){var n={type:e.PROMISE_ERROR,message:M(t.reason),url:re(),name:"unhandledrejection",time:w(),level:z.Low};R(t.reason)&&(n=o(o(o({},n),B(t.reason,z.Low)),{url:re()})),$.push({type:c.UNHANDLEDREJECTION,category:$.getCategory(c.UNHANDLEDREJECTION),data:o({},n),level:z.Error}),ne.send(n)},onPageNotFound:function(e){$.push({category:$.getCategory(c.ROUTE),type:c.ROUTE,data:e,level:z.Error})}},Ae={onShow:function(){var e=getCurrentPages().pop(),t={path:e.route,query:e.options};$.push({category:$.getCategory(c.PAGE_ON_SHOW),type:c.PAGE_ON_SHOW,data:t,level:z.Info})},onHide:function(){var e=getCurrentPages().pop(),t={path:e.route,query:e.options};$.push({category:$.getCategory(c.PAGE_ON_HIDE),type:c.PAGE_ON_HIDE,data:t,level:z.Info})},onShareAppMessage:function(e){var t=getCurrentPages().pop(),n={path:t.route,query:t.options,options:e};$.push({category:$.getCategory(c.PAGE_ON_SHARE_APP_MESSAGE),type:c.PAGE_ON_SHARE_APP_MESSAGE,data:n,level:z.Info})},onShareTimeline:function(){var e=getCurrentPages().pop(),t={path:e.route,query:e.options};$.push({category:$.getCategory(c.PAGE_ON_SHARE_TIMELINE),type:c.PAGE_ON_SHARE_TIMELINE,data:t,level:z.Info})},onTabItemTap:function(e){var t=getCurrentPages().pop(),n={path:t.route,query:t.options,options:e};$.push({category:$.getCategory(c.PAGE_ON_TAB_ITEM_TAP),type:c.PAGE_ON_TAB_ITEM_TAP,data:n,level:z.Info})},onAction:function(e){var t=c.TOUCHMOVE;e.type===W.Tap&&(t=c.TAP),$.push({category:$.getCategory(t),type:t,data:oe(e),level:z.Info})}},_e=function(e){he.handleConsole(e)},Ce=function(e){var t=ie(e);t.url=re(),void 0===e.status&&(t.message=e.errMsg);var n,r=c.XHR;$.push({type:r,category:$.getCategory(r),data:t,level:z.Info}),(0===(n=e.status)||n===f.BAD_REQUEST||n>f.UNAUTHORIZED)&&($.push({type:r,category:$.getCategory(c.CODE_ERROR),data:o({},t),level:z.Error}),ne.send(t))},Ie=function(t){if(t.isFail){$.push({type:c.ROUTE,category:$.getCategory(c.CODE_ERROR),data:t,level:z.Error});var n={type:e.ROUTE_ERROR,message:t.message,url:t.to,name:"MINI_"+e.ROUTE_ERROR,level:z.Error};return ne.send(n)}$.push({type:c.ROUTE,category:$.getCategory(c.ROUTE),data:t,level:z.Info})};function Pe(e){return ue.filterXhrUrlRegExp&&ue.filterXhrUrlRegExp.test(e)}function Se(e){switch(e){case l.CONSOLE:!function(){if(console&&O.isObject(console)){["log","debug","info","warn","error","assert"].forEach((function(e){e in console&&x(console,e,(function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];t&&(Oe(l.CONSOLE,{args:n,level:e}),t.apply(console,n))}}))}))}}();break;case l.XHR:["request","downloadFile","uploadFile"].forEach((function(e){var t=wx[e];Object.defineProperty(wx,e,{writable:!0,enumerable:!0,configurable:!0,value:function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var a,i=n[0];a=i.method?i.method:"downloadFile"===e?Q.Get:Q.Post;var s,c=i.url,u=i.header;if(a===Q.Post&&ne.isSdkTransportUrl(c)||Pe(c))return t.call(this,i);s="request"===e?i.data:"downloadFile"===e?{filePath:i.filePath}:{filePath:i.filePath,name:i.name};var f={type:p.XHR,method:a,url:c,reqData:s,sTime:w()};function d(e,t){u[e]=t}le(c,(function(e,t){f.traceId=t,u[e]=t})),ue.beforeAppAjaxSend&&ue.beforeAppAjaxSend({method:a,url:c},{setRequestHeader:d});var h=function(e){var t=w();if(f.responseText=(O.isString(e.data)||O.isObject(e.data))&&e.data,f.elapsedTime=t-f.sTime,f.status=e.statusCode,f.errMsg=e.errMsg,Oe(l.XHR,f),"function"==typeof i.success)return i.success(e)},g=i.fail,E=function(e){var t=w();if(f.elapsedTime=t-f.sTime,f.errMsg=e.errMsg,Oe(l.XHR,f),O.isFunction(g))return g(e)},R=o(o({},i),{success:h,fail:E});return t.call(this,R)}})}));break;case l.MINI_ROUTE:[r.SwitchTab,r.ReLaunch,r.RedirectTo,r.NavigateTo,r.NavigateBack].forEach((function(e){var t=wx[e];Object.defineProperty(wx,e,{writable:!0,enumerable:!0,configurable:!0,value:function(n){var a;a=e===r.NavigateBack?function(e){if(!O.isFunction(getCurrentPages))return"";var t=getCurrentPages();if(!t.length)return"App";e=e||1;var n=t[t.length-e];return G(n.route,n.options)}(n.delta):n.url;var i={from:re(),to:a};if(Oe(l.MINI_ROUTE,i),O.isFunction(n.complete)||O.isFunction(n.success)||O.isFunction(n.fail)){var s=n.fail;n.fail=function(e){var t=o(o({},i),{isFail:!0,message:e.errMsg});if(Oe(l.MINI_ROUTE,t),O.isFunction(s))return s(e)}}return t.call(this,n)}})}))}}function Ue(e){Ee(e)&&Se(e.type)}var He=[n.PageOnShow,n.PageOnHide,n.PageOnShareAppMessage,n.PageOnShareTimeline,n.PageOnTabItemTap];function xe(e){He.forEach((function(t){x(e,t.replace("PageOn","on"),(function(e){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];Oe.apply(null,s([t],n)),e&&e.apply(this,n)}}),!0)}))}function ke(e){var t=k((function(e){e.mitoWorked=!0,Oe(l.DOM,e)}),500),n=[W.Touchmove,W.Tap];Object.keys(e).forEach((function(r){"function"==typeof e[r]&&x(e,r,(function(e){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var a=r[0];return a&&a.type&&a.currentTarget&&!a.mitoWorked&&n.indexOf(a.type)>-1&&t(a),e.apply(this,r)}}),!0)}))}function we(){!function(){if(App){var e=App;App=function(n){return[t.AppOnLaunch,t.AppOnShow,t.AppOnError,t.AppOnUnhandledRejection,t.AppOnPageNotFound,t.AppOnHide].forEach((function(e){C(e)||(Ue({callback:function(t){return be[e.replace("AppOn","on")](t)},type:e}),x(n,e.replace("AppOn","on"),(function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];Oe.apply(null,s([e],n)),t&&t.apply(this,n)}}),!0))})),e(n)}}}(),function(){if(Page){var e=Page;He.forEach((function(e){C(e)||Ue({callback:function(t){return Ae[e.replace("PageOn","on")](t)},type:e})})),Page=function(t){return xe(t),ke(t),e.call(this,t)}}}(),function(){if(Component){var e=Component;Component=function(t){return y(t.methods)||(xe(t.methods),ke(t.methods)),e.call(this,t)}}}(),function(){if(Behavior){var e=Behavior;Behavior=function(t){return y(t.methods)||ke(t.methods),e.call(this,t)}}}(),Ue({callback:function(e){return Ie(e)},type:l.MINI_ROUTE}),Ue({callback:function(e){Ce(e)},type:l.XHR}),Ue({callback:function(e){_e(e)},type:l.CONSOLE}),Ue({callback:function(e){return Ae.onAction(e)},type:l.DOM})}function De(e){void 0===e&&(e={}),"XMLHttpRequest"in N&&!e.disabled&&(Ne(e),Te({callback:function(e){he.handleHttp(e,c.XHR)},type:l.XHR}),Te({callback:function(e){he.handleHttp(e,c.FETCH)},type:l.FETCH}),Te({callback:function(e){he.handleError(e)},type:l.ERROR}),Te({callback:function(e){he.handleConsole(e)},type:l.CONSOLE}),Te({callback:function(e){he.handleHistory(e)},type:l.HISTORY}),Te({callback:function(e){he.handleUnhandleRejection(e)},type:l.UNHANDLEDREJECTION}),Te({callback:function(e){var t=function(e){var t=e.tagName.toLowerCase();if("body"===t)return null;var n=e.classList.value;return n=""!==n?' class="'+n+'"':"","<"+t+(e.id?' id="'+e.id+'"':"")+(""!==n?n:"")+">"+e.innerText+"</"+t+">"}(e.data.activeElement);t&&$.push({type:c.CLICK,category:$.getCategory(c.CLICK),data:t,level:z.Info})},type:l.DOM}),Te({callback:function(e){he.handleHashchange(e)},type:l.HASHCHANGE}))}return{MitoVue:de,SDK_VERSION:"1.2.7",SDK_NAME:"@zyf2e/mitojs",init:function(e){void 0===e&&(e={}),T?De(e):m&&function(e){void 0===e&&(e={}),m&&(Ne(e),we(),Object.assign(wx,{mitoLog:ae}))}(e)},log:ae,errorBoundaryReport:function(t){if(R(t)){var n=B(t,z.Normal);n.type=e.REACT_ERROR,$.push({type:c.REACT,category:$.getCategory(c.REACT),data:n.name+": "+n.message,level:z.fromString(n.level)}),ne.send(n)}else console.warn("传入的react error不是一个object Error")}}}();