@mitojs/browser
Version:
A SDK For Monitoring Browser Errors
2 lines (1 loc) • 23.4 kB
JavaScript
var MITO=function(t){"use strict";var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,n)};function n(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r=function(){return(r=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function o(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function i(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function a(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var s=/^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/,c={isLogAddBreadcrumb:!0,crossOriginThreshold:1e3},u=Object.prototype.toString;function l(t){return function(e){return u.call(e)==="[object "+t+"]"}}var f={isNumber:l("Number"),isString:l("String"),isBoolean:l("Boolean"),isNull:l("Null"),isUndefined:l("Undefined"),isSymbol:l("Symbol"),isFunction:l("Function"),isObject:l("Object"),isArray:l("Array"),isProcess:l("process"),isWindow:l("Window")};function p(t){switch(u.call(t)){case"[object Error]":case"[object Exception]":case"[object DOMException]":return!0;default:return function(t,e){try{return t instanceof e}catch(t){return!1}}(t,Error)}}var h=f.isProcess("undefined"!=typeof process?process:0),d=f.isObject("undefined"!=typeof wx?wx:0)&&f.isFunction("undefined"!=typeof App?App:0),m=f.isWindow("undefined"!=typeof window?window:0);var g=m?window:d?wx:h?process:void 0,v=(g.__MITO__=g.__MITO__||{},g.__MITO__);var y="MITO Logger",b=function(){function t(){var t=this;if(this.enabled=!1,this._console={},g.console=console||g.console,console||g.console){["log","debug","info","warn","error","assert"].forEach((function(e){e in g.console&&(t._console[e]=g.console[e])}))}}return t.prototype.disable=function(){this.enabled=!1},t.prototype.bindOptions=function(t){this.enabled=!!t},t.prototype.enable=function(){this.enabled=!0},t.prototype.getEnableStatus=function(){return this.enabled},t.prototype.log=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.enabled&&(t=this._console).log.apply(t,a([y+"[Log]:"],e,!1))},t.prototype.warn=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.enabled&&(t=this._console).warn.apply(t,a([y+"[Warn]:"],e,!1))},t.prototype.error=function(){for(var t,e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];(t=this._console).error.apply(t,a([y+"[Error]:"],e,!1))},t}(),x=v.logger||(v.logger=new b);function w(){return"undefined"==typeof document||null==document.location?"":document.location.href}function O(){return d?function(){if(!f.isFunction(getCurrentPages))return"";var t=getCurrentPages();if(!t.length)return"App";var e=t.pop();return function(t,e){var n=[];Object.keys(e).forEach((function(t){n.push(t+"="+e[t])})),t=-1!==t.indexOf("?")?t+"&"+n.join("&"):t+"?"+n.join("&");return t}(e.route,e.options)}():m?w():""}function k(t,e,n,r){void 0===r&&(r=!1),t.addEventListener(e,n,r)}function T(t,e,n,r){if(void 0===r&&(r=!1),void 0!==t&&(e in t||r)){var o=n(t[e]);"function"==typeof o&&(t[e]=o)}}function I(){return Date.now()}function S(t,e,n){return!!function(t,e){return u.call(t)==="[object "+e+"]"}(t,n)||(void 0!==t&&x.error(e+"期望传入:"+n+"类型,当前是:"+u.call(t)+"类型"),!1)}function N(t){return f.isString(t)?t:f.isUndefined(t)?"undefined":JSON.stringify(t)}function R(t,e){return f.isString(t)?t.slice(0,e)+(t.length>e?";slice the first "+e+" characters":""):""}function U(t){var e=new Set,n=JSON.stringify(t,(function(t,n){return e.has(n)?"Circular":("object"==typeof n&&e.add(n),n)}));return e.clear(),n}function E(t){var e=this;t.forEach((function(t){var n=t[0],r=t[1];return S(n,r,t[2])&&(e[r]=n)}))}function C(t){if(!t)return{};var e=t.match(/^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?$/);if(!e)return{};var n=e[6]||"",r=e[8]||"";return{host:e[4],path:e[5],protocol:e[2],relative:e[5]+n+r}}function j(t){switch(t){case"Xhr":case"Fetch":return"http";case"UI.Click":case"Route":return"user";case"Customer":case"Console":return"debug";case"Unhandledrejection":case"Code Error":case"Resource":default:return"exception"}}function _(t,e){var n={time:I(),url:O(),name:t.name,level:e,message:t.message};if(void 0===t.stack||!t.stack)return n;for(var o,i,a,s=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|[a-z]:|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,c=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i,u=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,l=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,f=/\((\S*)(?::(\d+))(?::(\d+))\)/,p=t.stack.split("\n"),h=[],d=0,m=p.length;d<m;++d){if(i=s.exec(p[d])){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]),a={url:g?null:i[2],func:i[1]||"UNKNOWN_FUNCTION",args:g?[i[2]]:[],line:i[3]?+i[3]:null,column:i[4]?+i[4]:null}}else if(i=u.exec(p[d]))a={url:i[2],func:i[1]||"UNKNOWN_FUNCTION",args:[],line:+i[3],column:i[4]?+i[4]:null};else{if(!(i=c.exec(p[d])))continue;i[3]&&i[3].indexOf(" > eval")>-1&&(o=l.exec(i[3]))?(i[3]=o[1],i[4]=o[2],i[5]=null):0!==d||i[5]||void 0===t.columnNumber||(h[0].column=t.columnNumber+1),a={url:i[3],func:i[1]||"UNKNOWN_FUNCTION",args:i[2]?i[2].split(","):[],line:i[4]?+i[4]:null,column:i[5]?+i[5]:null}}!a.func&&a.line&&(a.func="UNKNOWN_FUNCTION"),h.push(a)}return h.length?r(r({},n),{stack:h}):null}var A,F=function(){function t(){this.stack=[],this.isFlushing=!1,"Promise"in g&&(this.micro=Promise.resolve())}return t.prototype.addTask=function(t){var e=this;"function"==typeof t&&("Promise"in g?(this.stack.push(t),this.isFlushing||(this.isFlushing=!0,this.micro.then((function(){return e.flushStack()})))):t())},t.prototype.clear=function(){this.stack=[]},t.prototype.getStack=function(){return this.stack},t.prototype.flushStack=function(){var t=this.stack.slice(0);this.stack.length=0,this.isFlushing=!1;for(var e=0,n=t;e<n.length;e++){(0,n[e])()}},t}();!function(t){t.Else="else",t.Error="error",t.Warning="warning",t.Info="info",t.Debug="debug",t.Low="low",t.Normal="normal",t.High="high",t.Critical="critical"}(A||(A={})),function(t){t.fromString=function(e){switch(e){case"debug":return t.Debug;case"info":case"log":case"assert":return t.Info;case"warn":case"warning":return t.Warning;case t.Low:case t.Normal:case t.High:case t.Critical:case"error":return t.Error;default:return t.Else}}}(A||(A={}));var P={};function B(t,e,n){var r;switch(t.type){case"HTTP":r=t.type+t.request.method+t.response.status+H(t.request.url)+e;break;case"JAVASCRIPT":case"VUE":case"REACT":r=t.type+t.name+t.message+e;break;case"LOG":r=t.customTag+t.type+t.name+e;break;case"PROMISE":r=function(t,e){var n=H(t.url);if("unhandledrejection"===t.name)return t.type+D(t.message)+e;return t.type+t.name+D(t.message)+n}(t,e);break;default:r=t.type+t.message+e}return r=function(t){var e=0;if(0==t.length)return e;for(var n=0;n<t.length;n++){var r=t.charCodeAt(n);e=(e<<5)-e+r,e&=e}return e}(r),P[r]>=n?null:("number"==typeof P[r]?P[r]++:P[r]=1,r)}function D(t){try{if(/\{.*\}/.test(t)){var e=JSON.parse(t);return e=function t(e){return Object.keys(e).sort().reduce((function(n,r){return f.isObject(e[r])?n[r]=t(e[r]):n[r]=e[r],n}),{})}(e),JSON.stringify(e)}return t}catch(e){return t}}function H(t){return t.replace(/[?#].*$/,"").replace(/\/(\d+)\//g,"/{param}/$1").replace(/\/\d+([/]*$)/g,"/{param}$1")}var L=function(){function t(t){void 0===t&&(t={}),this.maxBreadcrumbs=10,this.beforePushBreadcrumb=null,this.stack=[],this.bindOptions(t)}return t.prototype.push=function(t){var e,n=this;if("function"==typeof this.beforePushBreadcrumb){var r=null,o=this.beforePushBreadcrumb;return e=function(){r=o.call(n,n,t)},c.isLogAddBreadcrumb=!1,e(),c.isLogAddBreadcrumb=!0,r?this.immediatePush(r):this.stack}return this.immediatePush(t)},t.prototype.immediatePush=function(t){return t.time||(t.time=I()),this.stack.length>=this.maxBreadcrumbs&&this.shift(),this.stack.push(t),this.stack.sort((function(t,e){return t.time-e.time})),x.log(this.stack),this.stack},t.prototype.shift=function(){return void 0!==this.stack.shift()},t.prototype.clear=function(){this.stack=[]},t.prototype.getStack=function(){return this.stack},t.prototype.bindOptions=function(t){void 0===t&&(t={});var e=t.maxBreadcrumbs,n=t.beforePushBreadcrumb;S(e,"maxBreadcrumbs","Number")&&(this.maxBreadcrumbs=e),S(n,"beforePushBreadcrumb","Function")&&(this.beforePushBreadcrumb=n)},t}(),q=function(){function t(){this.dep=new Map}return t.prototype.watch=function(t,e){var n=this.dep.get(t);n?this.dep.set(t,n.concat(e)):this.dep.set(t,[e])},t.prototype.notify=function(t,e){var n=this.dep.get(t);t&&n&&n.forEach((function(n){!function(t,e){try{t()}catch(t){console.error("err",t),e&&e(t)}}((function(){n(e)}),(function(e){x.error("Subscrib.notify:监听事件的回调函数发生错误\neventName:"+t+"\nName: "+function(t){return t&&"function"==typeof t&&t.name||"<anonymous>"}(n)+"\nError: "+e)}))}))},t}(),X=function(){function t(t){this.SDK_VERSION="3.0.1",this.options=t,x.bindOptions(t.debug)}return t.prototype.use=function(t){var e=this;if(!this.options.disabled){var n=new q;t.forEach((function(t){if(e.isPluginEnable(t.name)){t.monitor.call(e,n.notify.bind(n));n.watch(t.name,(function(){for(var n,r,o=[],i=0;i<arguments.length;i++)o[i]=arguments[i];var a=null===(n=t.transform)||void 0===n?void 0:n.apply(e,o);null===(r=t.consumer)||void 0===r||r.call(e,a)}))}}))}},t.prototype.getOptions=function(){return this.options},t}(),M=function(){function t(){this.enableTraceId=!1,this.includeHttpUrlTraceIdRegExp=/.*/,this.traceIdFieldName="Trace-Id",this.throttleDelayTime=0,this.beforeAppAjaxSend=null,this.vue=null}return t.prototype.bindOptions=function(t){var e=t.enableTraceId,n=t.vue,r=t.filterXhrUrlRegExp,o=[[e,"enableTraceId","Boolean"],[t.traceIdFieldName,"traceIdFieldName","String"],[t.throttleDelayTime,"throttleDelayTime","Number"],[r,"filterXhrUrlRegExp","RegExp"],[t.includeHttpUrlTraceIdRegExp,"includeHttpUrlTraceIdRegExp","RegExp"],[t.beforeAppAjaxSend,"beforeAppAjaxSend","Function"]];E.call(this,o),this.vue=n},t.prototype.isFilterHttpUrl=function(t){return this.filterXhrUrlRegExp&&this.filterXhrUrlRegExp.test(t)},t.prototype.setTraceId=function(t,e){var n,r=this.includeHttpUrlTraceIdRegExp;if(this.enableTraceId&&r&&r.test(t)){var o=(n=(new Date).getTime(),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var e=(n+16*Math.random())%16|0;return n=Math.floor(n/16),("x"==t?e:3&e|8).toString(16)})));e(this.traceIdFieldName,o)}},t}(),W=function(){function t(){this.apikey="",this.dsn="",this.beforeDataReport=null,this.backTrackerId=null,this.configReportUrl=null,this.maxDuplicateCount=3,this.queue=new F}return t.prototype.getAuthInfo=function(){var t=this.getTrackerId();return{trackerId:String(t),sdkVersion:"3.0.1",sdkName:"mitojs",apikey:this.apikey}},t.prototype.getTrackerId=function(){if("function"==typeof this.backTrackerId){var t=this.backTrackerId();if("string"==typeof t||"number"==typeof t)return t;x.error("trackerId:"+t+" 期望 string 或 number 类型,但是传入 "+typeof t)}return""},t.prototype.isSelfDsn=function(t){return this.dsn&&(e=t,n=this.dsn,!!~e.indexOf(n));var e,n},t.prototype.bindOptions=function(t){void 0===t&&(t={});var e=t.dsn,n=t.beforeDataReport,r=[[t.apikey,"apikey","String"],[e,"dsn","String"],[t.maxDuplicateCount,"maxDuplicateCount","Number"],[n,"beforeDataReport","Function"],[t.backTrackerId,"backTrackerId","Function"],[t.configReportUrl,"configReportUrl","Function"]];E.call(this,r)},t.prototype.send=function(t,e){return void 0===e&&(e=[]),o(this,void 0,void 0,(function(){var n,o,a;return i(this,(function(i){switch(i.label){case 0:if(!t.isTrack){if(!(n=B(t,this.apikey,this.maxDuplicateCount)))return[2];t.errorId=n}return o=r(r({},this.getTransportData(t)),{breadcrumb:e}),"function"!=typeof this.beforeDataReport?[3,2]:[4,this.beforeDataReport(o)];case 1:if(!(o=i.sent()))return[2];i.label=2;case 2:return a=this.dsn,s=a,f.isString(s)&&""===s.trim()||null==s?(x.error("dsn is empty,pass in when initializing please"),[2]):"function"!=typeof this.configReportUrl||(a=this.configReportUrl(o,a))?[2,this.sendToServer(o,a)]:[2]}var s}))}))},t}(),$=function(t){function e(e){var n=t.call(this)||this;return n.configReportXhr=null,t.prototype.bindOptions.call(n,e),n.bindOptions(e),n}return n(e,t),e.prototype.bindOptions=function(t){var e=[[t.silentXhr,"silentXhr","Boolean"],[t.silentFetch,"silentFetch","Boolean"],[t.silentConsole,"silentConsole","Boolean"],[t.silentDom,"silentDom","Boolean"],[t.silentHistory,"silentHistory","Boolean"],[t.silentError,"silentError","Boolean"],[t.silentHashchange,"silentHashchange","Boolean"],[t.silentUnhandledrejection,"silentUnhandledrejection","Boolean"],[t.useImgUpload,"useImgUpload","Boolean"],[t.configReportXhr,"configReportXhr","Function"]];E.call(this,e)},e}(M),J=function(t){function e(e){void 0===e&&(e={});var n=t.call(this)||this;return n.useImgUpload=!1,t.prototype.bindOptions.call(n,e),n.bindOptions(e),n}return n(e,t),e.prototype.post=function(t,e){var n=this;this.queue.addTask((function(){var r=new XMLHttpRequest;r.open("POST",e),r.setRequestHeader("Content-Type","application/json;charset=UTF-8"),r.withCredentials=!0,"function"==typeof n.configReportXhr&&n.configReportXhr(r,t),r.send(U(t))}))},e.prototype.imgRequest=function(t,e){this.queue.addTask((function(){var n=new Image,r=-1===e.indexOf("?")?"?":"&";n.src=""+e+r+"data="+encodeURIComponent(U(t)),n=null}))},e.prototype.sendToServer=function(t,e){return this.useImgUpload?this.imgRequest(t,e):this.post(t,e)},e.prototype.getTransportData=function(t){return{authInfo:this.getAuthInfo(),data:t}},e.prototype.bindOptions=function(t){void 0===t&&(t={});var e=t.configReportXhr,n=t.useImgUpload;S(e,"configReportXhr","Function")&&(this.configReportXhr=e),S(n,"useImgUpload","Boolean")&&(this.useImgUpload=n)},e}(W),K=function(t){function e(e){void 0===e&&(e={});var n=t.call(this,e)||this;return n.options=new $(e),n.transport=new J(e),n.breadcrumb=new L(e),n}return n(e,t),e.prototype.isPluginEnable=function(t){var e="silent"+t.replace(/\b(\w)(\w*)/g,(function(t,e,n){return""+e.toUpperCase()+n}));return!this.options[e]},e.prototype.log=function(t){var e=t.message,n=void 0===e?"empty.msg":e,o=t.tag,i=void 0===o?"empty.tag":o,a=t.level,s=void 0===a?A.Critical:a,c=t.ex,u=void 0===c?"":c,l={};p(u)&&(l=_(u,s));var f=r({type:"LOG",level:s,message:N(n),name:"Mito.log",customTag:N(i),time:I(),url:w()},l),h=this.breadcrumb.push({type:"Customer",category:j("Customer"),data:n,level:A.fromString(s.toString())});this.transport.send(f,h)},e}(X);function V(t,e,n,o){return void 0===n&&(n=A.Info),void 0===o&&(o={}),this.breadcrumb.push(r({type:e,data:t,category:j(e),level:n},o))}var G={name:"xhr",monitor:function(t){z.call(this,t)},transform:function(t){return Q(t)},consumer:function(t){Y.call(this,t)}};function z(t){var e=this.options,n=this.transport;if("XMLHttpRequest"in g){var r=XMLHttpRequest.prototype;T(r,"open",(function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];this.httpCollect={request:{httpType:"xhr",method:f.isString(e[0])?e[0].toUpperCase():e[0],url:e[1]},response:{},time:I()},t.apply(this,e)}})),T(r,"send",(function(r){return function(){for(var o=this,i=[],a=0;a<arguments.length;a++)i[a]=arguments[a];var s=this.httpCollect.request,c=s.method,u=s.url;e.setTraceId(u,(function(t,e){s.traceId=e,o.setRequestHeader(t,e)})),e.beforeAppAjaxSend&&e.beforeAppAjaxSend({method:c,url:u},this),k(this,"loadend",(function(){if(!(n.isSelfDsn(u)||e.isFilterHttpUrl(u))){var r=this.responseType,o=this.response,a=this.status;s.data=i[0];var c=I();-1!==["","json","text"].indexOf(r)&&(this.httpCollect.response.data="object"==typeof o?JSON.stringify(o):o),this.httpCollect.response.status=a,this.httpCollect.elapsedTime=c-this.httpCollect.time,t("xhr",this.httpCollect)}})),r.apply(this,i)}}))}}function Q(t){var e="",n=t.request,o=n.httpType,i=n.method,a=n.url,s=t.response.status,u=t.elapsedTime,l=o+"--"+i;return e="ok"===(e=0===s?u<=c.crossOriginThreshold?"http请求失败,失败原因:跨域限制或域名不存在":"http请求失败,失败原因:超时":function(t){if(t<400)return"ok";if(t>=400&&t<500)switch(t){case 401:return"unauthenticated";case 403:return"permission_denied";case 404:return"not_found";case 409:return"already_exists";case 413:return"failed_precondition";case 429:return"resource_exhausted";default:return"invalid_argument"}if(t>=500&&t<600)switch(t){case 501:return"unimplemented";case 503:return"unavailable";case 504:return"deadline_exceeded";default:return"internal_error"}return"unknown_error"}(s))?e:e+" "+H(a),r(r({},t),{type:"HTTP",url:w(),level:A.Low,message:e,name:l})}function Y(t){var e="fetch"===t.request.httpType?"Fetch":"Xhr",n=t.response.status,r=t.time,o=0===n||400===n||n>401;if(V.call(this,t,e,A.Info,{time:r}),o){var i=this.breadcrumb.push({type:e,category:"exception",data:t,level:A.Error,time:r});this.transport.send(t,i)}}var Z={name:"fetch",monitor:function(t){tt.call(this,t)},transform:function(t){return Q(t)},consumer:function(t){Y.call(this,t)}};function tt(t){var e=this.options,n=this.transport;"fetch"in g&&T(g,"fetch",(function(o){return function(i,a){void 0===a&&(a={});var s=I(),c=a&&a.method||"GET",u={request:{httpType:"fetch",url:i,method:c,data:a&&a.body},time:s,response:{}},l=new Headers(a.headers||{});Object.assign(l,{setRequestHeader:l.set}),e.setTraceId(i,(function(t,e){u.request.traceId=e,l.set(t,e)})),e.beforeAppAjaxSend&&e.beforeAppAjaxSend({method:c,url:i},l),a=r(r({},a),{headers:l});var f=n.isSelfDsn(i)||e.isFilterHttpUrl(i);return o.apply(g,[i,a]).then((function(e){var n=e.clone(),r=I();return u.elapsedTime=r-s,u.response.status=n.status,n.text().then((function(e){f||(u.response.data=e,t("fetch",u))})),e}),(function(e){if(!f){var n=I();throw u.elapsedTime=n-s,u.response.status=0,t("fetch",u),e}}))}}))}var et={name:"dom",monitor:function(t){if("document"in g){var e,n,r,o=(e=t,n=this.options.throttleDelayTime,r=!0,function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];r&&(e.apply(this,t),r=!1,setTimeout((function(){r=!0}),n))});k(g.document,"click",(function(){o("dom",{category:"click",data:this})}),!0)}},transform:function(t){return function(t){var e=t.tagName.toLowerCase();if("body"===e)return null;var n=t.classList.value;return n=""!==n?' class="'+n+'"':"","<"+e+(t.id?' id="'+t.id+'"':"")+(""!==n?n:"")+">"+t.innerText+"</"+e+">"}(t.data.activeElement)},consumer:function(t){t&&V.call(this,t,"UI.Click")}},nt={name:"error",monitor:function(t){k(g,"error",(function(e){t("error",e)}),!0)},transform:function(t){return t.target.localName?function(t){return{type:"RESOURCE",url:w(),message:"资源地址: "+(R(t.src,120)||R(t.href,120)),level:A.Low,time:I(),name:(rt[t.localName]||t.localName)+"加载失败"}}(t.target):function(t){var e,n=t.message,r=t.filename,o=t.lineno,i=t.colno,a=t.error;a&&p(a)&&(e=_(a,A.Normal));return e||(e=function(t,e,n,r){var o="UNKNOWN",i=e||w(),a=t,c=t.match(s);c[1]&&(o=c[1],a=c[2]);var u={url:i,func:"UNKNOWN_FUNCTION",args:"UNKNOWN",line:n,col:r};return{url:i,name:o,message:a,level:A.Normal,time:I(),stack:[u]}}(n,r,o,i)),e.type="JAVASCRIPT",e}(t)},consumer:function(t){var e="RESOURCE"===t.type?"Resource":"Code Error",n=V.call(this,t,e,A.Error);this.transport.send(t,n)}},rt={img:"图片",script:"JS脚本"};var ot={name:"hashchange",monitor:function(t){var e,n;e=g,n="onpopstate",Object.prototype.hasOwnProperty.call(e,n)||k(g,"hashchange",(function(e){var n=e.oldURL,r=e.newURL;t("hashchange",{from:n,to:r})}))},transform:function(t){return it(t)},consumer:function(t){at.call(this,t)}};function it(t){var e=t.from,n=t.to,r=C(e).relative,o=C(n).relative;return{from:r||"/",to:o||"/"}}function at(t){t.from!==t.to&&V.call(this,t,"Route")}var st={name:"history",monitor:function(t){var e;if(n=g.chrome,r=n&&n.app&&n.app.runtime,o="history"in g&&!!g.history.pushState&&!!g.history.replaceState,!r&&o){var n,r,o,i=g.onpopstate;g.onpopstate=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o=w(),a=e;e=o,t("history",{from:a,to:o}),i&&i.apply(this,n)},T(g.history,"pushState",a),T(g.history,"replaceState",a)}function a(n){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];var i=r.length>2?r[2]:void 0;if(i){var a=e,s=String(i);e=s,t("history",{from:a,to:s})}return n.apply(this,r)}}},transform:function(t){return it(t)},consumer:function(t){at.call(this,t)}},ct={name:"console",monitor:function(t){if("console"in g){["log","debug","info","warn","error","assert"].forEach((function(e){e in g.console&&T(g.console,e,(function(n){return function(){for(var r=[],o=0;o<arguments.length;o++)r[o]=arguments[o];n&&(t("console",{args:r,level:e}),n.apply(g.console,r))}}))}))}},transform:function(t){return t},consumer:function(t){c.isLogAddBreadcrumb&&V.call(this,t,"Console",A.fromString(t.level))}},ut="unhandledrejection",lt={name:ut,monitor:function(t){k(g,ut,(function(e){t(ut,e)}))},transform:function(t){console.log("collectedData",t);var e={type:"PROMISE",message:N(t.reason),url:w(),name:t.type,time:I(),level:A.Low};return p(t.reason)&&(e=r(r({},e),_(t.reason,A.Low))),e},consumer:function(t){var e=V.call(this,t,"Unhandledrejection",A.Error);this.transport.send(t,e)}};function ft(t,e){void 0===t&&(t={}),void 0===e&&(e=[]);var n=new K(t),r=[Z,G,et,nt,ot,st,ct,lt];return n.use(a(a([],r,!0),e,!0)),n}var pt=ft;return t.BrowserClient=K,t.createBrowserInstance=ft,t.init=pt,Object.defineProperty(t,"__esModule",{value:!0}),t}({});