mutiple
Version:
A SDK for monitoring browser and miniPrograme errors
2 lines (1 loc) • 26.6 kB
JavaScript
var MITO=function(e){"use strict";var t=function(){return(t=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 n(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 r(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 o(){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}var a,i,s,c,u,l,p,f,d;!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"}(a||(a={})),function(e){e.AppOnLaunch="AppOnLaunch",e.AppOnShow="AppOnShow",e.AppOnHide="AppOnHide",e.AppOnError="AppOnError",e.AppOnPageNotFound="AppOnPageNotFound",e.AppOnUnhandledRejection="AppOnUnhandledRejection"}(i||(i={})),function(e){e.PageOnShow="PageOnShow",e.PageOnHide="PageOnHide",e.PageOnShareAppMessage="PageOnShareAppMessage",e.PageOnShareTimeline="PageOnShareTimeline",e.PageOnTabItemTap="PageOnTabItemTap"}(s||(s={})),function(e){e.SwitchTab="switchTab",e.ReLaunch="reLaunch",e.RedirectTo="redirectTo",e.NavigateTo="navigateTo",e.NavigateBack="navigateBack",e.RouteFail="routeFail"}(c||(c={})),t(t(t({},i),s),a),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"}(u||(u={})),function(e){e.HTTP="http",e.USER="user",e.DEBUG="debug",e.EXCEPTION="exception",e.LIFECYCLE="lifecycle"}(l||(l={})),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"}(p||(p={})),function(e){e.XHR="xhr",e.FETCH="fetch"}(f||(f={})),function(e){e[e.BAD_REQUEST=400]="BAD_REQUEST",e[e.UNAUTHORIZED=401]="UNAUTHORIZED",e[e.INTERNAL_EXCEPTION=500]="INTERNAL_EXCEPTION"}(d||(d={}));var h=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/,E={isLogAddBreadcrumb:!0,crossOriginThreshold:1e3},R=Object.prototype.toString;function g(e){return function(t){return R.call(t)==="[object "+e+"]"}}var O={isNumber:g("Number"),isString:g("String"),isBoolean:g("Boolean"),isNull:g("Null"),isUndefined:g("Undefined"),isSymbol:g("Symbol"),isFunction:g("Function"),isObject:g("Object"),isArray:g("Array"),isProcess:g("process"),isWindow:g("Window")};function m(e){switch(R.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)}}var y=O.isProcess("undefined"!=typeof process?process:0),v=O.isObject("undefined"!=typeof wx?wx:0)&&O.isFunction("undefined"!=typeof App?App:0),b=O.isWindow("undefined"!=typeof window?window:0);var T=b?window:v?wx:y?process:void 0,N=(T.__MITO__=T.__MITO__||{},T.__MITO__);N.replaceFlag=N.replaceFlag||{};var _=N.replaceFlag;function A(e,t){_[e]||(_[e]=t)}function C(e){return!!_[e]}var S="MITO Logger",U=function(){function e(){var e=this;if(this.enabled=!1,this._console={},T.console=console||T.console,console||T.console){["log","debug","info","warn","error","assert"].forEach((function(t){t in T.console&&(e._console[t]=T.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,o([S+"[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,o([S+"[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,o([S+"[Error]:"],t))},e}(),I=N.logger||(N.logger=new U);function x(){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 P(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)}}function k(){return Date.now()}function w(e,t,n){return!!function(e,t){return typeof e===t}(e,n)||(void 0!==e&&I.error(t+"期望传入"+n+"类型,目前是"+typeof e+"类型"),!1)}function D(e,t,n){return!!function(e,t){return R.call(e)===t}(e,n)||(void 0!==e&&I.error(t+"期望传入"+n+"类型,目前是"+R.call(e)+"类型"),!1)}function L(e){E.isLogAddBreadcrumb=!1,e(),E.isLogAddBreadcrumb=!0}function F(e){return O.isString(e)?e:O.isUndefined(e)?"undefined":JSON.stringify(e)}function M(e){return Number(e.split(".")[0])}function j(){if(!O.isFunction(getCurrentPages))return"";var e=getCurrentPages();if(!e.length)return"App";var t,n,r,o=e.pop();return t=o.route,n=o.options,r=[],Object.keys(n).forEach((function(e){r.push(e+"="+n[e])})),t=-1!==t.indexOf("?")?t+"&"+r.join("&"):t+"?"+r.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(e,n){var r={time:k(),url:x(),name:e.name,level:n,message:e.message};if(void 0===e.stack||!e.stack)return r;for(var o,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=e.stack.split("\n"),h=[],E=0,R=d.length;E<R;++E){if(i=c.exec(d[E])){var g=i[2]&&0===i[2].indexOf("native");i[2]&&0===i[2].indexOf("eval")&&(o=f.exec(i[2]))&&(i[2]=o[1],i[3]=o[2],i[4]=o[3]),s={url:g?null:i[2],func:i[1]||a.UNKNOWN_FUNCTION,args:g?[i[2]]:[],line:i[3]?+i[3]:null,column:i[4]?+i[4]:null}}else if(i=l.exec(d[E]))s={url:i[2],func:i[1]||a.UNKNOWN_FUNCTION,args:[],line:+i[3],column:i[4]?+i[4]:null};else{if(!(i=u.exec(d[E])))continue;i[3]&&i[3].indexOf(" > eval")>-1&&(o=p.exec(i[3]))?(i[3]=o[1],i[4]=o[2],i[5]=null):0!==E||i[5]||void 0===e.columnNumber||(h[0].column=e.columnNumber+1),s={url:i[3],func:i[1]||a.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=a.UNKNOWN_FUNCTION),h.push(s)}return h.length?t(t({},r),{stack:h}):null}var G,V,W=function(){function e(){this.stack=[],this.isFlushing=!1,"Promise"in T&&(this.micro=Promise.resolve())}return e.prototype.addFn=function(e){var t=this;"function"==typeof e&&("Promise"in T?(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}();!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"}(G||(G={})),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}}}(G||(G={})),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"}(V||(V={}));var $,J=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(L((function(){n=r(t,e)})),!n)return;this.immediatePush(n)}},e.prototype.immediatePush=function(e){e.time=k(),this.stack.length>=this.maxBreadcrumbs&&this.shift(),this.stack.push(e),I.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 u.XHR:case u.FETCH:return l.HTTP;case u.CLICK:case u.ROUTE:case u.TAP:case u.TOUCHMOVE:return l.USER;case u.CUSTOMER:case u.CONSOLE:return l.DEBUG;case u.APP_ON_LAUNCH:case u.APP_ON_SHOW:case u.APP_ON_HIDE:case u.PAGE_ON_SHOW:case u.PAGE_ON_HIDE:case u.PAGE_ON_SHARE_APP_MESSAGE:case u.PAGE_ON_SHARE_TIMELINE:case u.PAGE_ON_TAB_ITEM_TAP:return l.LIFECYCLE;case u.UNHANDLEDREJECTION:case u.CODE_ERROR:case u.RESOURCE:case u.VUE:case u.REACT:default:return l.EXCEPTION}},e.prototype.bindOptions=function(e){void 0===e&&(e={});var t=e.maxBreadcrumbs,n=e.beforePushBreadcrumb;w(t,"maxBreadcrumbs","number")&&(this.maxBreadcrumbs=t),w(n,"beforePushBreadcrumb","function")&&(this.beforePushBreadcrumb=n)},e}(),q=N.breadcrumb||(N.breadcrumb=new J),K={};function Y(e,t){var n;switch(e.type){case a.FETCH_ERROR:n=e.type+e.request.method+e.response.status+Q(e.request.url)+t;break;case a.JAVASCRIPT_ERROR:case a.VUE_ERROR:case a.REACT_ERROR:n=e.type+e.name+e.message+t;break;case a.LOG_ERROR:n=e.customTag+e.type+e.name+t;break;case a.PROMISE_ERROR:n=function(e,t){var n=Q(e.url);if(e.name===p.UNHANDLEDREJECTION)return e.type+Z(e.message)+t;return e.type+e.name+Z(e.message)+n}(e,t);break;default:n=e.type+e.message+t}return n=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}(n),K[n]>1?null:("number"==typeof K[n]?K[n]++:K[n]=1,n)}function Z(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 Q(e){return e.replace(/[\?#].*$/,"").replace(/\/\d+([\/]*$)/,"{param}$1")}!function(e){e.Get="GET",e.Post="POST",e.Put="PUT",e.Delete="DELETE"}($||($={}));var z=function(){function e(e){this.url=e,this.beforeDataReport=null,this.backTrackerId=null,this.configReportXhr=null,this.apikey="",this.queue=new W}return e.prototype.getRecord=function(){var e=N.record;return e&&O.isArray(e)&&e.length>2?e:[]},e.prototype.beforePost=function(e){return n(this,void 0,void 0,(function(){var t,n;return r(this,(function(r){switch(r.label){case 0:return(t=Y(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 n(this,void 0,void 0,(function(){var t,n,o=this;return r(this,(function(r){switch(r.label){case 0:return[4,this.beforePost(e)];case 1:return(t=r.sent())?(n=function(){var e=new XMLHttpRequest;e.open($.Post,o.url),e.setRequestHeader("Content-Type","application/json;charset=UTF-8"),e.withCredentials=!0,"function"==typeof o.configReportXhr&&o.configReportXhr(e),e.send(t)},this.queue.addFn(n),[2]):[2]}}))}))},e.prototype.wxPost=function(e){return n(this,void 0,void 0,(function(){var t,n,o=this;return r(this,(function(r){switch(r.label){case 0:return[4,this.beforePost(e)];case 1:return(t=r.sent())?(n=function(){wx.request({method:"POST",header:{"Content-Type":"application/json;charset=UTF-8"},url:o.url,data:t})},this.queue.addFn(n),[2]):[2]}}))}))},e.prototype.getAuthInfo=function(){var e=this.getTrackerId();return{trackerId:String(e),sdkVersion:"2.0.0",sdkName:"mito",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;I.error("trackerId:"+e+" 期望 string 或 number 类型,但是传入 "+typeof e)}return""},e.prototype.getTransportData=function(e){return{authInfo:this.getAuthInfo(),breadcrumb:q.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;w(r,"apikey","string")&&(this.apikey=r),w(t,"dsn","string")&&(this.url=t),w(n,"beforeDataReport","function")&&(this.beforeDataReport=n),w(o,"configReportXhr","function")&&(this.configReportXhr=o),w(a,"backTrackerId","function")&&(this.backTrackerId=a)},e.prototype.send=function(e){return b?this.xhrPost(e):v?this.wxPost(e):void 0},e}(),ee=N.transportData||(N.transportData=new z("//localhost:3000/api/error/upload"));function te(e){var t="",n=e.elapsedTime,r=e.time,o=e.method,i=e.traceId,s=e.type,c=e.status,u=s+"--"+o;return t=(t=0===c?n<=E.crossOriginThreshold?"http请求失败,失败原因:跨域限制或域名不存在":"http请求失败,失败原因:超时":function(e){if(e<400)return V.Ok;if(e>=400&&e<500)switch(e){case 401:return V.Unauthenticated;case 403:return V.PermissionDenied;case 404:return V.NotFound;case 409:return V.AlreadyExists;case 413:return V.FailedPrecondition;case 429:return V.ResourceExhausted;default:return V.InvalidArgument}if(e>=500&&e<600)switch(e){case 501:return V.Unimplemented;case 503:return V.Unavailable;case 504:return V.DeadlineExceeded;default:return V.InternalError}return V.UnknownError}(c))===V.Ok?t:t+" "+Q(e.url),{type:a.FETCH_ERROR,url:x(),time:r,elapsedTime:n,level:G.Low,message:t,name:u,request:{httpType:s,traceId:i,method:o,url:e.url,data:e.reqData||""},response:{status:c,data:e.responseText}}}var ne={img:"图片",script:"js脚本"};var re=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;w(t,"beforeAppAjaxSend","function")&&(this.beforeAppAjaxSend=t),w(n,"enableTraceId","boolean")&&(this.enableTraceId=n),w(o,"traceIdFieldName","string")&&(this.traceIdFieldName=o),D(r,"filterXhrUrlRegExp","[object RegExp]")&&(this.filterXhrUrlRegExp=r),D(a,"includeHttpUrlTraceIdRegExp","[object RegExp]")&&(this.includeHttpUrlTraceIdRegExp=a)},e}(),oe=N.options||(N.options=new re);function ae(e,t){var n,r=oe.includeHttpUrlTraceIdRegExp;if(oe.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(oe.traceIdFieldName,o)}}function ie(e){var t;void 0===e&&(e={}),void 0===(t=e)&&(t={}),A(p.XHR,!!t.silentXhr),A(p.FETCH,!!t.silentFetch),A(p.CONSOLE,!!t.silentConsole),A(p.DOM,!!t.silentDom),A(p.HISTORY,!!t.silentHistory),A(p.ERROR,!!t.silentError),A(p.HASHCHANGE,!!t.silentHashchange),A(p.UNHANDLEDREJECTION,!!t.silentUnhandledrejection),A(p.VUE,!!t.silentVue),A(i.AppOnError,!!t.silentWxOnError),A(i.AppOnUnhandledRejection,!!t.silentUnhandledrejection),A(i.AppOnPageNotFound,!!t.silentWxOnPageNotFound),A(s.PageOnShareAppMessage,!!t.silentWxOnShareAppMessage),A(p.MINI_ROUTE,!!t.silentMiniRoute),q.bindOptions(e),I.bindOptions(e.debug),ee.bindOptions(e),oe.bindOptions(e)}var se={};function ce(e,t){e&&se[e]&&se[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;I.error("重写事件triggerHandlers的回调函数发生错误\nType:"+e+"\nName: "+(((r=n)&&"function"==typeof r&&r.name||"<anonymous>")+"\nError: ")+t)}))}))}var ue,le,pe,fe,de={handleHttp:function(e,n){var r=0===e.status||e.status===d.BAD_REQUEST||e.status>d.UNAUTHORIZED,o=te(e);q.push({type:n,category:q.getCategory(n),data:t({},o),level:G.Info}),r&&(q.push({type:n,category:q.getCategory(u.CODE_ERROR),data:t({},o),level:G.Error}),ee.send(o))},handleError:function(e){if(e.target.localName){var n=function(e){return{type:a.RESOURCE_ERROR,url:x(),message:"资源地址: "+(e.src.slice(0,100)||e.href.slice(0,100)),level:G.Low,time:k(),name:(ne[e.localName]||e.localName)+"加载失败"}}(e.target);return q.push({type:u.RESOURCE,category:q.getCategory(u.RESOURCE),data:n,level:G.Error}),ee.send(n)}var r,o=e.message,i=e.filename,s=e.lineno,c=e.colno,l=e.error;l&&m(l)&&(r=B(l,G.Normal)),r||(r=de.handleNotErrorInstance(o,i,s,c)),r.type=a.JAVASCRIPT_ERROR,q.push({type:u.CODE_ERROR,category:q.getCategory(u.CODE_ERROR),data:t({},r),level:G.Error}),ee.send(r)},handleNotErrorInstance:function(e,t,n,r){var o=a.UNKNOWN,i=t||x(),s=e,c=e.match(h);c[1]&&(o=c[1],s=c[2]);var u={url:i,func:a.UNKNOWN_FUNCTION,args:a.UNKNOWN,line:n,col:r};return{url:i,name:o,message:s,level:G.Normal,time:k(),stack:[u]}},handleHistory:function(e){var t=e.from,n=e.to,r=X(t).relative,o=X(n).relative;q.push({type:u.ROUTE,category:q.getCategory(u.ROUTE),data:{from:r||"/",to:o||"/"},level:G.Info})},handleHashchange:function(e){var t=e.oldURL,n=e.newURL,r=X(t).relative,o=X(n).relative;q.push({type:u.ROUTE,category:q.getCategory(u.ROUTE),data:{from:r,to:o},level:G.Info})},handleUnhandleRejection:function(e){var n={type:a.PROMISE_ERROR,message:F(e.reason),url:x(),name:e.type,time:k(),level:G.Low};m(e.reason)&&(n=t(t({},n),B(e.reason,G.Low))),q.push({type:u.UNHANDLEDREJECTION,category:q.getCategory(u.UNHANDLEDREJECTION),data:t({},n),level:G.Error}),ee.send(n)}},he=(ue=ce,le=600,pe=!0,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];pe&&(ue.apply(this,e),pe=!1,setTimeout((function(){pe=!0}),le))});function Ee(e){return oe.filterXhrUrlRegExp&&oe.filterXhrUrlRegExp.test(e)}function Re(e){switch(e){case p.XHR:!function(){if(!("XMLHttpRequest"in T))return;var e=XMLHttpRequest.prototype;P(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:k(),type:f.XHR},e.apply(this,t)}})),P(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;ae(i,(function(e,n){t.mito_xhr.traceId=n,t.setRequestHeader(e,n)})),oe.beforeAppAjaxSend&&oe.beforeAppAjaxSend({method:a,url:i},this),H(this,"loadend",(function(){if(!(a===$.Post&&ee.isSdkTransportUrl(i)||Ee(i))){var e=this.responseType,t=this.response,r=this.status;this.mito_xhr.reqData=n[0];var o=k();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,ce(p.XHR,this.mito_xhr)}})),e.apply(this,n)}}))}();break;case p.FETCH:!function(){if(!("fetch"in T))return;P(T,p.FETCH,(function(e){return function(n,r){void 0===r&&(r={});var o=k(),a=r&&r.method||"GET",i={type:f.FETCH,method:a,reqData:r&&r.body,url:n},s=new Headers(r.headers||{});return Object.assign(s,{setRequestHeader:s.set}),ae(n,(function(e,t){i.traceId=t,s.set(e,t)})),oe.beforeAppAjaxSend&&oe.beforeAppAjaxSend({method:a,url:n},s),r=t(t({},r),{headers:s}),e.apply(T,[n,r]).then((function(e){var r=e.clone(),s=k();return i=t(t({},i),{elapsedTime:s-o,status:r.status,time:s}),r.text().then((function(e){a===$.Post&&ee.isSdkTransportUrl(n)||Ee(n)||(i.responseText=r.status>d.UNAUTHORIZED&&e,ce(p.FETCH,i))})),e}),(function(e){var r=k();if(!(a===$.Post&&ee.isSdkTransportUrl(n)||Ee(n)))throw i=t(t({},i),{elapsedTime:r-o,status:0,time:r}),ce(p.FETCH,i),e}))}}))}();break;case p.ERROR:H(T,"error",(function(e){ce(p.ERROR,e)}),!0);break;case p.CONSOLE:!function(){if(!("console"in T))return;["log","debug","info","warn","error","assert"].forEach((function(e){e in T.console&&P(T.console,e,(function(t){return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];t&&(ce(p.CONSOLE,{args:n,level:e}),t.apply(T.console,n))}}))}))}();break;case p.HISTORY:!function(){if(e=T.chrome,t=e&&e.app&&e.app.runtime,n="history"in T&&!!T.history.pushState&&!!T.history.replaceState,t||!n)return;var e,t,n;var r=T.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=fe,a=String(r);fe=a,ce(p.HISTORY,{from:o,to:a})}return e.apply(this,t)}}T.onpopstate=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=x(),o=fe;ce(p.HISTORY,{from:o,to:n}),r&&r.apply(this,e)},P(T.history,"pushState",o),P(T.history,"replaceState",o)}();break;case p.UNHANDLEDREJECTION:H(T,p.UNHANDLEDREJECTION,(function(e){ce(p.UNHANDLEDREJECTION,e)}));break;case p.DOM:!function(){if(!("document"in T))return;H(T.document,"click",(function(){he(p.DOM,{category:"click",data:this})}),!0)}();break;case p.HASHCHANGE:n="onpopstate",T.hasOwnProperty(n)||H(T,p.HASHCHANGE,(function(e){ce(p.HASHCHANGE,e)}))}var n}function ge(e){(function(e){return!(!e||C(e.type))&&(A(e.type,!0),se[e.type]=se[e.type]||[],se[e.type].push(e.callback),!0)})(e)&&Re(e.type)}function Oe(){ge({callback:function(e){de.handleHttp(e,u.XHR)},type:p.XHR}),ge({callback:function(e){de.handleHttp(e,u.FETCH)},type:p.FETCH}),ge({callback:function(e){de.handleError(e)},type:p.ERROR}),ge({callback:function(e){!function(e){E.isLogAddBreadcrumb&&q.push({type:u.CONSOLE,category:q.getCategory(u.CONSOLE),data:e,level:G.fromString(e.level)})}(e)},type:p.CONSOLE}),ge({callback:function(e){de.handleHistory(e)},type:p.HISTORY}),ge({callback:function(e){de.handleUnhandleRejection(e)},type:p.UNHANDLEDREJECTION}),ge({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&&q.push({type:u.CLICK,category:q.getCategory(u.CLICK),data:t,level:G.Info})},type:p.DOM}),ge({callback:function(e){de.handleHashchange(e)},type:p.HASHCHANGE})}function me(e,n,r,o,i,s){var c=null==s?void 0:s.version,l={type:a.VUE_ERROR,message:e.message+"("+r+")",level:o,url:x(),name:e.name,stack:e.stack||[],time:k()};if(O.isString(c))switch(console.log("getBigVersion",M(c)),M(c)){case 2:l=t(t({},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=t(t({},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}q.push({type:u.VUE,category:q.getCategory(u.VUE),data:l,level:i}),ee.send(l)}fe=x();var ye="undefined"!=typeof console,ve={install:function(e){!C(p.VUE)&&e&&e.config&&(A(p.VUE,!0),e.config.errorHandler=function(t,n,r){me.apply(null,[t,n,r,G.Normal,G.Error,e]),ye&&!e.config.silent&&L((function(){console.error("Error in "+r+': "'+t.toString()+'"',n),console.error(t)}))})}};return e.MitoVue=ve,e.SDK_NAME="mito",e.SDK_VERSION="2.0.0",e.errorBoundaryReport=function(e){if(m(e)){var t=B(e,G.Normal);t.type=a.REACT_ERROR,q.push({type:u.REACT,category:q.getCategory(u.REACT),data:t.name+": "+t.message,level:G.fromString(t.level)}),ee.send(t)}else console.warn("传入的react error不是一个object Error")},e.init=function(e){void 0===e&&(e={}),function(e){void 0===e&&(e={}),"XMLHttpRequest"in T&&!e.disabled&&(ie(e),Oe())}(e)},e.log=function(e){var n=e.message,r=void 0===n?"emptyMsg":n,o=e.tag,i=void 0===o?"":o,s=e.level,c=void 0===s?G.Critical:s,l=e.ex,p=void 0===l?"":l,f={};m(p)&&(f=B(p,c));var d=t({type:a.LOG_ERROR,level:c,message:F(r),name:"MITO.log",customTag:F(i),time:k(),url:v?j():x()},f);q.push({type:u.CUSTOMER,category:q.getCategory(u.CUSTOMER),data:r,level:G.fromString(c.toString())}),ee.send(d)},Object.defineProperty(e,"__esModule",{value:!0}),e}({});