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.
10 lines
54 KiB
10 lines
54 KiB
/**
|
|
* ================================================================
|
|
* aegis-mp-sdk@1.38.4 (c) 2023 TencentCloud Real User Monitoring.
|
|
* Author pumpkincai.
|
|
* Last Release Time Mon Oct 30 2023 20:32:22 GMT+0800 (中国标准时间).
|
|
* Released under the MIT License.
|
|
* Thanks for supporting RUM & Aegis!
|
|
* ================================================================
|
|
**/
|
|
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Aegis=t()}(this,function(){"use strict";var j=function(e,t){return(j=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}))(e,t)};function e(e,t){function n(){this.constructor=e}j(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var p=function(){return(p=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 _(r,o){var i,a,s,c={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]},e={next:t(0),throw:t(1),return:t(2)};return"function"==typeof Symbol&&(e[Symbol.iterator]=function(){return this}),e;function t(n){return function(e){var t=[n,e];if(i)throw new TypeError("Generator is already executing.");for(;c;)try{if(i=1,a&&(s=2&t[0]?a.return:t[0]?a.throw||((s=a.return)&&s.call(a),0):a.next)&&!(s=s.call(a,t[1])).done)return s;switch(a=0,(t=s?[2&t[0],s.value]:t)[0]){case 0:case 1:s=t;break;case 4:return c.label++,{value:t[1],done:!1};case 5:c.label++,a=t[1],t=[0];continue;case 7:t=c.ops.pop(),c.trys.pop();continue;default:if(!((s=0<(s=c.trys).length&&s[s.length-1])||6!==t[0]&&2!==t[0])){c=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))c.label=t[1];else if(6===t[0]&&c.label<s[1])c.label=s[1],s=t;else{if(!(s&&c.label<s[2])){s[2]&&c.ops.pop(),c.trys.pop();continue}c.label=s[2],c.ops.push(t)}}t=o.call(r,c)}catch(e){t=[6,e],a=0}finally{i=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function H(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),o=0,t=0;t<n;t++)for(var i=arguments[t],a=0,s=i.length;a<s;a++,o++)r[o]=i[a];return r}Object.assign||Object.defineProperty(Object,"assign",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n<arguments.length;n++)if(null!=(r=arguments[n]))for(var r=Object(r),o=Object.keys(Object(r)),i=0,a=o.length;i<a;i++){var s=o[i],c=Object.getOwnPropertyDescriptor(r,s);null!=c&&c.enumerable&&(t[s]=r[s])}return t}});var M=/_?t(\d)?(imestamp)?=\d+&?/g,D=["aegis.qq.com","tamaegis.com","/aegis-sdk","rumt-","/flog.core.min.js","pingfore.qq.com","pingfore.tencent.com","zhiyan.tencent-cloud.net","h.trace.qq.com","btrace.qq.com","beacon.qq.com","dmplog.qq.com","qq.com/report","svibeacon.onezapp.com","cube.weixinbridge.com","doubleclick.net","pcmgrmonitor.3g.qq.com","tdm.qq.com","report.qqweb.qq.com","tpstelemetry.tencent.com","insight.cloud.tencent.com","facebook.com","facebook.net","google","yahoo.com","twitter.com","ga-audiences","report.idqqimg.com","arms-retcode.aliyuncs.com","px.effirst.com","sentry","baidu.com","hot-update.json","u.c.b.r.o.w.s.e.r","report.url.cn","sockjs-node","m3u8"],F=["ext1","ext2","ext3","level","trace","tag","seq","code"],B=(r.prototype.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n].callback===t)return n;return-1},r.prototype.on=function(e,t,n){var r;if(void 0===n&&(n=0),this)return(r=this.eventsList[e])||(this.eventsList[e]=[],r=this.eventsList[e]),-1===this.indexOf(r,t)&&r.push({name:e,type:n||0,callback:t}),this},r.prototype.one=function(e,t){this.on(e,t,1)},r.prototype.remove=function(e,t){if(this){var n=this.eventsList[e];if(n){if(t)return n.length&&(t=this.indexOf(n,t),n.splice(t,1)),this;try{delete this.eventsList[e]}catch(e){}}return null}},r.prototype.clear=function(){this.eventsList={}},r),t={generateTraceId:W(16),generateSpanId:W(8)},n=Array(32);function r(){var a=this;this.emit=function(e,t){if(a){var n;if(null!=(r=a.eventsList[e])&&r.length)for(var r=r.slice(),o=0;o<r.length;o++){n=r[o];try{var i=n.callback.apply(a,[t]);if(1===n.type&&a.remove(e,n.callback),!1===i)break}catch(e){throw e}}return a}},this.eventsList={}}function W(t){return function(){for(var e=0;e<2*t;e++)n[e]=Math.floor(16*Math.random())+48,58<=n[e]&&(n[e]+=39);return String.fromCharCode.apply(null,n.slice(0,2*t))}}function V(){return([1e7]+1e3+4e3+8e3+1e11).replace(/[018]/g,function(e){return(e^(16*Math.random()&15)>>e/4).toString(16)})}function G(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function J(e){for(var t,n,r,o="",i=0,a=(e=String(e)).length%3;i<e.length;){if(255<(t=e.charCodeAt(i++))||255<(n=e.charCodeAt(i++))||255<(r=e.charCodeAt(i++)))throw new TypeError("Failed to execute 'btoa': The string to be encoded contains characters outside of the Latin1 range.");o+=s.charAt((t=t<<16|n<<8|r)>>18&63)+s.charAt(t>>12&63)+s.charAt(t>>6&63)+s.charAt(63&t)}return a?o.slice(0,a-3)+"===".substring(a):o}function z(e){if(e=String(e).replace(/[\t\n\f\r ]+/g,""),!$.test(e))throw new TypeError("Failed to execute 'atob': The string to be decoded is not correctly encoded.");var t;e+="==".slice(2-(3&e.length));for(var n,r,o="",i=0;i<e.length;)t=s.indexOf(e.charAt(i++))<<18|s.indexOf(e.charAt(i++))<<12|(n=s.indexOf(e.charAt(i++)))<<6|(r=s.indexOf(e.charAt(i++))),o+=64===n?String.fromCharCode(t>>16&255):64===r?String.fromCharCode(t>>16&255,t>>8&255):String.fromCharCode(t>>16&255,t>>8&255,255&t);return o}function K(e){var t,n="";return n="object"==typeof e&&(t=(e=function(e,t){for(var n=0;n<t.length;n++){var r=t[n],o=e[r]||"function"==typeof e.get&&e.get(r);if(o)return[r,o]}return["",""]}(e,Object.keys(Y)))[0],e=e[1],t)?Y[t](e):n}var s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",$=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/,Z=(o.prototype.generate=function(e,t,n){if(void 0===t&&(t={}),this.url=e,!this.isUrlIgnored()&&this.isUrlInTraceUrls()&&this.traceType){switch(this.traceType){case"traceparent":this.traceId=this.createTraceparent();break;case"b3":this.traceId=this.createB3();break;case"sw8":this.traceId=this.createSw8(n);break;case"sentry-trace":this.traceId=this.createSentryTrace();break;default:return console.warn("this trace key "+this.traceType+" is not supported"),void(this.traceId="")}return t[this.traceType]&&(this.traceId=t[this.traceType]),{name:this.traceType,value:this.traceId}}},o.prototype.createTraceparent=function(){var e=t.generateSpanId();return"00-"+t.generateTraceId()+"-"+e+"-0"+Number(1).toString(16)},o.prototype.createB3=function(){var e=t.generateSpanId();return t.generateTraceId()+"-"+e+"-1"},o.prototype.createSw8=function(e){var t="function"==typeof btoa?btoa:J,e=e||{},n=e.host,n=void 0===n?"":n,e=e.pathname,e=void 0===e?"":e,r=G(),o=G();return"1-"+String(t(o))+"-"+String(t(r))+"-1-"+String(t("aegis"))+"-"+String(t("1.38.4"))+"-"+String(t(encodeURI(e)))+"-"+String(t(n))},o.prototype.createSentryTrace=function(){var e=V().substring(16);return V()+"-"+e+"-1"},o.prototype.isUrlIgnored=function(){if(Array.isArray(this.ignoreUrls)&&0!==this.ignoreUrls.length)for(var e=0,t=this.ignoreUrls;e<t.length;e++){var n=t[e];if(this.urlMatches(this.url,n))return!0}return!1},o.prototype.isUrlInTraceUrls=function(){if(!this.urls)return!0;if(Array.isArray(this.urls)){if(0===this.urls.length)return!1;for(var e=0,t=this.urls;e<t.length;e++){var n=t[e];if(this.urlMatches(this.url,n))return!0}}return!1},o.prototype.urlMatches=function(e,t){return"string"==typeof t?e===t:!!e.match(t)},o),Y={sw8:function(e){var t="function"==typeof atob?atob:z,e=e.split("-")[1];return e?t(e):""},traceparent:function(e){return e.split("-")[1]},b3:function(e){return e.split("-")[0]},"sentry-trace":function(e){return e.split("-")[0]}},Q=function(e){if(!e||0===e.length)return"{}";e=Array.isArray(e)?e:[e];var t=Object.keys(e[0]),n={},r=(t.forEach(function(t){n[t]=e.map(function(e){return e[t]})}),n.count=e.length,n);if("string"==typeof r)return r;try{return JSON.stringify(r,ve())||"undefined"}catch(r){return"error happen when aegis stringify: \n "+r.message+" \n "+r.stack}};function o(e,t,n){void 0===n&&(n=null),this.traceType=e,this.ignoreUrls=t,this.urls=n}function X(e,t){return"string"==typeof e?e.split("?")[t?1:0]||"":e}function ee(e){return"string"==typeof e&&/^\//.test(e)?"https:"===(null===location||void 0===location?void 0:location.protocol):/^https/.test(e)}function te(e,t,n){var r,o;try{if("function"==typeof(null==t?void 0:t.retCodeHandler))return{code:void 0===(i=(o=t.retCodeHandler(e,null==n?void 0:n.url,null==n?void 0:n.ctx,null==n?void 0:n.payload)||{}).code)?"unknown":i,isErr:o.isErr};if(!(e="string"==typeof e?JSON.parse(e):e))return{code:"unknown",isErr:!1};"function"==typeof(null==(r=null==t?void 0:t.ret)?void 0:r.join)&&(ye=[].concat(t.ret.map(function(e){return e.toLowerCase()})));var i,a=Object.getOwnPropertyNames(e).filter(function(e){return-1!==ye.indexOf(e.toLowerCase())});return a.length?{code:""+(i="未知"!==(i=e[a[0]])&&""!==i?i:"unknown"),isErr:0!==i&&"0"!==i&&"unknown"!==i}:{code:"unknown",isErr:!1}}catch(e){return{code:"unknown",isErr:!1}}}function d(e,t,n){try{var r="function"==typeof t?t(e,null==n?void 0:n.url)||"":e;return be(r).slice(0,102400)}catch(e){return""}}function h(t,e){return"string"!=typeof t||!t||e&&-1<t.indexOf(e)||Re.test(t)||D.some(function(e){return-1<t.indexOf(e)})}function m(n,r){var o,i=[],a=n.config;return n.lifeCycle.on("destroy",function(){i.length=0}),function(e,t){Array.isArray(e)?i=i.concat(e):i.push(e),r&&i.length>=r||n.sendNow&&0<i.length?(i=we(i),t(i.splice(0,i.length)),o&&clearTimeout(o)):(o&&clearTimeout(o),o=setTimeout(function(){o=null,0<(i=we(i)).length&&t(i.splice(0,i.length))},a.delay))}}function ne(e,t){return Array.isArray(e)?t(e.map(function(e){return t=p(p({},e),{msg:"string"==typeof e.msg?e.msg:[].concat(e.msg).map(E).join(" ")}),F.forEach(function(e){t[e]||delete t[e]}),t;var t})):t([p(p({},e),{msg:"string"==typeof e.msg?e.msg:E(e.msg)})])}function re(c,l){return function(e,t){var n,r,o,i=Array.isArray(e),a=i?e:[e],s=(c.lifeCycle.emit("beforeRequest",e),c.config.beforeRequest);(a="function"==typeof s?a.map(function(t){try{var e=s({logs:t,logType:l});return(null==e?void 0:e.logType)===l&&null!=e&&e.logs?e.logs:!1!==e&&t}catch(e){return t}}).filter(function(e){return!1!==e}):a).length&&(n=a,e=F,!Array.isArray(n)||n.length<=1||(r=[],o=[],!(o="string"==typeof e?[e]:e))||o.length<=0||(o.forEach(function(t){n.forEach(function(e){null!=e&&e[t]&&r.push(t)})}),0<r.length&&(n=n.map(function(e){var t={};return r.forEach(function(e){t[e]=""}),p(p({},t),e)}))),a=n,t(i?a:a[0]))}}function oe(o){return function(e,t){o.lifeCycle.emit("modifyRequest",e);var n=o.config.modifyRequest;if("function"==typeof n)try{var r=n(e);"object"==typeof r&&"url"in r&&(e=r)}catch(e){console.error(e)}t(e)}}function ie(r){return function(e,t){null!=(n=r.lifeCycle)&&n.emit("afterRequest",e);var n=(r.config||{}).afterRequest;"function"==typeof n&&!1===n(e)||t(e)}}function y(n){if(n&&n.reduce&&n.length)return 1===n.length?function(e,t){n[0](e,t||ke)}:n.reduce(function(n,r){return function(e,t){return void 0===t&&(t=ke),n(e,function(e){return null==r?void 0:r(e,t)})}});throw new TypeError("createPipeline need at least one function param")}function ae(t,n){Object.getOwnPropertyNames(t).forEach(function(e){"function"==typeof t[e]&&"constructor"!==e&&(n?n[e]="sendPipeline"===e?function(){return function(){}}:function(){}:t[e]=function(){})})}function se(e){try{var t,n,r,o="";return o=e.pageUrl||(n=(t=getCurrentPages())[t.length-1]||{},i=n.options,r=Object.keys(i).length?"?"+Object.keys(i).map(function(e){return e+"="+i[e]}).join("&"):"",n.route?n.route+r:""),(o="function"==typeof e.urlHandler?e.urlHandler():o).slice(0,2048)}catch(e){return""}var i}function ce(e,t){if("string"==typeof e&&"string"==typeof t){if(e===t)return 1;for(var n=e.split("."),r=t.split("."),o=Math.max(n.length,r.length),i=0;i<o;i++){var a=~~n[i],s=~~r[i];if(a<s)return;if(s<a)return 1}}}function le(e,t){var n=this;this.taskQueue=[],this.count=1,this.maxCount=2,this.addTask=function(e){n.taskQueue.push(e)},this.fireTask=function(){var e=n.taskQueue.length;n.count>n.maxCount||0===e||(n.count=n.count+1,(e=n.taskQueue.shift())&&n.sendRequest(e.options,null==e?void 0:e.success,null==e?void 0:e.fail))},this.complete=function(){1<n.count&&(n.count=n.count-1),n.fireTask()},t&&(this.maxCount=t),this.sendRequest=e}function i(e){return Ce=Ce||g.getSystemInfoSync().SDKVersion,ce(Ce,"1.1.1")&&g.canIUse?g.canIUse(e):!!g[e]}function ue(e){for(var t,n={unknown:/unknown|none/i,wifi:/wifi/i,net2g:/2g/i,net3g:/3g/i,net4g:/4g/i,net5g:/5g/i,net6g:/6g/i},r=c.unknown,o=0;o<Object.keys(n).length;o++){var i=Object.keys(n)[o];if(null!=(t=n[i])&&t.test(e)){r=c[i];break}}return r}function fe(e){var t=e.apiName,n=S[t];n?n.hackCloudReq.addCallback(e):(n=x.cloud[t],S[t]={hackCloudReq:new qe(e),originApi:n}),S[t]}function pe(e){var t=e.apiName,n=T[t];n?n.hackReq.addCallback(e):(n=wx[t],T[t]={hackReq:new Ie(e),originApi:n}),T[t]}var v,a,c,b,u,de,he,ge,me,ye=["ret","retcode","code","errcode"],ve=function(){var n=new WeakSet;return function(e,t){if(t instanceof Error)return"Error.message: "+t.message+" \n Error.stack: "+t.stack;if("object"==typeof t&&null!==t){if(n.has(t))return"[Circular "+(e||"root")+"]";n.add(t)}return t}},E=function(e){if("string"==typeof e)return e;try{return e instanceof Error?(JSON.stringify(e,ve(),4)||"undefined").replace(/"/gim,""):JSON.stringify(e,ve(),4)||"undefined"}catch(e){return"error happen when aegis stringify: \n "+e.message+" \n "+e.stack}},be=function(n,r){void 0===r&&(r=3);var o,i,a,s="";return Array.isArray(n)?(s+="[",o=n.length,n.forEach(function(e,t){s=(s+="object"==typeof e&&1<r?be(e,r-1):Oe(e))+(t===o-1?"":",")}),s+="]"):n instanceof Object?(s="{",i=Object.keys(n),a=i.length,i.forEach(function(e,t){"object"==typeof n[e]&&1<r?s+='"'+e+'":'+be(n[e],r-1):s+=Ee(e,n[e]),s+=t===a-1||t<a-1&&void 0===n[i[t+1]]?"":","}),s+="}"):s+=n,s},Ee=function(e,t){var n=typeof t,r="";return"string"==n||"object"==n?r+='"'+e+'":"'+t+'"':"function"==typeof t?r+='"'+e+'":"function '+t.name+'"':"symbol"==typeof t?r+='"'+e+'":"symbol"':"number"!=typeof t&&"boolean"!=n||(r+='"'+e+'": '+t),r},Oe=function(e){var t=typeof e;return""+("undefined"==t||"symbol"==t||"function"==t?"null":"string"==t||"object"==t?'"'+e+'"':e)},Re=/data:(image|text|application|font)\/.*;base64/,we=((l=v=v||{}).INFO_ALL="-1",l.API_RESPONSE="1",l.INFO="2",l.ERROR="4",l.PROMISE_ERROR="8",l.AJAX_ERROR="16",l.SCRIPT_ERROR="32",l.IMAGE_ERROR="64",l.CSS_ERROR="128",l.CONSOLE_ERROR="256",l.MEDIA_ERROR="512",l.RET_ERROR="1024",l.REPORT="2048",l.PV="4096",l.EVENT="8192",l.PAGE_NOT_FOUND_ERROR="16384",l.WEBSOCKET_ERROR="32768",l.BRIDGE_ERROR="65536",l.LAZY_LOAD_ERROR="131072",(l=a=a||{})[l.android=1]="android",l[l.ios=2]="ios",l[l.windows=3]="windows",l[l.macos=4]="macos",l[l.linux=5]="linux",l[l.devtools=6]="devtools",l[l.other=100]="other",(l=c=c||{})[l.unknown=100]="unknown",l[l.wifi=1]="wifi",l[l.net2g=2]="net2g",l[l.net3g=3]="net3g",l[l.net4g=4]="net4g",l[l.net5g=5]="net5g",l[l.net6g=6]="net6g",(l=b=b||{}).LOG="log",l.SPEED="speed",l.PERFORMANCE="performance",l.OFFLINE="offline",l.WHITE_LIST="whiteList",l.VITALS="vitals",l.PV="pv",l.CUSTOM_PV="customPV",l.EVENT="event",l.CUSTOM="custom",l.SDK_ERROR="sdkError",l.SET_DATA="setData",l.LOAD_PACKAGE="loadPackage",(l=u=u||{}).production="production",l.development="development",l.gray="gray",l.pre="pre",l.daily="daily",l.local="local",l.test="test",l.others="others",function(e){return e.filter(function(n,r){return"static"!==n.type||!e.find(function(e,t){return n.url===e.url&&200===n.status&&r<t})})}),xe=function(e){e.level===v.INFO_ALL&&(e.level=v.INFO)},O={},R={},Se=function(e){return O[e]||(O[e]=setTimeout(function(){R[e]={},O[e]=null},6e4)),O[e]},Te=function(e){return(Array.isArray(e)?e:[e]).map(function(n){return Object.getOwnPropertyNames(n).reduce(function(e,t){return"ctx"!==t&&(e[t]=n[t]),e},{level:v.INFO,msg:""})})},Pe=function(r){return function(e){return r.sendPipeline([function(e,n){return n({url:r.config.url||"",data:Q(Te(e)),method:"post",contentType:"application/json",type:b.LOG,log:e,requestConfig:{timeout:5e3},success:function(){var t=r.config.onReport;"function"==typeof t&&e.forEach(function(e){t(e)}),"function"==typeof n&&n([])}})}],b.LOG)(e)}},ke=function(){},l=(Object.defineProperty(A.prototype,"__version__",{get:function(){return console.warn("__version__ has discard, please use version"),"1.38.4"},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"LogType",{get:function(){return console.warn("LogType has discard, please use logType"),v},enumerable:!1,configurable:!0}),A.prototype.init=function(e){this.setConfig(e);for(var t=0;t<A.installedPlugins.length;t++)try{A.installedPlugins[t].patch(this)}catch(e){this.sendSDKError(e)}this.lifeCycle.emit("onInited")},A.prototype.setConfig=function(e){Object.assign(this.config,e);var e=this.config,t=e.id,n=e.uin,r=e.version,o=e.ext1,i=e.ext2,a=e.ext3,s=e.aid,c=e.env,l=void 0===c?"production":c,c=e.pageUrl,e=this.bean.id!==t||this.bean.uin!==n||this.bean.aid!==s;return this.bean.id=t||"",this.bean.uin=n||"",this.bean.version=r||"1.38.4",this.bean.aid=s||"",this.bean.env=function(){switch(l){case u.production:case u.development:case u.gray:case u.pre:case u.daily:case u.local:case u.test:case u.others:return 1;default:return}}()?l:u.others,c&&this.extendBean("from",encodeURIComponent(c.slice(0,2048))),o&&this.extendBean("ext1",encodeURIComponent(o)),i&&this.extendBean("ext2",encodeURIComponent(i)),a&&this.extendBean("ext3",encodeURIComponent(a)),e&&this.lifeCycle.emit("onConfigChange",this.config),this.config},A.use=function(e){-1===A.installedPlugins.indexOf(e)&&e.aegisPlugin&&A.installedPlugins.push(e)},A.unuse=function(e){e=A.installedPlugins.indexOf(e);-1!==e&&A.installedPlugins.splice(e,1)},A.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:v.INFO,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:v.INFO}),this.normalLogPipeline(n)},A.prototype.infoAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:v.INFO_ALL,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:v.INFO_ALL}),this.normalLogPipeline(n)},A.prototype.report=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:v.REPORT,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0])),this.normalLogPipeline(n)},A.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:v.ERROR,msg:e};1===e.length&&e[0].msg&&Object.assign(n,p({},e[0]),{level:v.ERROR}),this.normalLogPipeline(n)},A.prototype.speedLogPipeline=function(e){throw new Error('You need to override "speedLogPipeline" method')},A.prototype.reportPv=function(n){var r,o=this;n&&(console.warn("reportPv is deprecated, please use reportEvent"),r=""+Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+o.bean[e]}).join("&"),this.sendPipeline([function(e,t){t({url:o.config.url+"/"+n+"?"+r,addBean:!1,type:b.CUSTOM_PV})}],b.CUSTOM_PV)(null))},A.prototype.reportEvent=function(e){e&&((e="string"==typeof e?{name:e,ext1:this.config.ext1||"",ext2:this.config.ext2||"",ext3:this.config.ext3||""}:e).name?("string"!=typeof e.name&&(console.warn("reportEvent params name must be string"),e.name=String(e.name)),this.eventPipeline(e)):console.warn("reportEvent params error"))},A.prototype.reportTime=function(e,t){if("object"==typeof e)return this.reportT(e);"string"==typeof e?"number"==typeof t?t<0||6e4<t?console.warn("reportTime: duration must between 0 and 60000"):this.submitCustomTime(e,t):console.warn("reportTime: second param must be number"):console.warn("reportTime: first param must be a string")},A.prototype.reportT=function(e){var t=e.name,n=e.duration,r=e.ext1,r=void 0===r?"":r,o=e.ext2,o=void 0===o?"":o,i=e.ext3,i=void 0===i?"":i,e=e.from;if("string"==typeof t&&"number"==typeof n&&"string"==typeof r&&"string"==typeof o&&"string"==typeof i){if(!(n<0||6e4<n))return this.submitCustomTime(t,n,r,o,i,void 0===e?"":e);console.warn("reportTime: duration must between 0 and 60000")}else console.warn("reportTime: params error")},A.prototype.time=function(e){"string"==typeof e?this.timeMap[e]?console.warn("Timer "+e+" already exists"):this.timeMap[e]=Date.now():console.warn("time: first param must be a string")},A.prototype.timeEnd=function(e){"string"==typeof e?this.timeMap[e]?(this.submitCustomTime(e,Date.now()-this.timeMap[e]),delete this.timeMap[e]):console.warn("Timer "+e+" does not exist"):console.warn("timeEnd: first param must be a string")},A.prototype.submitCustomTime=function(e,t,n,r,o,i){this.customTimePipeline({name:e,duration:t,ext1:n||this.config.ext1,ext2:r||this.config.ext2,ext3:o||this.config.ext3,from:i||void 0})},A.prototype.extendBean=function(e,t){this.bean[e]=t},A.prototype.sendPipeline=function(e,t){var n,i=this;return y(H([function(e,t){if("number"!=typeof n.config.random&&(console.warn("random must in [0, 1], default is 1."),n.config.random=1),!n.isHidden||!n.isGetSample)if(n.isGetSample)n.isHidden||t(e);else{if(n.isGetSample=!0,Math.random()<n.config.random)return n.isHidden=!1,t(e);n.isHidden=!0}},re(n=this,t)],e,[oe(this),function(r,o){i.request(r,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=!1;-1<(""+e[i.failRequestCount=0]).indexOf("403 forbidden")&&(n=!0,i.destroy()),o({isErr:n,result:e,logType:null==r?void 0:r.type,logs:null==r?void 0:r.log}),null!=(n=null==r?void 0:r.success)&&n.call.apply(n,H([r],e))},function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];60<=++i.failRequestCount&&i.destroy(),-1<(""+t[0]).indexOf("403 forbidden")&&i.destroy(),o({isErr:!0,result:t,logType:null==r?void 0:r.type,logs:null==r?void 0:r.log}),null!=(e=null==r?void 0:r.fail)&&e.call.apply(e,H([r],t))})},ie(this)]))},A.prototype.send=function(e,o,i){var t=this;return y([oe(this),function(n,r){t.request(n,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r({isErr:!1,result:e,logType:n.type,logs:n.log}),null!=o&&o.apply(void 0,e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r({isErr:!0,result:e,logType:n.type,logs:n.log}),null!=i&&i.apply(void 0,e)})},ie(this)])(e)},A.prototype.ready=function(e,t,n){throw new Error('You need to override "ready" method')},A.prototype.request=function(e,t,n){throw new Error('You need to override "request" method')},A.prototype.sendSDKError=function(e){var n=this;this.sendPipeline([function(e,t){t({url:n.config.url+"?id=1085&msg[0]="+encodeURIComponent(E(e))+"&level[0]=2&from="+n.config.id+"&count=1&version="+n.config.id+"(1.38.4)",addBean:!1,method:"get",type:b.SDK_ERROR,log:e})}],b.SDK_ERROR)(e)},A.prototype.destroy=function(e){void 0===e&&(e=!1);var t,n,r=A.instances.indexOf(this);-1!==r&&A.instances.splice(r,1);for(var o=A.installedPlugins.length-1;0<=o;o--)try{A.installedPlugins[o].unpatch(this)}catch(e){this.sendSDKError(e)}if(this.lifeCycle.emit("destroy"),this.lifeCycle.clear(),e)t=this,n=Object.getOwnPropertyDescriptors(t),Object.keys(n).forEach(function(e){n[e].writable&&(t[e]=null)}),Object.setPrototypeOf(this,null);else{for(var i=this;i.constructor!==Object&&ae(i,this),i=Object.getPrototypeOf(i););0===A.instances.length&&(r=Object.getPrototypeOf(this).constructor,ae(r),ae(A))}},A.version="1.38.4",A.instances=[],A.logType=v,A.environment=u,A.installedPlugins=[],A),f=(L.prototype.patch=function(e){this.canUse(e)&&this.exist(e)&&(this.instances.push(e),this.triggerInit(e),this.triggerOnNewAegis(e))},L.prototype.unpatch=function(e){var t=this.instances.indexOf(e);-1!==t&&(this.instances.splice(t,1),0===this.instances.length)&&this.uninstall(e)},L.prototype.countInstance=function(){return this.instances.length},L.prototype.uninstall=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.destroy)&&t.apply(this,[e])},L.prototype.walk=function(n){var r=this;this.instances.forEach(function(e){var t=r.canUse(e);t&&n(e,t)})},L.prototype.canUse=function(e){e=this.getConfig(e);return!(!e||"object"!=typeof e)||!!e},L.prototype.getConfig=function(e){return null==(e=e.config)?void 0:e[this.name]},L.prototype.exist=function(e){return-1===this.instances.indexOf(e)},L.prototype.triggerInit=function(e){var t;this.inited||(this.inited=!0,null==(t=null==(t=this.option)?void 0:t.init))||t.call(this.option,this.getConfig(e))},L.prototype.triggerOnNewAegis=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.onNewAegis)&&t.call(this.option,e,this.getConfig(e))},L),g=wx||qq,Ce="",Ne=new f({name:"device",onNewAegis:function(t){return e=this,c=function(){return _(this,function(e){return this.setSystemInfo(t),this.setNetworkType(t),this.setNetworkChange(t),[2]})},new(s=(s=a=void 0)||Promise)(function(n,t){function r(e){try{i(c.next(e))}catch(e){t(e)}}function o(e){try{i(c.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?n(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(r,o)}i((c=c.apply(e,a||[])).next())});var e,a,s,c},setSystemInfo:function(a){var s=this;try{i("getSystemInfo")&&g.getSystemInfo({success:function(e){var t=e.platform,n=e.model,r=e.windowHeight,o=e.windowWidth,i=e.screenWidth,i=void 0===i?0:i,e=e.screenHeight,e=void 0===e?0:e;a.extendBean("platform",s.getPlatFormType(t)),a.extendBean("model",n),a.extendBean("vp",Math.round(o)+" * "+Math.round(r)),a.extendBean("sr",Math.round(i)+" * "+Math.round(e))}})}catch(a){}},getPlatFormType:function(e){for(var t,n={android:/android/i,ios:/ios/i,windows:/windows/i,macos:/mac/i,devtools:/devtools/i},r=a.other,o=0;o<Object.keys(n).length;o++){var i=Object.keys(n)[o];if(null!=(t=n[i])&&t.test(e)){r=a[i];break}}return r},setNetworkChange:function(t){i("onNetworkStatusChange")&&g.onNetworkStatusChange(function(e){e=ue(e.networkType);t.extendBean("netType",e)})},setNetworkType:function(t){i("getNetworkType")&&g.getNetworkType({success:function(e){e=ue(e.networkType);t.extendBean("netType",e)}})}}),Le=g.request,l=(e(N,ge=l),Object.defineProperty(N.prototype,"getBean",{get:function(){var t=this;return this.bean?Object.getOwnPropertyNames(this.bean).map(function(e){return e+"="+t.bean[e]}).join("&")+"&from="+encodeURIComponent(se(this.config)):"from="+encodeURIComponent(se(this.config))},enumerable:!1,configurable:!0}),N.prototype.initRequestSchedule=function(){this.requestSchedule=new le(this.sendRequest)},N.prototype.uploadLogs=function(e,t){this.lifeCycle.emit("uploadLogs",e=void 0===e?{}:e,t=void 0===t?{}:t)},N.prototype.reportPv=function(e){var t,n=this;e&&(t=Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+n.bean[e]}).join("&")+"&from="+encodeURIComponent(se(this.config)),this.send({url:this.config.url+"/"+e+"?"+t,addBean:!1,type:b.CUSTOM_PV,log:b.CUSTOM_PV},function(){},function(){}))},N.sessionID="session-"+Date.now(),N.asyncPluginIndex=0,N),Ae=new f({name:"aid",onNewAegis:function(t){this.initAid(function(e){t.bean.aid=e,t.config.aid=e})},initAid:function(t){g.getStorage({key:"AEGIS_ID",success:function(e){t(e.data)},fail:function(){var e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)});g.setStorage({key:"AEGIS_ID",data:e,success:function(){t(e)}})}})}}),w=(C.prototype.addCallback=function(e){e&&this.callbacks.push(e)},C.prototype.prefixHandler=function(e){return p(p({},e),{aegisRequestStartTime:+new Date})},C.prototype.onStartHandler=function(n){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.onStart)&&t.call(e,n)}catch(e){}}),null!=(e=n.onStart)&&e.call(n,n)},C.prototype.successHandler=function(n,r){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.success)&&t.call(e,n,r)}catch(e){}}),null!=(e=r.success)&&e.call(r,n,r)},C.prototype.failHandler=function(n,r){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.fail)&&t.call(e,n,r)}catch(e){}}),null!=(e=r.fail)&&e.call(r,n,r)},C.prototype.completeHandler=function(n,r){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.complete)&&t.call(e,n,r)}catch(e){}}),null!=(e=r.complete)&&e.call(r,n,r)},C.prototype.override=function(){try{this.defineApiProperty()}catch(e){console.warn("cannot override `"+this.apiName+"`, error is: "+e)}finally{this.isOverride=!0}},C),x=wx||qq,S={},qe=(e(k,he=w),k.prototype.defineApiProperty=function(){var e=this;x.cloud&&x.cloud[this.apiName]&&Object.defineProperty(x.cloud,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},k.prototype.hackHandler=function(e){var r=this,o=this.prefixHandler(e);return new Promise(function(t,n){var e=null==(e=S[r.apiName])?void 0:e.originApi;null!=e&&e(p(p({},o),{success:function(e){r.successHandler(e,o),t(e)},fail:function(e){r.failHandler(e,o),n(e)},complete:function(e){r.completeHandler(e,o)}}))})},k),Ue=wx||qq,T={},Ie=(e(P,de=w),P.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(Ue,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},P.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=(this.onStartHandler(n),null==(e=T[this.apiName])?void 0:e.originApi);return null==e?void 0:e(p(p({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))},P),je=wx||qq,_e=je.request;function P(){return null!==de&&de.apply(this,arguments)||this}function k(){return null!==he&&he.apply(this,arguments)||this}function C(e){this.callbacks=[],this.isOverride=!1;var t=e.apiName;this.apiName=t,this.isOverride||this.override(),this.callbacks.push(e)}function N(e){var r,a,u=ge.call(this,e)||this;u.originRequest=Le,u.speedLogPipeline=y([(a=u.config,function(e,t){var n,r,o,i="number"==typeof a.repeat?a.repeat:60;!a.speedSample||i<=0?t(e):(n=(null==a?void 0:a.id)||"0",r=R[n]||{},Array.isArray(e)?(o=e.filter(function(e){var t=!r[e.url]||r[e.url]<i;return t?(r[e.url]=1+~~r[e.url],R[n]=r):O[n]||Se(n),t})).length&&t(o):!r[e.url]||r[e.url]<i?(r[e.url]=1+~~r[e.url],R[n]=r,t(e)):O[n]||Se(n))}),m(u),function(t,n){i("getNetworkType")?g.getNetworkType({success:function(e){e=ue(e.networkType);r.extendBean("netType",e),n(t)}}):n(t)},function(e,t){u.lifeCycle.emit("beforeReportSpeed",e);var n=u.config.beforeReportSpeed;if((e="function"==typeof n?e.filter(function(e){return!1!==n(e)}):e).length)return t(e)},re(r=u,b.SPEED),function(e,t){t(e.map(function(e){return void 0!==e.payload&&delete e.payload,e}))},function(e){var t,n,r,o;u.send({url:""+u.config.speedUrl,method:"post",data:(e=e,t=u.bean,r={fetch:[],static:[],bridge:[]},o={},Array.isArray(e)?e.forEach(function(e){var t;null!=(t=r[e.type])&&t.push(e)}):null!=(n=r[e.type])&&n.push(e),o.payload=JSON.stringify(p({duration:r},t)),o)})}]),u.request=function(e,t,n){e.url&&u.bean.id&&(!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(String(u.bean.aid))||i("getNetworkType")&&void 0===u.bean.netType?u.requestSchedule.addTask({options:e,success:t,fail:n}):(u.requestSchedule.addTask({options:e,success:t,fail:n}),u.requestSchedule.fireTask()))},u.sendRequest=function(e,t,n){var r,o,i,a=e.url,s=(u.config.whiteListUrl===a&&(r=t,t=function(e){null!=r&&r(JSON.stringify(e.data))}),e.method),s=void 0===s?"get":s,c=(!1!==e.addBean&&(a=a+(-1===(null==a?void 0:a.indexOf("?"))?"?":"&")+u.getBean),e),l=u.config.onBeforeRequest;return(c=l?l(e,u):c)&&c.url?(l=u.config.enableHttp2||!1,"get"===s?(s=a,o=c.data,a="string"!=typeof s?"":"object"==typeof o&&o?(i=Object.getOwnPropertyNames(o).map(function(e){var t=o[e];return e+"="+("string"==typeof t?encodeURIComponent(t):encodeURIComponent(JSON.stringify(t)))}).join("&").replace(/eval/gi,"evaI"),s+(-1===s.indexOf("?")?"?":"&")+i):s,u.originRequest(p({url:a,enableHttp2:l,success:t,fail:n,complete:u.requestSchedule.complete},e.requestConfig))):("string"==typeof c.data&&(c.data=c.data.replace(/eval/gi,"evaI")),u.originRequest(p({url:a,enableHttp2:l,header:c.contentType?{"content-type":c.contentType}:void 0,method:"POST",data:c.data,success:t,fail:n,complete:u.requestSchedule.complete},e.requestConfig))),!0):(i="",c&&c.url||(i="Sending request blocked. Please handle the parameters reasonably, options.url is necessary",console.log(i)),null!=n&&n(i),u.requestSchedule.complete(),!1)};try{u.initRequestSchedule(),u.init(e),u.extendBean("sessionId",N.sessionID),u.extendBean("referer",(i("getLaunchOptionsSync")?g.getLaunchOptionsSync():{scene:""}).scene||"")}catch(e){console.warn(e),console.log("%cThe above error occurred in the process of initializing Aegis, which will affect your normal use of Aegis.\nIt is recommended that you contact us for feedback and thank you for your support.","color: red"),u.sendSDKError(e)}return u}function L(e){this.aegisPlugin=!0,this.name="",this.instances=[],this.inited=!1,e.$walk=this.walk.bind(this),e.$getConfig=this.getConfig.bind(this),this.option=e,this.name=e.name}function A(e){var n,t,r,o,a,i,s,c,l,u,f,p,d,h,g=this;this.isGetSample=!1,this.isHidden=!1,this.config={version:0,delay:1e3,onError:!0,repeat:60,random:1,aid:!0,device:!0,pagePerformance:!0,webVitals:!0,speedSample:!0,onClose:!0,reportLoadPackageSpeed:!0,hostUrl:"https://aegis.qq.com",env:"production",url:"",offlineUrl:"",whiteListUrl:"",pvUrl:"",speedUrl:"",customTimeUrl:"",performanceUrl:"",performanceUrlForHippy:"",webVitalsUrl:"",eventUrl:"",setDataReportUrl:"",reportImmediately:!0},this.isWhiteList=!1,this.lifeCycle=new B,this.bean={},this.normalLogPipeline=y([m(this,5),ne,function(e,t){var r=n.config;t(e=e.map(function(e){var t,n=r.maxLength||102400;try{if(!e.msg||e.msg.length<=n)return e;e.msg=null==(t=e.msg)?void 0:t.substring(0,n)}catch(t){e.msg=E(e.msg).substring(0,r.maxLength)}return e}))},(h=(n=this).config,function(e,t){var n="number"==typeof h.repeat?h.repeat:60;if(n<=0)return t(e);var r=(null==h?void 0:h.id)+"_error",o=R[r]||{};t(e.filter(function(e){if(e.level===v.ERROR||e.level===v.PROMISE_ERROR||e.level===v.AJAX_ERROR||e.level===v.SCRIPT_ERROR||e.level===v.IMAGE_ERROR||e.level===v.CSS_ERROR||e.level===v.MEDIA_ERROR||e.level===v.RET_ERROR||e.level===v.BRIDGE_ERROR||e.level===v.PAGE_NOT_FOUND_ERROR||e.level===v.WEBSOCKET_ERROR||e.level===v.LAZY_LOAD_ERROR){e=e.msg.slice(0,200);if(o[e]>n)return O[r]||Se(r),!1;o[e]=1+~~o[e],R[r]=o}return!0}))}),(p=this.lifeCycle.emit,d=this.config,function(e,t){var n,r=d.logCreated;return"function"==typeof r?(n=e.filter(function(e){return!1!==r(e)}),p("beforeWrite",n),t(n)):(p("beforeWrite",e),t(e))}),(f=this,setTimeout(function(){var e=f.config,t=e.pvUrl,n=void 0===t?"":t,t=e.spa,e=-1<["web-sdk","mp-sdk"].indexOf("mp-sdk");n&&(e&&!t||!e)&&f.sendPipeline([function(e,t){t({url:n,type:b.PV})}],b.PV)(null)},100),function(e,t){t(e)}),(l=c=s=!1,u=[],(a=this).lifeCycle.on("onConfigChange",function(){i&&clearTimeout(i),i=setTimeout(function(){var e,n;!l&&a.config&&(l=!0,e=a.config.whiteListUrl,(n=void 0===e?"":e)&&a.sendPipeline([function(e,t){t({url:n,type:b.WHITE_LIST,success:function(e){c=!0;try{var t=e.data||JSON.parse(e),n=t.retcode,r=t.result,o=void 0===r?{}:r,i=(0===n&&(s=o.is_in_white_list,a.isWhiteList=s,0<=o.rate)&&o.rate<=1&&(a.config.random=o.rate,a.isGetSample=!1),a.isWhiteList&&u.length?Pe(a)(u.splice(0),function(){}):!a.isWhiteList&&u.length&&(u.length=0),a.config.onWhitelist);"function"==typeof i&&i(s)}catch(e){}},fail:function(){c=!0}})}],b.WHITE_LIST)(null),l=!1)},a.config.uin?50:500)}),a.lifeCycle.on("destroy",function(){u.length=0}),function(e,t){var n;s||null!=(n=null==(n=a.config)?void 0:n.api)&&n.reportRequest?t(e.concat(u.splice(0)).map(function(e){return xe(e),e})):(n=e.filter(function(e){return e.level!==v.INFO&&e.level!==v.API_RESPONSE?(xe(e),!0):(c||(u.push(e),200<=u.length&&(u.length=200)),!1)})).length&&t(n)}),function(e,t){try{var n=JSON.parse(JSON.stringify(e)),r=(g.lifeCycle.emit("beforeReport",n),g.config.beforeReport);(e="function"==typeof r?e.filter(function(e){return!1!==r(e)}):e).length&&t(e)}catch(e){}},Pe(this)]),this.eventPipeline=y([m(this,10),(o=this,function(e){o.sendPipeline([function(e,t){var n=e.map(function(e){return{name:e.name,ext1:e.ext1||o.config.ext1||"",ext2:e.ext2||o.config.ext2||"",ext3:e.ext3||o.config.ext3||""}});t({url:o.config.eventUrl+"?payload="+encodeURIComponent(JSON.stringify(n)),type:b.EVENT,log:e})}],b.EVENT)(e)})]),this.timeMap={},this.failRequestCount=0,this.customTimePipeline=y([m(this,10),(r=this,function(e){return r.sendPipeline([function(e,t){t({url:r.config.customTimeUrl+"?payload="+encodeURIComponent(JSON.stringify({custom:e})),type:b.CUSTOM,log:e})}],b.CUSTOM)(e)})]),this.config=(t=this.config,void 0===(e=e.hostUrl)&&(e="https://aegis.qq.com"),t.url=t.url||e+"/collect",t.offlineUrl=t.offlineUrl||e+"/offline",t.whiteListUrl=t.whiteListUrl||e+"/collect/whitelist",t.pvUrl=t.pvUrl||e+"/collect/pv",t.eventUrl=t.eventUrl||e+"/collect/events",t.speedUrl=t.speedUrl||e+"/speed",t.customTimeUrl=t.customTimeUrl||e+"/speed/custom",t.performanceUrl=t.performanceUrl||e+"/speed/performance",t.performanceUrlForHippy=t.performanceUrlForHippy||e+"/speed/hippyPerformance",t.webVitalsUrl=t.webVitalsUrl||e+"/speed/webvitals",t.setDataReportUrl=t.SetDataReportUrl||e+"/speed/miniProgramData",t),A.instances.push(this)}function He(){return null!==me&&me.apply(this,arguments)||this}e(He,me=w),He.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(je,"request",{get:function(){return e.hackHandler.bind(e)}})};function q(r,e,o){return null!=e&&e.length&&"object"==typeof r?e.reduce(function(e,t){var n=r[t];return n?e+(""===e?"\n":"\n\n")+o+" header "+t+": "+n:e},""):""}var U,Me,De=new f({name:"reportApiSpeed",override:!(He.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e);return this.onStartHandler(n),_e(p(p({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))}),onNewAegis:function(e){var t,n;this.override||(null!=(n=(e.config||{}).api)&&n.injectTraceHeader&&(this.traceRequestHeader=new Z(n.injectTraceHeader,null!=(t=null==n?void 0:n.injectTraceIgnoreUrls)?t:[],null==n?void 0:n.injectTraceUrls)),this.override=!0,this.hackRequest(e.config),this.overrideCallFunction(e.config),this.overrideCallContainer(e.config))},hackRequest:function(u){var f=this;pe({apiName:"request",onStart:function(e){var t=((null==u?void 0:u.api)||{}).injectTraceHeader,n=(e||{}).url;t&&(t={host:((t=/^(?:([A-Za-z]+):)?(\/{0,3})([0-9.\-A-Za-z]+)(?::(\d+))?(?:\/([^?#]*))?(?:\?([^#]*))?(?:#(.*))?$/.exec(t=n)||[])[1],t[2],[t[3],t[4],t[5]][0]),pathname:(t=getCurrentPages()).length?t[t.length-1].route:""},t=(n=f.traceRequestHeader.generate(n,{},{host:t.host,pathname:t.pathname})||{}).name,n=n.value,t)&&n&&e&&(e.header=p(p({},e.header),((e={})[t]=n,e)))},success:function(e,t){var n,r,o,i,a,s,c,l;h(t.url,u.hostUrl)||(n={method:t.method||"get",url:X(t.url),duration:Date.now()-t.aegisRequestStartTime,status:e.statusCode||0,nextHopProtocol:"",isHttps:ee(t.url),type:"fetch"},i=null==(i=u.api)?void 0:i.apiDetail,r=(o=te(e.data,u.api,{url:t.url,ctx:e,payload:t.data})||{}).code,o=o.isErr,l=i?d(t.data,null==(l=u.api)?void 0:l.reqParamHandler,{url:t.url}):"",i=i?d(e.data,null==(i=u.api)?void 0:i.resBodyHandler,{url:t.url}):"",a=(null==(a=u.api)?void 0:a.reqHeaders)||[],a=q(null==t?void 0:t.header,a,"req"),s=(null==(s=u.api)?void 0:s.resHeaders)||[],s=q(null==e?void 0:e.header,s,"res"),c=K(null==t?void 0:t.header),l="req url: "+n.url+" \n \nres status: "+(e.statusCode||0)+" \n \nres duration: "+n.duration+"ms \n \nreq method: "+n.method+" \n \nreq param: "+l+" \n \nres retcode: "+r+" \n \nres data: "+i+"\n "+a+"\n "+s,n.ret=r,n.isErr=+o,n.payload=t.data,f.publishNormalLog({msg:l,level:o?v.RET_ERROR:v.API_RESPONSE,ctx:e,trace:c}),f.publishSpeedLog(n))},fail:function(e,t){h(t.url,u.hostUrl)||(t={method:t.method||"get",url:X(t.url),duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",isHttps:ee(t.url),type:"fetch"},f.publishSpeedLog(t))}})},overrideCallFunction:function(n){var r=this;fe({apiName:"callFunction",success:function(e,t){r.cloudSuccessCallback(n,t,e,"callFunction")},fail:function(e,t){t={method:"call",url:"wx.cloud.callFunction."+t.name,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};r.publishSpeedLog(t)}})},overrideCallContainer:function(n){var r=this;fe({apiName:"callContainer",success:function(e,t){r.cloudSuccessCallback(n,t,e,"callContainer")},fail:function(e,t){t={method:"call",url:"wx.cloud.callContainer."+t.path,duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",type:"fetch",errMsg:e.errMsg,isHttps:!0};r.publishSpeedLog(t)}})},cloudSuccessCallback:function(e,n,t,r){var o="callFunction"===r?n.name:n.path,i="callFunction"===r?t.result:t.data,o={method:"call",url:"wx.cloud."+r+"."+o,duration:Date.now()-n.aegisRequestStartTime,status:200,nextHopProtocol:"",type:"fetch",isHttps:!0},a=["apiName","aegisRequestStartTime","config","success","fail","complete"],s=Object.keys(n).reduce(function(e,t){return a.includes(t)||(e[t]=n[t]),e},{}),r="callFunction"===r?(null==(r=t.data)?void 0:r.code)||0:t.statusCode,c=te(i,e.api,{url:o.url,ctx:t,payload:s})||{},l=c.code,c=c.isErr,c=void 0!==c&&c,l=(o.ret=l,o.isErr=+c,o.payload=s,null==(l=e.api)?void 0:l.apiDetail),s=l?d(s,null==(s=e.api)?void 0:s.reqParamHandler,{url:o.url}):"",i=l?d(i,null==(l=e.api)?void 0:l.resBodyHandler,{url:o.url}):"",l=(null==(l=e.api)?void 0:l.reqHeaders)||[],l=q(null==n?void 0:n.header,l,"req"),e=(null==(e=e.api)?void 0:e.resHeaders)||[],e=q(null==t?void 0:t.header,e,"res"),u=K(null==n?void 0:n.header),r="req url: "+o.url+"\n \nres status: "+r+"\n \nres duration: "+o.duration+"ms \n \nreq type: "+o.type+"\n \nreq params: "+s+"\n \nres retcode: "+o.ret+"\n \nres data: "+i+"\n "+l+"\n "+e;this.publishNormalLog({msg:r,level:c?v.RET_ERROR:v.API_RESPONSE,ctx:t,trace:u}),this.publishSpeedLog(o)},publishSpeedLog:function(t){this.$walk(function(e){e.speedLogPipeline(t)})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})}}),Fe=wx||qq,Be=Fe.connectSocket,We=(Ke.prototype.addConfig=function(e){var t=e.send,e=e.onError;t&&this.sends.push(t),e&&this.onErrors.push(e)},Ke.prototype.toHack=function(t){var o=this,n=(this.onErrors.forEach(function(e){t.onError(e)}),t.send);return Object.defineProperty(t,"send",{get:function(){return function(r){return new Promise(function(e){n.call(t,p(p({},r),{fail:function(n){o.sends.forEach(function(e){var t;null!=(t=e.fail)&&t.call(e,n,r)}),e(n)}}))})}}}),t},Ke),Ve=(e(I,Me=w),I.prototype.addTaskConf=function(e){this.taskHack.addConfig(e)},I.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(Fe,"connectSocket",{get:function(){return e.hackHandler.bind(e)}})},I.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=Be(p(p({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}));return this.taskHack.toHack(e),e},I),w=new f({name:"onError",onNewAegis:function(e){var t=g.getSystemInfoSync().SDKVersion;this.listenError(),this.hackNetWork(e),this.hackCloud(e),e.config.websocketHack&&ce(t,"1.7.0")&&this.hackWsConnect()},listenError:function(){var t=this;"function"==typeof g.onError&&g.onError(function(e){e&&t.publishErrorLog({msg:e,level:v.ERROR})}),i("onUnhandledRejection")&&g.onUnhandledRejection(function(e){e=e.reason;!e||-1<JSON.stringify(e).indexOf("request:fail")||t.publishErrorLog({msg:e,level:v.PROMISE_ERROR})}),i("onPageNotFound")&&g.onPageNotFound(function(e){e&&t.publishErrorLog({msg:e,level:v.PAGE_NOT_FOUND_ERROR})}),i("onLazyLoadError")&&g.onLazyLoadError(function(e){e&&t.publishErrorLog({msg:e,level:v.LAZY_LOAD_ERROR})})},publishErrorLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},hackNetWork:function(e){for(var n=this,r=e.config,t=0,o=[{apiName:"request",complete:function(e,t){return n.requestCompleteError(e,t,r)}},{apiName:"uploadFile",complete:function(e,t){return n.uploadFileCompleteError(e,t,r)}},{apiName:"downloadFile",complete:function(e,t){return n.downloadFileCompleteError(e,t,r)}}];t<o.length;t++){var i=o[t],a=i.apiName,i=i.complete;pe({apiName:a,complete:i})}},requestCompleteError:function(e,t,n){var r=e.errMsg,o=e.statusCode;h(t.url,n.hostUrl)||(r=this.getErrorType({errMsg:r,statusCode:o}))&&this.publishNetWorkError({apiName:"request",opts:t,res:e,config:n,type:r})},downloadFileCompleteError:function(e,t,n){var r=e.errMsg,o=e.statusCode,i=e.filePath,a=e.tempFilePath,r=this.getErrorType({errMsg:r,statusCode:o});r&&this.publishNetWorkError({apiName:"downloadFile",opts:t,res:e,config:n,type:r},{extraInfo:"\nres filePath: "+i+"\nres tempFilePath: "+a})},uploadFileCompleteError:function(e,t,n){var r=e.errMsg,o=e.statusCode,r=this.getErrorType({errMsg:r,statusCode:o});r&&this.publishNetWorkError({apiName:"uploadFile",opts:t,res:e,config:n,type:r})},hackCloud:function(e){for(var n=this,r=e.config,t=0,o=[{apiName:"callFunction",complete:function(e,t){return n.callFunctionCompleteError(e,t,r)}},{apiName:"callContainer",complete:function(e,t){return n.callContainerCompleteError(e,t,r)}}];t<o.length;t++){var i=o[t],a=i.apiName,i=i.complete;fe({apiName:a,complete:i})}},callFunctionCompleteError:function(e,t,n){var r=e.errMsg,r=this.getErrorType({errMsg:r});r&&this.publishNetWorkError({apiName:"cloud.callFunction",opts:t,res:e,config:n,type:r})},callContainerCompleteError:function(e,t,n){var r=e.errMsg,o=e.statusCode,r=this.getErrorType({errMsg:r,statusCode:o});r&&this.publishNetWorkError({apiName:"cloud.callContainer",opts:t,res:e,config:n,type:r})},publishNetWorkError:function(e,t){var t=(null==t?void 0:t.extraInfo)||"",n=e.apiName,r=e.opts,o=e.res,i=e.config,e=e.type,a=o.errMsg,s=o.statusCode,c=o.data,l=r.url,u=te(c,i.api,{url:l,ctx:o,payload:r.data}).code,f=null==(f=i.api)?void 0:f.apiDetail,p=f?d(r.data,null==(p=i.api)?void 0:p.reqParamHandler,{url:l}):"",c=f?d(c,null==(f=i.api)?void 0:f.resBodyHandler,{url:l}):"",l=(null==(f=i.api)?void 0:f.reqHeaders)||[],f=q(null==r?void 0:r.header,l,"req"),i=(null==(l=i.api)?void 0:l.resHeaders)||[],l=q(null==o?void 0:o.header,i,"res"),o=K(null==r?void 0:r.header);this.publishErrorLog({msg:"AJAX_ERROR: "+n+" "+e+"\n \nreq url: "+r.url+"\n \nres status: "+(s||0)+"\n \nres duration: "+(Date.now()-r.aegisRequestStartTime)+"ms\n \nreq method: "+(r.method||"get")+"\n \nreq param: "+p+"\n \nres retcode: "+u+"\n \nres data: "+c+"\n \nerrMsg: "+a.slice(0,1e3)+"\n "+t+"\n "+f+"\n "+l,level:v.AJAX_ERROR,trace:o})},getErrorType:function(e){var t=e.errMsg,e=e.statusCode,n="",r=t;return["timeout","time out","ERR_CONNECTION_TIMED_OUT","ERR_TIMED_OUT","超时"].some(function(e){return String(r||"").includes(e)})?n="timeout":400<=e?n="error":(-1<t.indexOf("fail")||!e||e<0)&&(n="failed"),n},hackWsConnect:function(){var e,t,n=this;pe({apiName:"sendSocketMessage",fail:function(e){n.publishSocketError(e)}}),e=(t={connectCallback:{fail:function(e){n.publishSocketError(e)}},taskOpt:{onError:function(e){n.publishSocketError(e)},send:{fail:function(e){n.publishSocketError(e)}}}}).connectCallback,t=t.taskOpt,U?U.addCallback(e):U=new Ve(e),t&&U.addTaskConf(t)},publishSocketError:function(e){e&&this.publishErrorLog({msg:e.errMsg,level:v.WEBSOCKET_ERROR})}}),Ge=new f({name:"reportAssetSpeed",isStart:!1,onNewAegis:function(e){this.isStart||(this.isStart=!0,this.start(e))},start:function(t){var e,n=this;g.getPerformance&&"function"==typeof(e=g.getPerformance()).createObserver&&e.createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){h(e.uri,t.config.hostUrl)||"number"!=typeof e.duration||e.duration<=0||n.publishAssetLog(e)})}).observe({entryTypes:["resource"]})},generateLog:function(e){var t,n,r=e.transferSize;return{url:(t=e.uri,void 0===n&&(n=2048),String(t).replace(M,"").slice(0,n)),method:"get",duration:Math.round(100*e.duration)/100,status:200,type:"static",isHttps:!0,urlQuery:X(e.uri,!0),nextHopProtocol:"",domainLookup:0,connectTime:0,transferSize:0<r?r:-1}},publishAssetLog:function(t){var n=this;this.$walk(function(e){e.speedLogPipeline(n.generateLog(t))})}}),Je=["onLaunch","onHide","onError","onLoad","onReady","onShow","onUnload"],ze=new f({name:"pagePerformance",pageNavigationStartTime:{},onNewAegis:function(e){try{i("getPerformance")&&this.reportPerformance(e),this.setPagePV(e),this.reportSetDataTiming(e)}catch(e){}},reportPerformance:function(f){var p=this,e=g.getPerformance();"function"==typeof e.createObserver&&null!=(e=null==e?void 0:e.createObserver(function(e){var t={},n=null==(n=e.getEntriesByName("appLaunch"))?void 0:n[0],r=null==(r=e.getEntriesByName("firstRender"))?void 0:r[0],o=null==(o=e.getEntriesByName("evaluateScript"))?void 0:o[0],i=null==(i=e.getEntriesByName("route"))?void 0:i[0],a=null==(a=null==(a=e.getEntriesByName("firstPaint"))?void 0:a[0])?void 0:a.startTime,s=null==(s=null==(s=e.getEntriesByName("largestContentfulPaint"))?void 0:s[0])?void 0:s.startTime,c=null==(c=null==(c=e.getEntriesByName("firstContentfulPaint"))?void 0:c[0])?void 0:c.startTime,l=null==(l=(null==(l=e.getEntriesByName("firstPaint"))?void 0:l[0])||(null==(l=e.getEntriesByName("route"))?void 0:l[0])||(null==(l=e.getEntriesByName("appLaunch"))?void 0:l[0]))?void 0:l.pageId,u=null==(e=(null==(u=e.getEntriesByName("route"))?void 0:u[0])||(null==(u=e.getEntriesByName("appLaunch"))?void 0:u[0]))?void 0:e.startTime;l&&(p.pageNavigationStartTime[l]=null,u)&&(p.pageNavigationStartTime[l]=u),n&&(t.appLaunch=n.duration||-1),r&&(t.firstScreenTiming=r.duration||-1),o&&(t.scriptEvaluateTiming=o.duration||-1),i&&(t.pageRouteTiming=i.duration||-1),a&&u?t.firstPaintTiming=Math.max(a-u,-1):a&&p.pageNavigationStartTime[l]&&(t.firstPaintTiming=Math.max(a-p.pageNavigationStartTime[l],-1)),s&&u?t.LCP=Math.max(s-u,-1):s&&p.pageNavigationStartTime[l]&&(t.LCP=Math.max(s-p.pageNavigationStartTime[l],-1)),c&&u?t.FCP=Math.max(c-u,-1):c&&p.pageNavigationStartTime[l]&&(t.FCP=Math.max(c-p.pageNavigationStartTime[l],-1)),0<Object.keys(t).length&&p.publish(t,f)}))&&e.observe({entryTypes:["navigation","render","script"]})},publish:function(t,n){var e,r,o,i=[],a=n.config,s=-1===(null==(e=n.config.performanceUrl)?void 0:e.indexOf("?"))?"?":"&";for(r in t)i.push(r+"="+t[r]);"function"==typeof a.urlHandler?(o=a.urlHandler()||window.location.href,this.$walk(function(e){e.send({url:n.config.performanceUrl+s+i.join("&")+"&from="+encodeURIComponent(o),beanFilter:["from"],type:b.PERFORMANCE,log:t})})):this.$walk(function(e){e.send({url:n.config.performanceUrl+s+i.join("&"),type:b.PERFORMANCE,log:t})})},setPagePV:function(t){var n=this;g.onAppRoute&&g.onAppRoute(function(e){"appLaunch"===e.openType&&!t.config.spa||(n.$walk(function(e){e.send({url:""+e.config.pvUrl,type:b.PV})}),n.reportPageLoaded(e))})},reportPageLoaded:function(e){e="infoType: behaviorBacktracking\ndataType: pageLoadAndRoute\npageLoadedPath: "+e.path+"\nopenType: "+e.openType;this.publishNormalLog({msg:e,level:v.INFO})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},reportSetDataTiming:function(t){var e,o,s,c,n,i,a,l,u=this,r=t.config.setDataReportConfig,r=void 0===r?{}:r;!0!==r.disabled&&(e=r.timeThreshold,o=!1!==r.withDataPaths,s=e&&0<+e?+e:30,c=y([m(t,10),function(e){e=e.map(function(e){return{type:b.SET_DATA,component:e.from,duration:e.duration,fields:e.dataPaths&&e.dataPaths.length?e.dataPaths.sort().join(";"):void 0,size:e.size}});t.send({url:t.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:e})),type:b.SET_DATA,log:e})}]),n=Page,i=Component,a=function(e,t){var i,a,n=t.updateStartTimestamp,r=t.updateEndTimestamp,t=t.dataPaths,t=void 0===t?[]:t,r=r-n;isNaN(r)||r<s||(n={from:e.is,duration:r},o&&0<t.length&&Object.assign(n,{dataPaths:t.slice(0,30),size:(r=t,a=0,null!=(i=e)&&i.data?(r.forEach(function(e){for(var t=i.data[e[0]],n=1,r=e.length;n<r;n++)t[e[n]]&&(t=t[e[n]]);var o="";try{o=JSON.stringify(t)}catch(e){o=""}a+=2*(void 0===o?"":o).replace(/[\u4e00-\u9fa5]/g,"aa").length}),a=Math.min(a,10485760)):a)}),c(n))},l=function(r){var e="infoType: behaviorBacktracking\ndataType: tapEvent"+Object.keys(r[0]).reduce(function(e,t){var n="";try{n=t+": "+JSON.stringify(r[0][t])}catch(e){n=""}return e+"\n"+n},"");u.publishNormalLog({msg:e,level:v.INFO})},Page=function(t){var e=t.onReady;return t.onReady=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){a(t,e)}),null==e?void 0:e.call(this)},Object.keys(t).forEach(function(e){var n;"function"!=typeof t[e]||Je.includes(e)||(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&l(e),null==n?void 0:n.apply(this,e)})}),n(t)},Component=function(e){e.lifetimes&&e.lifetimes.attached?(n=e.lifetimes.attached,e.lifetimes.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){a(t,e)}),null==n?void 0:n.call(this)}):(r=e.attached,e.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){a(t,e)}),null==r?void 0:r.call(this)});var n,r,t=e.methods;return t&&"[object Object]"===Object.prototype.toString.call(t)&&Object.keys(t).forEach(function(e){var n;"function"==typeof t[e]&&(n=t[e],t[e]=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return null!=e&&e[0]&&"tap"===e[0].type&&l(e),null==n?void 0:n.apply(this,e)})}),i(e)})}}),f=new f({name:"reportLoadPackageSpeed",isLoaded:!1,onNewAegis:function(e){this.isLoaded||(this.isLoaded=!0,this.start(e))},start:function(){var e,t=this;g.getPerformance&&"function"==typeof(e=g.getPerformance()).createObserver&&e.createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){"number"!=typeof e.duration||e.duration<=0||t.publishPackageLog(e)})}).observe({entryTypes:["loadPackage"]})},generateLog:function(e){return[{type:b.LOAD_PACKAGE,packageName:e.packageName,size:Math.round(100*e.packageSize)/100,duration:Math.round(100*e.duration)/100}]},publishPackageLog:function(n){var r=this;this.$walk(function(e){var t=r.generateLog(n);e.send({url:e.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:t})),type:b.LOAD_PACKAGE,log:t})})}});function I(e){e=Me.call(this,e)||this;return e.taskHack=new We,e}function Ke(){this.onErrors=[],this.sends=[]}return l.use(w),l.use(De),l.use(Ae),l.use(Ge),l.use(ze),l.use(f),l.use(Ne),l});
|
|
|