/** * ================================================================ * aegis-mp-sdk@1.37.5 (c) 2023 TencentCloud Real User Monitoring. * Author pumpkincai. * Last Release Time Mon Jun 26 2023 14:20:23 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 f=function(){return(f=Object.assign||function(e){for(var t,n=1,i=arguments.length;ns[0]&&t[1]=i||n.sendNow&&0n.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(){1l){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;on)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