aegis.min.js 54 KB

12345678910
  1. /**
  2. * ================================================================
  3. * aegis-mp-sdk@1.37.5 (c) 2023 TencentCloud Real User Monitoring.
  4. * Author pumpkincai.
  5. * Last Release Time Mon Jun 26 2023 14:20:23 GMT+0800 (中国标准时间).
  6. * Released under the MIT License.
  7. * Thanks for supporting RUM & Aegis!
  8. * ================================================================
  9. **/
  10. !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 f=function(){return(f=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function H(i,o){var r,a,s,l={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(r)throw new TypeError("Generator is already executing.");for(;l;)try{if(r=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 l.label++,{value:t[1],done:!1};case 5:l.label++,a=t[1],t=[0];continue;case 7:t=l.ops.pop(),l.trys.pop();continue;default:if(!((s=0<(s=l.trys).length&&s[s.length-1])||6!==t[0]&&2!==t[0])){l=0;continue}if(3===t[0]&&(!s||t[1]>s[0]&&t[1]<s[3]))l.label=t[1];else if(6===t[0]&&l.label<s[1])l.label=s[1],s=t;else{if(!(s&&l.label<s[2])){s[2]&&l.ops.pop(),l.trys.pop();continue}l.label=s[2],l.ops.push(t)}}t=o.call(i,l)}catch(e){t=[6,e],a=0}finally{r=s=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function a(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var i=Array(e),o=0,t=0;t<n;t++)for(var r=arguments[t],a=0,s=r.length;a<s;a++,o++)i[o]=r[a];return i}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!=(i=arguments[n]))for(var i=Object(i),o=Object.keys(Object(i)),r=0,a=o.length;r<a;r++){var s=o[r],l=Object.getOwnPropertyDescriptor(i,s);null!=l&&l.enumerable&&(t[s]=i[s])}return t}});var I=/_?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","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","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"],M=(t.prototype.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n].callback===t)return n;return-1},t.prototype.on=function(e,t,n){var i;if(void 0===n&&(n=0),this)return(i=this.eventsList[e])||(this.eventsList[e]=[],i=this.eventsList[e]),-1===this.indexOf(i,t)&&i.push({name:e,type:n||0,callback:t}),this},t.prototype.one=function(e,t){this.on(e,t,1)},t.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}},t.prototype.clear=function(){this.eventsList={}},t),B=function(e){if(!e||0===e.length)return"{}";e=Array.isArray(e)?e:[e];var t=Object.keys(e[0]),n={},i=(t.forEach(function(t){n[t]=e.map(function(e){return e[t]})}),n.count=e.length,n);if("string"==typeof i)return i;try{return JSON.stringify(i,re())||"undefined"}catch(i){return"error happen when aegis stringify: \n "+i.message+" \n "+i.stack}};function t(){var a=this;this.emit=function(e,t){if(a){var n;if(null!=(i=a.eventsList[e])&&i.length)for(var i=i.slice(),o=0;o<i.length;o++){n=i[o];try{var r=n.callback.apply(a,[t]);if(1===n.type&&a.remove(e,n.callback),!1===r)break}catch(e){throw e}}return a}},this.eventsList={}}function p(e,t){return"string"==typeof e?e.split("?")[t?1:0]||"":e}function J(e){return"string"==typeof e&&/^\//.test(e)?"https:"===(null===location||void 0===location?void 0:location.protocol):/^https/.test(e)}function d(e,t,n){var i,o;try{if("function"==typeof(null==t?void 0:t.retCodeHandler))return{code:void 0===(r=(o=t.retCodeHandler(e,null==n?void 0:n.url,null==n?void 0:n.ctx,null==n?void 0:n.payload)||{}).code)?"unknown":r,isErr:o.isErr};if(!(e="string"==typeof e?JSON.parse(e):e))return{code:"unknown",isErr:!1};"function"==typeof(null==(i=null==t?void 0:t.ret)?void 0:i.join)&&(oe=[].concat(t.ret.map(function(e){return e.toLowerCase()})));var r,a=Object.getOwnPropertyNames(e).filter(function(e){return-1!==oe.indexOf(e.toLowerCase())});return a.length?{code:""+(r="未知"!==(r=e[a[0]])&&""!==r?r:"unknown"),isErr:0!==r&&"0"!==r&&"unknown"!==r}:{code:"unknown",isErr:!1}}catch(e){return{code:"unknown",isErr:!1}}}function h(e,t,n){try{var i="function"==typeof t?t(e,null==n?void 0:n.url)||"":e;return ae(i).slice(0,102400)}catch(e){return""}}function g(t,e){return"string"!=typeof t||!t||e&&-1<t.indexOf(e)||ue.test(t)||D.some(function(e){return-1<t.indexOf(e)})}function m(n,i){var o,r=[],a=n.config;return n.lifeCycle.on("destroy",function(){r.length=0}),function(e,t){Array.isArray(e)?r=r.concat(e):r.push(e),i&&r.length>=i||n.sendNow&&0<r.length?(r=ce(r),t(r.splice(0,r.length)),o&&clearTimeout(o)):(o&&clearTimeout(o),o=setTimeout(function(){o=null,0<(r=ce(r)).length&&t(r.splice(0,r.length))},a.delay))}}function V(e,t){return Array.isArray(e)?t(e.map(function(e){return t=f(f({},e),{msg:"string"==typeof e.msg?e.msg:[].concat(e.msg).map(O).join(" ")}),F.forEach(function(e){t[e]||delete t[e]}),t;var t})):t([f(f({},e),{msg:"string"==typeof e.msg?e.msg:O(e.msg)})])}function W(l,u){return function(e,t){var n,i,o,r=Array.isArray(e),a=r?e:[e],s=(l.lifeCycle.emit("beforeRequest",e),l.config.beforeRequest);(a="function"==typeof s?a.map(function(t){try{var e=s({logs:t,logType:u});return(null==e?void 0:e.logType)===u&&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||(i=[],o=[],!(o="string"==typeof e?[e]:e))||o.length<=0||(o.forEach(function(t){n.forEach(function(e){null!=e&&e[t]&&i.push(t)})}),0<i.length&&(n=n.map(function(e){var t={};return i.forEach(function(e){t[e]=""}),f(f({},t),e)}))),a=n,t(r?a:a[0]))}}function G(o){return function(e,t){o.lifeCycle.emit("modifyRequest",e);var n=o.config.modifyRequest;if("function"==typeof n)try{var i=n(e);"object"==typeof i&&"url"in i&&(e=i)}catch(e){console.error(e)}t(e)}}function K(i){return function(e,t){null!=(n=i.lifeCycle)&&n.emit("afterRequest",e);var n=(i.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||ge)}:n.reduce(function(n,i){return function(e,t){return void 0===t&&(t=ge),n(e,function(e){return null==i?void 0:i(e,t)})}});throw new TypeError("createPipeline need at least one function param")}function z(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 i(e){try{var t,n,i,o="";return o=e.pageUrl||(n=(t=getCurrentPages())[t.length-1]||{},r=n.options,i=Object.keys(r).length?"?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"):"",n.route?n.route+i:""),(o="function"==typeof e.urlHandler?e.urlHandler():o).slice(0,2048)}catch(e){return""}var r}function $(e,t){if("string"==typeof e&&"string"==typeof t){if(e===t)return 1;for(var n=e.split("."),i=t.split("."),o=Math.max(n.length,i.length),r=0;r<o;r++){var a=~~n[r],s=~~i[r];if(a<s)return;if(s<a)return 1}}}function X(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 o(e){return me=me||w.getSystemInfoSync().SDKVersion,$(me,"1.1.1")&&w.canIUse?w.canIUse(e):!!w[e]}function Y(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},i=l.unknown,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=l[r];break}}return i}function Q(e){var t=e.apiName,n=S[t];n?n.hackCloudReq.addCallback(e):(n=P.cloud[t],S[t]={hackCloudReq:new Re(e),originApi:n}),S[t]}function Z(e){var t=e.apiName,n=k[t];n?n.hackReq.addCallback(e):(n=wx[t],k[t]={hackReq:new Pe(e),originApi:n}),k[t]}var v,s,l,b,c,ee,te,ne,ie,oe=["ret","retcode","code","errcode"],re=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}},O=function(e){if("string"==typeof e)return e;try{return e instanceof Error?(JSON.stringify(e,re(),4)||"undefined").replace(/"/gim,""):JSON.stringify(e,re(),4)||"undefined"}catch(e){return"error happen when aegis stringify: \n "+e.message+" \n "+e.stack}},ae=function(n,i){void 0===i&&(i=3);var o,r,a,s="";return Array.isArray(n)?(s+="[",o=n.length,n.forEach(function(e,t){s=(s+="object"==typeof e&&1<i?ae(e,i-1):le(e))+(t===o-1?"":",")}),s+="]"):n instanceof Object?(s="{",r=Object.keys(n),a=r.length,r.forEach(function(e,t){"object"==typeof n[e]&&1<i?s+='"'+e+'":'+ae(n[e],i-1):s+=se(e,n[e]),s+=t===a-1||t<a-1&&void 0===n[r[t+1]]?"":","}),s+="}"):s+=n,s},se=function(e,t){var n=typeof t,i="";return"string"==n||"object"==n?i+='"'+e+'":"'+t+'"':"function"==typeof t?i+='"'+e+'":"function '+t.name+'"':"symbol"==typeof t?i+='"'+e+'":"symbol"':"number"!=typeof t&&"boolean"!=n||(i+='"'+e+'": '+t),i},le=function(e){var t=typeof e;return""+("undefined"==t||"symbol"==t||"function"==t?"null":"string"==t||"object"==t?'"'+e+'"':e)},ue=/data:(image|text|application|font)\/.*;base64/,ce=((n=v=v||{}).INFO_ALL="-1",n.API_RESPONSE="1",n.INFO="2",n.ERROR="4",n.PROMISE_ERROR="8",n.AJAX_ERROR="16",n.SCRIPT_ERROR="32",n.IMAGE_ERROR="64",n.CSS_ERROR="128",n.CONSOLE_ERROR="256",n.MEDIA_ERROR="512",n.RET_ERROR="1024",n.REPORT="2048",n.PV="4096",n.EVENT="8192",n.PAGE_NOT_FOUND_ERROR="16384",n.WEBSOCKET_ERROR="32768",n.BRIDGE_ERROR="65536",n.LAZY_LOAD_ERROR="131072",(n=s=s||{})[n.android=1]="android",n[n.ios=2]="ios",n[n.windows=3]="windows",n[n.macos=4]="macos",n[n.linux=5]="linux",n[n.devtools=6]="devtools",n[n.other=100]="other",(n=l=l||{})[n.unknown=100]="unknown",n[n.wifi=1]="wifi",n[n.net2g=2]="net2g",n[n.net3g=3]="net3g",n[n.net4g=4]="net4g",n[n.net5g=5]="net5g",n[n.net6g=6]="net6g",(n=b=b||{}).LOG="log",n.SPEED="speed",n.PERFORMANCE="performance",n.OFFLINE="offline",n.WHITE_LIST="whiteList",n.VITALS="vitals",n.PV="pv",n.CUSTOM_PV="customPV",n.EVENT="event",n.CUSTOM="custom",n.SDK_ERROR="sdkError",n.SET_DATA="setData",n.LOAD_PACKAGE="loadPackage",(n=c=c||{}).production="production",n.development="development",n.gray="gray",n.pre="pre",n.daily="daily",n.local="local",n.test="test",n.others="others",function(e){return e.filter(function(n,i){return"static"!==n.type||!e.find(function(e,t){return n.url===e.url&&200===n.status&&i<t})})}),fe=function(e){e.level===v.INFO_ALL&&(e.level=v.INFO)},E={},R={},pe=function(e){return E[e]||(E[e]=setTimeout(function(){R[e]={},E[e]=null},6e4)),E[e]},de=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:""})})},he=function(i){return function(e){return i.sendPipeline([function(e,n){return n({url:i.config.url||"",data:B(de(e)),method:"post",contentType:"application/json",type:b.LOG,log:e,requestConfig:{timeout:5e3},success:function(){var t=i.config.onReport;"function"==typeof t&&e.forEach(function(e){t(e)}),"function"==typeof n&&n([])}})}],b.LOG)(e)}},ge=function(){},n=(Object.defineProperty(q.prototype,"__version__",{get:function(){return console.warn("__version__ has discard, please use version"),"1.37.5"},enumerable:!1,configurable:!0}),Object.defineProperty(q.prototype,"LogType",{get:function(){return console.warn("LogType has discard, please use logType"),v},enumerable:!1,configurable:!0}),q.prototype.init=function(e){this.setConfig(e);for(var t=0;t<q.installedPlugins.length;t++)try{q.installedPlugins[t].patch(this)}catch(e){this.sendSDKError(e)}this.lifeCycle.emit("onInited")},q.prototype.setConfig=function(e){Object.assign(this.config,e);var e=this.config,t=e.id,n=e.uin,i=e.version,o=e.ext1,r=e.ext2,a=e.ext3,s=e.aid,l=e.env,u=void 0===l?"production":l,l=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=i||"1.37.5",this.bean.aid=s||"",this.bean.env=function(){switch(u){case c.production:case c.development:case c.gray:case c.pre:case c.daily:case c.local:case c.test:case c.others:return 1;default:return}}()?u:c.others,l&&this.extendBean("from",encodeURIComponent(l.slice(0,2048))),o&&this.extendBean("ext1",encodeURIComponent(o)),r&&this.extendBean("ext2",encodeURIComponent(r)),a&&this.extendBean("ext3",encodeURIComponent(a)),e&&this.lifeCycle.emit("onConfigChange",this.config),this.config},q.use=function(e){-1===q.installedPlugins.indexOf(e)&&e.aegisPlugin&&q.installedPlugins.push(e)},q.unuse=function(e){e=q.installedPlugins.indexOf(e);-1!==e&&q.installedPlugins.splice(e,1)},q.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,f({},e[0]),{level:v.INFO}),this.normalLogPipeline(n)},q.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,f({},e[0]),{level:v.INFO_ALL}),this.normalLogPipeline(n)},q.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,f({},e[0])),this.normalLogPipeline(n)},q.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,f({},e[0]),{level:v.ERROR}),this.normalLogPipeline(n)},q.prototype.speedLogPipeline=function(e){throw new Error('You need to override "speedLogPipeline" method')},q.prototype.reportPv=function(n){var i,o=this;n&&(console.warn("reportPv is deprecated, please use reportEvent"),i=""+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+"?"+i,addBean:!1,type:b.CUSTOM_PV})}],b.CUSTOM_PV)(null))},q.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"))},q.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")},q.prototype.reportT=function(e){var t=e.name,n=e.duration,i=e.ext1,i=void 0===i?"":i,o=e.ext2,o=void 0===o?"":o,r=e.ext3,r=void 0===r?"":r,e=e.from;if("string"==typeof t&&"number"==typeof n&&"string"==typeof i&&"string"==typeof o&&"string"==typeof r){if(!(n<0||6e4<n))return this.submitCustomTime(t,n,i,o,r,void 0===e?"":e);console.warn("reportTime: duration must between 0 and 60000")}else console.warn("reportTime: params error")},q.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")},q.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")},q.prototype.submitCustomTime=function(e,t,n,i,o,r){this.customTimePipeline({name:e,duration:t,ext1:n||this.config.ext1,ext2:i||this.config.ext2,ext3:o||this.config.ext3,from:r||void 0})},q.prototype.extendBean=function(e,t){this.bean[e]=t},q.prototype.sendPipeline=function(e,t){var n,r=this;return y(a([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}},W(n=this,t)],e,[G(this),function(i,o){r.request(i,function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.failRequestCount=0,o({isErr:!1,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.success)&&e.call.apply(e,a([i],t))},function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];60<=++r.failRequestCount&&r.destroy(),-1<(""+t[0]).indexOf("403 forbidden")&&r.destroy(),o({isErr:!0,result:t,logType:null==i?void 0:i.type,logs:null==i?void 0:i.log}),null!=(e=null==i?void 0:i.fail)&&e.call.apply(e,a([i],t))})},K(this)]))},q.prototype.send=function(e,o,r){var t=this;return y([G(this),function(n,i){t.request(n,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];i({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];i({isErr:!0,result:e,logType:n.type,logs:n.log}),null!=r&&r.apply(void 0,e)})},K(this)])(e)},q.prototype.ready=function(e,t,n){throw new Error('You need to override "ready" method')},q.prototype.request=function(e,t,n){throw new Error('You need to override "request" method')},q.prototype.sendSDKError=function(e){var n=this;this.sendPipeline([function(e,t){t({url:n.config.url+"?id=1085&msg[0]="+encodeURIComponent(O(e))+"&level[0]=2&from="+n.config.id+"&count=1&version="+n.config.id+"(1.37.5)",addBean:!1,method:"get",type:b.SDK_ERROR,log:e})}],b.SDK_ERROR)(e)},q.prototype.destroy=function(e){void 0===e&&(e=!1);var t,n,i=q.instances.indexOf(this);-1!==i&&q.instances.splice(i,1);for(var o=q.installedPlugins.length-1;0<=o;o--)try{q.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 r=this;r.constructor!==Object&&z(r,this),r=Object.getPrototypeOf(r););0===q.instances.length&&(i=Object.getPrototypeOf(this).constructor,z(i),z(q))}},q.version="1.37.5",q.instances=[],q.logType=v,q.environment=c,q.installedPlugins=[],q),r=(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 i=this;this.instances.forEach(function(e){var t=i.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),w=wx||qq,me="",ye=new r({name:"offlineLog",onNewAegis:function(o){if(w.getFileSystemManager)try{var e=o.config,t=e.id,r=void 0===t?"":t,n=e.uin,a=void 0===n?0:n,i=e.offlineUrl,s=void 0===i?"":i,l=e.offlineLogLimit,u=new ve({limit:l});o.lifeCycle.on("beforeWrite",function(e){u.save2Offline(e=void 0===e?[]:e,o.config)}),u.ready(function(t){var e=(o.bean||{}).aid,i=void 0===e?"":e;!t&&r&&(a||i)&&o.send({url:s+"/offlineAuto",type:b.OFFLINE,log:b.OFFLINE},function(e){var n=(null==e?void 0:e.data).secretKey;n&&!t&&u.getLogs({id:r,uin:a},function(e,t){e?console.error(e):o.send({url:s+"/offlineLog",data:{logs:t,secretKey:n,id:r,uin:a,aid:i},method:"post",type:b.OFFLINE,log:t},function(){u.clearLogs()})})})})}catch(o){console.error(o)}else console.warn("[aegis-mp-sdk]unsupport getFileSystemManager offline log not work!")}}),ve=(Te.prototype.getLogs=function(e,t){var n=this.fileSystem,i=this.filePath;n.readFile({filePath:i,encoding:"utf8",fail:function(e){console.error(e)},success:function(e){e=e.data,e=(void 0===e?"":e).toString().split("\n").filter(function(e){return e}).map(function(e){return JSON.parse(e)});t(null,e)}})},Te.prototype.checkLimit=function(o,r){void 0===r&&(r=function(){});var a=this.fileSystem,s=this.filePath,l=this.limitSize;a.readFile({filePath:s,encoding:"utf8",success:function(e){e=e.data,e=void 0===e?"":e;if((e=e.toString()+o).length>l){for(var t=e.split("\n"),n="",i=t.length-1;0<=i&&!(t[i]&&(n=t[i]+"\n"+n).length>l);i--);a.writeFile({filePath:s,data:n,success:r})}else a.appendFile({data:o,filePath:s,encoding:"utf8",success:r,fail:function(e){console.error(e)}})}})},Te),be=new r({name:"device",onNewAegis:function(t){return e=this,l=function(){return H(this,function(e){return this.setSystemInfo(t),this.refreshNetwork(t),this.setNetworkChange(t),[2]})},new(s=(s=a=void 0)||Promise)(function(n,t){function i(e){try{r(l.next(e))}catch(e){t(e)}}function o(e){try{r(l.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?n(e.value):((t=e.value)instanceof s?t:new s(function(e){e(t)})).then(i,o)}r((l=l.apply(e,a||[])).next())});var e,a,s,l},setSystemInfo:function(a){var s=this;try{o("getSystemInfo")&&w.getSystemInfo({success:function(e){var t=e.platform,n=e.model,i=e.windowHeight,o=e.windowWidth,r=e.screenWidth,r=void 0===r?0:r,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(i)),a.extendBean("sr",Math.round(r)+" * "+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},i=s.other,o=0;o<Object.keys(n).length;o++){var r=Object.keys(n)[o];if(null!=(t=n[r])&&t.test(e)){i=s[r];break}}return i},setNetworkChange:function(t){o("onNetworkStatusChange")&&w.onNetworkStatusChange(function(e){e=Y(e.networkType);t.extendBean("netType",e)})},setNetworkType:function(t){o("getNetworkType")&&w.getNetworkType({success:function(e){e=Y(e.networkType);t.extendBean("netType",e)}})},refreshNetwork:function(e){var t=this;this.timer&&clearTimeout(this.timer),this.setNetworkType(e),this.timer=setTimeout(function(){t.refreshNetwork(e)},1e4)}}),Oe=w.request,n=(e(N,ne=n),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(i(this.config)):"from="+encodeURIComponent(i(this.config))},enumerable:!1,configurable:!0}),N.prototype.initOfflineLog=function(){N.use(ye)},N.prototype.initRequestSchedule=function(){this.requestSchedule=new X(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(i(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),Ee=new r({name:"aid",onNewAegis:function(t){this.initAid(function(e){t.bean.aid=e,t.config.aid=e})},initAid:function(t){w.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)});w.setStorage({key:"AEGIS_ID",data:e,success:function(){t(e)}})}})}}),u=(C.prototype.addCallback=function(e){e&&this.callbacks.push(e)},C.prototype.prefixHandler=function(e){return f(f({},e),{aegisRequestStartTime:+new Date})},C.prototype.successHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.success)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.success)&&e.call(i,n,i)},C.prototype.failHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.fail)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.fail)&&e.call(i,n,i)},C.prototype.completeHandler=function(n,i){var e;this.callbacks.forEach(function(e){var t;try{null!=(t=e.complete)&&t.call(e,n,i)}catch(e){}}),null!=(e=i.complete)&&e.call(i,n,i)},C.prototype.override=function(){try{this.defineApiProperty()}catch(e){console.warn("cannot override `"+this.apiName+"`, error is: "+e)}finally{this.isOverride=!0}},C),P=wx||qq,S={},Re=(e(x,te=u),x.prototype.defineApiProperty=function(){var e=this;P.cloud&&P.cloud[this.apiName]&&Object.defineProperty(P.cloud,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},x.prototype.hackHandler=function(e){var i=this,o=this.prefixHandler(e);return new Promise(function(t,n){var e=null==(e=S[i.apiName])?void 0:e.originApi;null!=e&&e(f(f({},o),{success:function(e){i.successHandler(e,o),t(e)},fail:function(e){i.failHandler(e,o),n(e)},complete:function(e){i.completeHandler(e,o)}}))})},x),we=wx||qq,k={},Pe=(e(T,ee=u),T.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(we,this.apiName,{get:function(){return e.hackHandler.bind(e)}})},T.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=null==(e=k[this.apiName])?void 0:e.originApi;return null==e?void 0:e(f(f({},n),{success:function(e){t.successHandler(e,n)},fail:function(e){t.failHandler(e,n)},complete:function(e){t.completeHandler(e,n)}}))},T),Se=wx||qq,ke=Se.request;function T(){return null!==ee&&ee.apply(this,arguments)||this}function x(){return null!==te&&te.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 i,a,c=ne.call(this,e)||this;c.originRequest=Oe,c.speedLogPipeline=y([(a=c.config,function(e,t){var n,i,o,r="number"==typeof a.repeat?a.repeat:60;!a.speedSample||r<=0?t(e):(n=(null==a?void 0:a.id)||"0",i=R[n]||{},Array.isArray(e)?(o=e.filter(function(e){var t=!i[e.url]||i[e.url]<r;return t?(i[e.url]=1+~~i[e.url],R[n]=i):E[n]||pe(n),t})).length&&t(o):!i[e.url]||i[e.url]<r?(i[e.url]=1+~~i[e.url],R[n]=i,t(e)):E[n]||pe(n))}),m(c),function(t,n){o("getNetworkType")?w.getNetworkType({success:function(e){e=Y(e.networkType);i.extendBean("netType",e),n(t)}}):n(t)},function(e,t){c.lifeCycle.emit("beforeReportSpeed",e);var n=c.config.beforeReportSpeed;if((e="function"==typeof n?e.filter(function(e){return!1!==n(e)}):e).length)return t(e)},W(i=c,b.SPEED),function(e,t){t(e.map(function(e){return void 0!==e.payload&&delete e.payload,e}))},function(e){var t,n,i,o;c.send({url:""+c.config.speedUrl,method:"post",data:(e=e,t=c.bean,i={fetch:[],static:[],bridge:[]},o={},Array.isArray(e)?e.forEach(function(e){var t;null!=(t=i[e.type])&&t.push(e)}):null!=(n=i[e.type])&&n.push(e),o.payload=JSON.stringify(f({duration:i},t)),o)})}]),c.request=function(e,t,n){e.url&&c.bean.id&&(!/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(String(c.bean.aid))||o("getNetworkType")&&void 0===c.bean.netType?c.requestSchedule.addTask({options:e,success:t,fail:n}):(c.requestSchedule.addTask({options:e,success:t,fail:n}),c.requestSchedule.fireTask()))},c.sendRequest=function(e,t,n){var i,o,r,a=e.url,s=(c.config.whiteListUrl===a&&(i=t,t=function(e){null!=i&&i(JSON.stringify(e.data))}),e.method),s=void 0===s?"get":s,l=(!1!==e.addBean&&(a=a+(-1===(null==a?void 0:a.indexOf("?"))?"?":"&")+c.getBean),e),u=c.config.onBeforeRequest;return(l=u?u(e,c):l)&&l.url?(u=c.config.enableHttp2||!1,"get"===s?(s=a,o=l.data,a="string"!=typeof s?"":"object"==typeof o&&o?(r=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("?")?"?":"&")+r):s,c.originRequest(f({url:a,enableHttp2:u,success:t,fail:n,complete:c.requestSchedule.complete},e.requestConfig))):("string"==typeof l.data&&(l.data=l.data.replace(/eval/gi,"evaI")),c.originRequest(f({url:a,enableHttp2:u,header:l.contentType?{"content-type":l.contentType}:void 0,method:"POST",data:l.data,success:t,fail:n,complete:c.requestSchedule.complete},e.requestConfig))),!0):(r="",l&&l.url||(r="Sending request blocked. Please handle the parameters reasonably, options.url is necessary",console.log(r)),null!=n&&n(r),c.requestSchedule.complete(),!1)};try{e.offlineLog&&c.initOfflineLog(),c.initRequestSchedule(),c.init(e),c.extendBean("sessionId",N.sessionID),c.extendBean("referer",(o("getLaunchOptionsSync")?w.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"),c.sendSDKError(e)}return c}function Te(e){var o,r,a=this,e=void 0===e?{}:e,t=e.path,t=void 0===t?"/.aegis.offline.log":t,e=e.limit,e=void 0===e?2e4:e;this.offlineBuffer=[],this.insertLog=(o=null,r=[],function(e){r=r.concat(e),o=o||setTimeout(function(){var e,t=a.fileSystem,n=a.filePath,i=r.map(function(e){return JSON.stringify(e)}).join("\n")+"\n";i&&(e=function(e){e?a.checkLimit(i,function(){r=[]}):t.writeFile({data:i,filePath:n,encoding:"utf8",fail:function(e){console.error(e)},success:function(){r=[]}})},t.access({path:n,success:function(){e(!0)},fail:function(){e()}})),clearTimeout(o),o=null},2e3)}),this.ready=function(e){a.fileSystem?setTimeout(function(){e(null)},0):(e(new Error("getFileSystemManager file")),a.offlineLog=!1)},this.clearLogs=function(){var e=a.fileSystem,t=a.filePath;e.writeFile({filePath:t,data:"",fail:function(){e.unlinkSync(t)}})},this.save2Offline=function(e,t){e=(e=Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e&&(e={msg:e}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)throw new TypeError("Cannot convert undefined or null to object");for(var n=Object(e[0]),i=1;i<e.length;i++){var o=e[i];if(null!==o)for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(n[r]=o[r])}return n}({id:t.id,uin:t.uin,time:+Date.now(),version:t.version,from:i(t)},e)});a.fileSystem?a.insertLog(e):(a.fileSystem||a.offlineBuffer.length||a.ready(function(e){e?console.error(e):a.offlineBuffer.length&&(a.addLogs(a.offlineBuffer),a.offlineBuffer=[])}),a.offlineBuffer=a.offlineBuffer.concat(e))},this.addLogs=function(e){a.fileSystem&&a.insertLog(e)},this.filePath=w.env.USER_DATA_PATH+t,this.fileSystem=w.getFileSystemManager(),this.limitSize=e}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 q(e){var n,t,i,o,a,r,s,l,u,c,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:"",webVitalsUrl:"",eventUrl:"",setDataReportUrl:"",reportImmediately:!0},this.isWhiteList=!1,this.lifeCycle=new M,this.bean={},this.normalLogPipeline=y([m(this,5),V,function(e,t){var i=n.config;t(e=e.map(function(e){var t,n=i.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=O(e.msg).substring(0,i.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 i=(null==h?void 0:h.id)+"_error",o=R[i]||{};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 E[i]||pe(i),!1;o[e]=1+~~o[e],R[i]=o}return!0}))}),(p=this.lifeCycle.emit,d=this.config,function(e,t){var n,i=d.logCreated;return"function"==typeof i?(n=e.filter(function(e){return!1!==i(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)}),(u=l=s=!1,c=[],(a=this).lifeCycle.on("onConfigChange",function(){r&&clearTimeout(r),r=setTimeout(function(){var e,n;!u&&a.config&&(u=!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){l=!0;try{var t=e.data||JSON.parse(e),n=t.retcode,i=t.result,o=void 0===i?{}:i,r=(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&&c.length?he(a)(c.splice(0),function(){}):!a.isWhiteList&&c.length&&(c.length=0),a.config.onWhitelist);"function"==typeof r&&r(s)}catch(e){}},fail:function(){l=!0}})}],b.WHITE_LIST)(null),u=!1)},a.config.uin?50:500)}),a.lifeCycle.on("destroy",function(){c.length=0}),function(e,t){var n;s||null!=(n=null==(n=a.config)?void 0:n.api)&&n.reportRequest?t(e.concat(c.splice(0)).map(function(e){return fe(e),e})):(n=e.filter(function(e){return e.level!==v.INFO&&e.level!==v.API_RESPONSE?(fe(e),!0):(l||(c.push(e),200<=c.length&&(c.length=200)),!1)})).length&&t(n)}),function(e,t){try{var n=JSON.parse(JSON.stringify(e)),i=(g.lifeCycle.emit("beforeReport",n),g.config.beforeReport);(e="function"==typeof i?e.filter(function(e){return!1!==i(e)}):e).length&&t(e)}catch(e){}},he(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),(i=this,function(e){return i.sendPipeline([function(e,t){t({url:i.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.webVitalsUrl=t.webVitalsUrl||e+"/speed/webvitals",t.setDataReportUrl=t.SetDataReportUrl||e+"/speed/miniProgramData",t),q.instances.push(this)}function xe(){return null!==ie&&ie.apply(this,arguments)||this}e(xe,ie=u),xe.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(Se,"request",{get:function(){return e.hackHandler.bind(e)}})};function A(i,e,o){return null!=e&&e.length&&"object"==typeof i?e.reduce(function(e,t){var n=i[t];return n?e+(""===e?"\n":"\n\n")+o+" header "+t+": "+n:e},""):""}var _,Ce,Ne=new r({name:"reportApiSpeed",override:!(xe.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e);return ke(f(f({},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){this.override||(this.override=!0,this.hackRequest(e.config),this.overrideCallFunction(e.config),this.overrideCallContainer(e.config))},hackRequest:function(u){var c=this;Z({apiName:"request",success:function(e,t){var n,i,o,r,a,s,l;g(t.url,u.hostUrl)||(n={method:t.method||"get",url:p(t.url),duration:Date.now()-t.aegisRequestStartTime,status:e.statusCode||0,nextHopProtocol:"",isHttps:J(t.url),type:"fetch"},r=null==(r=u.api)?void 0:r.apiDetail,i=(o=d(e.data,u.api,{url:t.url,ctx:e,payload:t.data})||{}).code,o=o.isErr,l=r?h(t.data,null==(l=u.api)?void 0:l.reqParamHandler,{url:t.url}):"",r=r?h(e.data,null==(r=u.api)?void 0:r.resBodyHandler,{url:t.url}):"",a=(null==(a=u.api)?void 0:a.reqHeaders)||[],a=A(null==t?void 0:t.header,a,"req"),s=(null==(s=u.api)?void 0:s.resHeaders)||[],s=A(null==e?void 0:e.header,s,"res"),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: "+i+" \n \nres data: "+r+"\n "+a+"\n "+s,c.publishNormalLog({msg:l,level:v.API_RESPONSE,ctx:e}),n.ret=i,n.isErr=+o,n.payload=t.data,c.publishSpeedLog(n),o&&c.publishNormalLog({msg:l,level:v.RET_ERROR,ctx:e}))},fail:function(e,t){g(t.url,u.hostUrl)||(t={method:t.method||"get",url:p(t.url),duration:Date.now()-t.aegisRequestStartTime,status:0,nextHopProtocol:"",isHttps:J(t.url),type:"fetch"},c.publishSpeedLog(t))}})},overrideCallFunction:function(n){var i=this;Q({apiName:"callFunction",success:function(e,t){i.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};i.publishSpeedLog(t)}})},overrideCallContainer:function(n){var i=this;Q({apiName:"callContainer",success:function(e,t){i.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};i.publishSpeedLog(t)}})},cloudSuccessCallback:function(e,n,t,i){var o="callFunction"===i?n.name:n.path,r="callFunction"===i?t.result:t.data,o={method:"call",url:"wx.cloud."+i+"."+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},{}),i="callFunction"===i?(null==(i=t.data)?void 0:i.code)||0:t.statusCode,l=d(r,e.api,{url:o.url,ctx:t,payload:s})||{},u=l.code,l=l.isErr,l=void 0!==l&&l,u=(o.ret=u,o.isErr=+l,o.payload=s,null==(u=e.api)?void 0:u.apiDetail),s=u?h(s,null==(s=e.api)?void 0:s.reqParamHandler,{url:o.url}):"",r=u?h(r,null==(u=e.api)?void 0:u.resBodyHandler,{url:o.url}):"",u=(null==(u=e.api)?void 0:u.reqHeaders)||[],u=A(null==n?void 0:n.header,u,"req"),e=(null==(e=e.api)?void 0:e.resHeaders)||[],e=A(null==t?void 0:t.header,e,"res"),i="req url: "+o.url+"\n \nres status: "+i+"\n \nres duration: "+o.duration+"ms \n \nreq type: "+o.type+"\n \nreq params: "+s+"\n \nres retcode: "+o.ret+"\n \nres data: "+r+"\n "+u+"\n "+e;this.publishNormalLog({msg:i,level:v.API_RESPONSE,ctx:t}),this.publishSpeedLog(o),l&&this.publishNormalLog({msg:i,level:v.RET_ERROR,ctx:t})},publishSpeedLog:function(t){this.$walk(function(e){e.speedLogPipeline(t)})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})}}),Le=wx||qq,qe=Le.connectSocket,Ae=(Ie.prototype.addConfig=function(e){var t=e.send,e=e.onError;t&&this.sends.push(t),e&&this.onErrors.push(e)},Ie.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(i){return new Promise(function(e){n.call(t,f(f({},i),{fail:function(n){o.sends.forEach(function(e){var t;null!=(t=e.fail)&&t.call(e,n,i)}),e(n)}}))})}}}),t},Ie),_e=(e(U,Ce=u),U.prototype.addTaskConf=function(e){this.taskHack.addConfig(e)},U.prototype.defineApiProperty=function(){var e=this;Object.defineProperty(Le,"connectSocket",{get:function(){return e.hackHandler.bind(e)}})},U.prototype.hackHandler=function(e){var t=this,n=this.prefixHandler(e),e=qe(f(f({},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},U),u=new r({name:"onError",onNewAegis:function(e){var t=w.getSystemInfoSync().SDKVersion;this.listenError(),this.hackNetWork(e),this.hackCloud(e),e.config.websocketHack&&$(t,"1.7.0")&&this.hackWsConnect()},listenError:function(){var t=this;"function"==typeof w.onError&&w.onError(function(e){e&&t.publishErrorLog({msg:e,level:v.ERROR})}),o("onUnhandledRejection")&&w.onUnhandledRejection(function(e){e=e.reason;!e||-1<JSON.stringify(e).indexOf("request:fail")||t.publishErrorLog({msg:e,level:v.PROMISE_ERROR})}),o("onPageNotFound")&&w.onPageNotFound(function(e){e&&t.publishErrorLog({msg:e,level:v.PAGE_NOT_FOUND_ERROR})}),o("onLazyLoadError")&&w.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,i=e.config,t=0,o=[{apiName:"request",complete:function(e,t){return n.requestCompleteError(e,t,i)}},{apiName:"uploadFile",complete:function(e,t){return n.uploadFileCompleteError(e,t,i)}},{apiName:"downloadFile",complete:function(e,t){return n.downloadFileCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;Z({apiName:a,complete:r})}},requestCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode;g(t.url,n.hostUrl)||(i=this.getErrorType({errMsg:i,statusCode:o}))&&this.publishNetWorkError({apiName:"request",opts:t,res:e,config:n,type:i})},downloadFileCompleteError:function(e,t,n){var i,o=e.errMsg,r=e.statusCode,a=e.filePath,e=e.tempFilePath,s=this.getErrorType({errMsg:o,statusCode:r});s&&(n=null!=(i=n.api)&&i.apiDetail?h(t.data,null==(i=n.api)?void 0:i.reqParamHandler,{url:t.url}):"",this.publishErrorLog({msg:"AJAX_ERROR: downloadFile "+s+"\n \nreq url: "+t.url+"\n \nres status: "+(r||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres filePath: "+a+"\n \nres tempFilePath: "+e+"\n \nreq method: "+(t.method||"get")+"\n \nreq param: "+n+"\n \nerrMsg: "+o.slice(0,1e3),level:v.AJAX_ERROR}))},uploadFileCompleteError:function(e,t,n){var i=e.errMsg,o=e.statusCode,i=this.getErrorType({errMsg:i,statusCode:o});i&&this.publishNetWorkError({apiName:"uploadFile",opts:t,res:e,config:n,type:i})},hackCloud:function(e){for(var n=this,i=e.config,t=0,o=[{apiName:"callFunction",complete:function(e,t){return n.callFunctionCompleteError(e,t,i)}},{apiName:"callContainer",complete:function(e,t){return n.callContainerCompleteError(e,t,i)}}];t<o.length;t++){var r=o[t],a=r.apiName,r=r.complete;Q({apiName:a,complete:r})}},callFunctionCompleteError:function(e,t,n){var i,o;(-1<e.errMsg.indexOf("fail")||-1<e.errMsg.indexOf("timeout"))&&(o=(i=null==(i=n.api)?void 0:i.apiDetail)?h(t.data,null==(o=n.api)?void 0:o.reqParamHandler,{url:null==t?void 0:t.url}):"",n=i?h(e,null==(i=n.api)?void 0:i.resBodyHandler,{url:null==t?void 0:t.url}):"",this.publishErrorLog({msg:"AJAX_ERROR: cloud.callFunction:fail\n \nreq url: cloud.callFunction."+t.name+"\n \nres status: 0\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nres data: "+n+"\n \nreq method: POST\n \nreq param: "+o+"\n \nerrMsg: "+e.errMsg.slice(0,1e3),level:v.AJAX_ERROR}))},callContainerCompleteError:function(e,t,n){var i,o,r,a=e.errMsg,s=e.statusCode;(400<=s||-1<a.indexOf("fail")||-1<a.indexOf("timeout"))&&(i=(o=null==(o=n.api)?void 0:o.apiDetail)?h(t.data,null==(i=n.api)?void 0:i.reqParamHandler,{url:null==t?void 0:t.url}):"",o=o?h(e,null==(o=n.api)?void 0:o.resBodyHandler,{url:null==t?void 0:t.url}):"",r=(null==(r=n.api)?void 0:r.reqHeaders)||[],r=A(null==t?void 0:t.header,r,"req"),n=(null==(n=n.api)?void 0:n.resHeaders)||[],e=A(null==e?void 0:e.header,n,"res"),this.publishErrorLog({msg:"AJAX_ERROR: cloud.callContainer:fail\n \nreq url: "+t.path+"\n \nres status: "+(s||0)+"\n \nres duration: "+(Date.now()-t.aegisRequestStartTime)+"ms\n \nreq method: "+(t.method||"POST")+"\n \nreq param: "+i+"\n \nres data: "+o+"\n \nerrMsg: "+a.slice(0,1e3)+"\n "+r+"\n "+e,level:v.AJAX_ERROR}))},publishNetWorkError:function(e){var t=e.apiName,n=e.opts,i=e.res,o=e.config,e=e.type,r=i.errMsg,a=i.statusCode,s=i.data,l="wx.cloud.callFunction."+n.url,u=d(s,o.api,{url:l,ctx:i,payload:n.data}).code,c=null==(c=o.api)?void 0:c.apiDetail,f=c?h(n.data,null==(f=o.api)?void 0:f.reqParamHandler,{url:l}):"",s=c?h(s,null==(c=o.api)?void 0:c.resBodyHandler,{url:l}):"",l=(null==(c=o.api)?void 0:c.reqHeaders)||[],c=A(null==n?void 0:n.header,l,"req"),o=(null==(l=o.api)?void 0:l.resHeaders)||[],l=A(null==i?void 0:i.header,o,"res");this.publishErrorLog({msg:"AJAX_ERROR: "+t+" "+e+"\n \nreq url: "+n.url+"\n \nres status: "+(a||0)+"\n \nres duration: "+(Date.now()-n.aegisRequestStartTime)+"ms\n \nreq method: "+(n.method||"get")+"\n \nreq param: "+f+"\n \nres retcode: "+u+"\n \nres data: "+s+"\n \nerrMsg: "+r.slice(0,1e3)+"\n "+c+"\n "+l,level:v.AJAX_ERROR})},getErrorType:function(e){var t=e.errMsg,e=e.statusCode,n="",i=t;return["timeout","time out","ERR_CONNECTION_TIMED_OUT","ERR_TIMED_OUT","超时"].some(function(e){return String(i||"").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;Z({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,_?_.addCallback(e):_=new _e(e),t&&_.addTaskConf(t)},publishSocketError:function(e){e&&this.publishErrorLog({msg:e.errMsg,level:v.WEBSOCKET_ERROR})}}),Ue=new r({name:"reportAssetSpeed",isStart:!1,onNewAegis:function(e){this.isStart||(this.isStart=!0,this.start(e))},start:function(t){var n=this;w.getPerformance&&w.getPerformance().createObserver(function(e){e=e.getEntries();null!=e&&e.forEach(function(e){g(e.uri,t.config.hostUrl)||"number"!=typeof e.duration||e.duration<=0||n.publishAssetLog(e)})}).observe({entryTypes:["resource"]})},generateLog:function(e){var t,n,i=e.transferSize;return{url:(t=e.uri,void 0===n&&(n=2048),String(t).replace(I,"").slice(0,n)),method:"get",duration:Math.round(100*e.duration)/100,status:200,type:"static",isHttps:!0,urlQuery:p(e.uri,!0),nextHopProtocol:"",domainLookup:0,connectTime:0,transferSize:0<i?i:-1}},publishAssetLog:function(t){var n=this;this.$walk(function(e){e.speedLogPipeline(n.generateLog(t))})}}),je=["onLaunch","onHide","onError","onLoad","onReady","onShow","onUnload"],He=new r({name:"pagePerformance",pageNavigationStartTime:{},onNewAegis:function(e){try{o("getPerformance")&&this.reportPerformance(e),this.setPagePV(e),this.reportSetDataTiming(e)}catch(e){}},reportPerformance:function(u){var c=this,e=w.getPerformance(),e=null==e?void 0:e.createObserver(function(e){var t={},n=null==(n=e.getEntriesByName("appLaunch"))?void 0:n[0],i=null==(i=e.getEntriesByName("firstRender"))?void 0:i[0],o=null==(o=e.getEntriesByName("evaluateScript"))?void 0:o[0],r=null==(r=e.getEntriesByName("route"))?void 0:r[0],a=null==(a=null==(a=e.getEntriesByName("firstPaint"))?void 0:a[0])?void 0:a.startTime,s=null==(s=(null==(s=e.getEntriesByName("firstPaint"))?void 0:s[0])||(null==(s=e.getEntriesByName("route"))?void 0:s[0])||(null==(s=e.getEntriesByName("appLaunch"))?void 0:s[0]))?void 0:s.pageId,l=null==(e=(null==(l=e.getEntriesByName("route"))?void 0:l[0])||(null==(l=e.getEntriesByName("appLaunch"))?void 0:l[0]))?void 0:e.startTime;s&&(c.pageNavigationStartTime[s]=null,l)&&(c.pageNavigationStartTime[s]=l),n&&(t.appLaunch=n.duration||-1),i&&(t.firstScreenTiming=i.duration||-1),o&&(t.scriptEvaluateTiming=o.duration||-1),r&&(t.pageRouteTiming=r.duration||-1),a&&l?t.firstPaintTiming=Math.max(a-l,-1):a&&c.pageNavigationStartTime[s]&&(t.firstPaintTiming=Math.max(a-c.pageNavigationStartTime[s],-1)),0<Object.keys(t).length&&c.publish(t,u)});null!=e&&e.observe({entryTypes:["navigation","render","script"]})},publish:function(t,n){var e,i,o,r=[],a=n.config,s=-1===(null==(e=n.config.performanceUrl)?void 0:e.indexOf("?"))?"?":"&";for(i in t)r.push(i+"="+t[i]);"function"==typeof a.urlHandler?(o=a.urlHandler()||window.location.href,this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&")+"&from="+encodeURIComponent(o),beanFilter:["from"],type:b.PERFORMANCE,log:t})})):this.$walk(function(e){e.send({url:n.config.performanceUrl+s+r.join("&"),type:b.PERFORMANCE,log:t})})},setPagePV:function(t){var n=this;w.onAppRoute&&w.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,l,n,r,a,u,c=this,i=t.config.setDataReportConfig,i=void 0===i?{}:i;!0!==i.disabled&&(e=i.timeThreshold,o=!1!==i.withDataPaths,s=e&&0<+e?+e:30,l=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,r=Component,a=function(e,t){var r,a,n=t.updateStartTimestamp,i=t.updateEndTimestamp,t=t.dataPaths,t=void 0===t?[]:t,i=i-n;isNaN(i)||i<s||(n={from:e.is,duration:i},o&&0<t.length&&Object.assign(n,{dataPaths:t.slice(0,30),size:(i=t,a=0,null!=(r=e)&&r.data?(i.forEach(function(e){for(var t=r.data[e[0]],n=1,i=e.length;n<i;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)}),l(n))},u=function(i){var e="infoType: behaviorBacktracking\ndataType: tapEvent"+Object.keys(i[0]).reduce(function(e,t){var n="";try{n=t+": "+JSON.stringify(i[0][t])}catch(e){n=""}return e+"\n"+n},"");c.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&&u(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)}):(i=e.attached,e.attached=function(){var t=this;return"function"==typeof this.setUpdatePerformanceListener&&this.setUpdatePerformanceListener({withDataPaths:o},function(e){a(t,e)}),null==i?void 0:i.call(this)});var n,i,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&&u(e),null==n?void 0:n.apply(this,e)})}),r(e)})}}),r=new r({name:"reportLoadPackageSpeed",isLoaded:!1,onNewAegis:function(e){this.isLoaded||(this.isLoaded=!0,this.start(e))},start:function(){var t=this;w.getPerformance&&w.getPerformance().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 i=this;this.$walk(function(e){var t=i.generateLog(n);e.send({url:e.config.setDataReportUrl+"?payload="+encodeURIComponent(JSON.stringify({miniProgramData:t})),type:b.LOAD_PACKAGE,log:t})})}});function U(e){e=Ce.call(this,e)||this;return e.taskHack=new Ae,e}function Ie(){this.onErrors=[],this.sends=[]}return n.use(u),n.use(Ne),n.use(Ee),n.use(Ue),n.use(He),n.use(r),n.use(be),n});