aegis.min.js 33 KB

12345678910
  1. /**
  2. * ===========================================================================
  3. * aegis-weex-sdk@1.36.4 (c) 2023 TencentCloud Real User Monitoring.
  4. * Author pumpkincai.
  5. * Last Release Time Mon Mar 27 2023 10:32:39 GMT+0800 (China Standard Time).
  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 n=function(e,t){return(n=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)},u=function(){return(u=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function s(e,s,l,a){return new(l=l||Promise)(function(n,t){function o(e){try{r(a.next(e))}catch(e){t(e)}}function i(e){try{r(a.throw(e))}catch(e){t(e)}}function r(e){var t;e.done?n(e.value):((t=e.value)instanceof l?t:new l(function(e){e(t)})).then(o,i)}r((a=a.apply(e,s||[])).next())})}function f(o,i){var r,s,l,a={label:0,sent:function(){if(1&l[0])throw l[1];return l[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(;a;)try{if(r=1,s&&(l=2&t[0]?s.return:t[0]?s.throw||((l=s.return)&&l.call(s),0):s.next)&&!(l=l.call(s,t[1])).done)return l;switch(s=0,(t=l?[2&t[0],l.value]:t)[0]){case 0:case 1:l=t;break;case 4:return a.label++,{value:t[1],done:!1};case 5:a.label++,s=t[1],t=[0];continue;case 7:t=a.ops.pop(),a.trys.pop();continue;default:if(!((l=0<(l=a.trys).length&&l[l.length-1])||6!==t[0]&&2!==t[0])){a=0;continue}if(3===t[0]&&(!l||t[1]>l[0]&&t[1]<l[3]))a.label=t[1];else if(6===t[0]&&a.label<l[1])a.label=l[1],l=t;else{if(!(l&&a.label<l[2])){l[2]&&a.ops.pop(),a.trys.pop();continue}a.label=l[2],a.ops.push(t)}}t=i.call(o,a)}catch(e){t=[6,e],s=0}finally{r=l=0}if(5&t[0])throw t[1];return{value:t[0]?t[1]:void 0,done:!0}}}}function l(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var o=Array(e),i=0,t=0;t<n;t++)for(var r=arguments[t],s=0,l=r.length;s<l;s++,i++)o[i]=r[s];return o}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!=(o=arguments[n]))for(var o=Object(o),i=Object.keys(Object(o)),r=0,s=i.length;r<s;r++){var l=i[r],a=Object.getOwnPropertyDescriptor(o,l);null!=a&&a.enumerable&&(t[l]=o[l])}return t}});var o,q=["/collect/offlineAuto","/aegis-sdk","/flog.core.min.js","pingfore.qq.com/pingd","h.trace.qq.com/kv","beacon.qq.com","dmplog.qq.com","qq.com/report","report.qqweb.qq.com","tpstelemetry.tencent.com","insight.cloud.tencent.com","www.googletagmanager.com","report.idqqimg.com","google-analytics.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"],p=["ext1","ext2","ext3","level","trace","tag","seq","code"],D=["static","fetch"],k=(e.prototype.indexOf=function(e,t){for(var n=0;n<e.length;n++)if(e[n].callback===t)return n;return-1},e.prototype.on=function(e,t,n){var o;if(void 0===n&&(n=0),this)return(o=this.eventsList[e])||(this.eventsList[e]=[],o=this.eventsList[e]),-1===this.indexOf(o,t)&&o.push({name:e,type:n||0,callback:t}),this},e.prototype.one=function(e,t){this.on(e,t,1)},e.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}},e.prototype.clear=function(){this.eventsList={}},e),F=function(e){if(!e||0===e.length)return"{}";e=Array.isArray(e)?e:[e];var t=Object.keys(e[0]),n={},o=(t.forEach(function(t){n[t]=e.map(function(e){return e[t]})}),n.count=e.length,n);if("string"==typeof o)return o;try{return JSON.stringify(o,i())||"undefined"}catch(o){return"error happen when aegis stringify: \n "+o.message+" \n "+o.stack}};function e(){var s=this;this.emit=function(e,t){if(s){var n;if(null!=(o=s.eventsList[e])&&o.length)for(var o=o.slice(),i=0;i<o.length;i++){n=o[i];try{var r=n.callback.apply(s,[t]);if(1===n.type&&s.remove(e,n.callback),!1===r)break}catch(e){throw e}}return s}},this.eventsList={}}(r=o=o||{})[r.number=-1]="number",r.string="";function d(e){return"string"==typeof e&&/^\//.test(e)?"https:"===(null===location||void 0===location?void 0:location.protocol):/^https/.test(e)}function h(e,t,n){try{var o="function"==typeof t?t(e,null==n?void 0:n.url)||"":e;return x(o).slice(0,102400)}catch(e){return""}}function g(t,e){return"string"!=typeof t||!t||e&&-1<t.indexOf(e)||X.test(t)||q.some(function(e){return-1<t.indexOf(e)})}function m(n,o){var i,r=[],s=n.config;return n.lifeCycle.on("destroy",function(){r.length=0}),function(e,t){Array.isArray(e)?r=r.concat(e):r.push(e),o&&r.length>=o||n.sendNow&&0<r.length?(r=z(r),t(r.splice(0,r.length)),i&&clearTimeout(i)):(i&&clearTimeout(i),i=setTimeout(function(){i=null,0<(r=z(r)).length&&t(r.splice(0,r.length))},s.delay))}}function B(e,t){return Array.isArray(e)?t(e.map(function(e){return t=u(u({},e),{msg:"string"==typeof e.msg?e.msg:[].concat(e.msg).map(w).join(" ")}),p.forEach(function(e){t[e]||delete t[e]}),t;var t})):t([u(u({},e),{msg:"string"==typeof e.msg?e.msg:w(e.msg)})])}function H(a,c){return function(e,t){var n,o,i,r=Array.isArray(e),s=r?e:[e],l=(a.lifeCycle.emit("beforeRequest",e),a.config.beforeRequest);(s="function"==typeof l?s.map(function(e){try{var t=l({logs:e,logType:c});return(null==t?void 0:t.logType)===c&&null!=t&&t.logs?t.logs:!1!==t&&e}catch(t){return e}}).filter(function(e){return!1!==e}):s).length&&(n=s,e=p,!Array.isArray(n)||n.length<=1||(o=[],i=[],!(i="string"==typeof e?[e]:e))||i.length<=0||(i.forEach(function(t){n.forEach(function(e){null!=e&&e[t]&&o.push(t)})}),0<o.length&&(n=n.map(function(e){var t={};return o.forEach(function(e){t[e]=""}),u(u({},t),e)}))),s=n,t(r?s:s[0]))}}function a(i){return function(e,t){i.lifeCycle.emit("modifyRequest",e);var n=i.config.modifyRequest;if("function"==typeof n)try{var o=n(e);"object"==typeof o&&"url"in o&&(e=o)}catch(e){console.error(e)}t(e)}}function c(o){return function(e,t){null!=(n=o.lifeCycle)&&n.emit("afterRequest",e);var n=(o.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||ee)}:n.reduce(function(n,o){return function(e,t){return void 0===t&&(t=ee),n(e,function(e){return null==o?void 0:o(e,t)})}});throw new TypeError("createPipeline need at least one function param")}function v(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 M(n){var t,e=this,o=(r=n.config).uin,i=r.id,r=r.offlineLogLimit;o&&i&&(t=new G({limit:void 0===r?2e4:r}),n.lifeCycle.on("beforeWrite",function(e){t.save2Offline(e=void 0===e?[]:e,n.config)}),n.getOfflineLog=function(){var e=t.getLogs({uin:o,id:i});return t.clearLogs(),e},n.uploadOfflineLogs=function(t){return s(e,void 0,void 0,function(){return f(this,function(e){return t=Array.isArray(t)?t:[t],[2,function(a,c){return s(this,void 0,void 0,function(){var t,n,o,i,r,s,l;return f(this,function(e){return t=a.config,n=a.bean,o=t.offlineUrl,i=t.id,r=t.uin,s=(n||{}).aid,l=void 0===s?"":s,(r||l)&&i?(a.send({url:o+"/offlineAuto",type:O.OFFLINE,log:O.OFFLINE},function(e){var t=(null==e?void 0:e.data).secretKey;if(t)try{a.send({url:o+"/offlineLog",data:{logs:c,secretKey:t,id:i,uin:r,aid:l},contentType:"application/json",method:"post",type:O.OFFLINE,log:O.OFFLINE})}catch(e){console.error(e)}},function(e){console.error(e)}),[2]):[2]})})}(n,t)]})})})}function G(e){var o=this,e=void 0===(e=(void 0===e?{}:e).limit)?2e4:e;this.offlineBuffer=[],this.clearLogs=function(){o.offlineBuffer=[]},this.save2Offline=function(e,t){e=(e=Array.isArray(e)?e:[e]).map(function(e){return"string"==typeof e&&(e={msg:e}),Object.assign({id:t.id,uin:t.uin,time:+Date.now(),version:t.version},e)});o.offlineBuffer=o.offlineBuffer.concat(e).slice(0,o.limitSize)},this.getLogs=function(t,e){var n=o.offlineBuffer.filter(function(e){return e.id===t.id&&e.uin===t.uin});return null!=e&&e(n),n},this.limitSize=e}function J(e,o){return void 0===o&&(o={}),new Promise(function(t,n){C||n(new Error("no available fetch found!"));try{C(u(u({},o),{url:e,type:"text"}),function(e){return t(j(e))})}catch(e){n(e)}})}var b,O,R,V,t,W=["application/xhtml+xml","application/xml","application/pdf","application/pkcs12","application/javascript","application/x-javascript","application/ecmascript","application/vnd.mspowerpoint","application/vnd.apple.mpegurl","application/ogg","text/css","text/javascript","image","audio","video","video/mp2t"],K=/\.(json|js|css|jpg|jpeg|png|svg|apng|webp|gif|bmp|mp4|mp3|ts|mpeg|wav|webm|ogg|flv|m3u8|ttf|woff2|otf|eot|woff|html|htm|shtml|shtm|)$/gi,$=["ret","retcode","code","errcode"],i=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}},w=function(e){if("string"==typeof e)return e;try{return e instanceof Error?(JSON.stringify(e,i(),4)||"undefined").replace(/"/gim,""):JSON.stringify(e,i(),4)||"undefined"}catch(e){return"error happen when aegis stringify: \n "+e.message+" \n "+e.stack}},x=function(r,s){void 0===s&&(s=3);var i,l,a,c="";return Array.isArray(r)?(c+="[",i=r.length,r.forEach(function(e,t){var n,o;c=(c+="object"==typeof e&&1<s?x(e,s-1):(o="",o+="undefined"==(n=typeof(e=e))||"symbol"==n||"function"==n?"null":"string"==n||"object"==n?'"'+e+'"':e))+(t===i-1?"":",")}),c+="]"):r instanceof Object?(c="{",l=Object.keys(r),a=l.length,l.forEach(function(e,t){var n,o,i;"object"==typeof r[e]&&1<s?c+='"'+e+'":'+x(r[e],s-1):c+=(n=r[e=e],i="","string"==(o=typeof n)||"object"==o?i+='"'+e+'":"'+n+'"':"function"==typeof n?i+='"'+e+'":"function '+n.name+'"':"symbol"==typeof n?i+='"'+e+'":"symbol"':"number"!=typeof n&&"boolean"!=o||(i+='"'+e+'": '+n),i),c+=t===a-1||t<a-1&&void 0===r[l[t+1]]?"":","}),c+="}"):c+=r,c},X=/data:(image|text)\/.*;base64/,z=((r=b=b||{}).INFO_ALL="-1",r.API_RESPONSE="1",r.INFO="2",r.ERROR="4",r.PROMISE_ERROR="8",r.AJAX_ERROR="16",r.SCRIPT_ERROR="32",r.IMAGE_ERROR="64",r.CSS_ERROR="128",r.CONSOLE_ERROR="256",r.MEDIA_ERROR="512",r.RET_ERROR="1024",r.REPORT="2048",r.PV="4096",r.EVENT="8192",r.PAGE_NOT_FOUND_ERROR="16384",r.WEBSOCKET_ERROR="32768",r.BRIDGE_ERROR="65536",(r=O=O||{}).LOG="log",r.SPEED="speed",r.PERFORMANCE="performance",r.OFFLINE="offline",r.WHITE_LIST="whiteList",r.VITALS="vitals",r.PV="pv",r.CUSTOM_PV="customPV",r.EVENT="event",r.CUSTOM="custom",r.SDK_ERROR="sdkError",r.SET_DATA="setData",r.LOAD_PACKAGE="loadPackage",(r=R=R||{}).production="production",r.development="development",r.gray="gray",r.pre="pre",r.daily="daily",r.local="local",r.test="test",r.others="others",function(e){return e.filter(function(n,o){return"static"!==n.type||!e.find(function(e,t){return n.url===e.url&&200===n.status&&o<t})})}),Y=function(e){e.level===b.INFO_ALL&&(e.level=b.INFO)},E={},P={},T=function(e){return E[e]||(E[e]=setTimeout(function(){P[e]={},E[e]=null},6e4)),E[e]},Q=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:b.INFO,msg:""})})},Z=function(o){return function(e){return o.sendPipeline([function(e,n){return n({url:o.config.url||"",data:F(Q(e)),method:"post",contentType:"application/json",type:O.LOG,log:e,requestConfig:{timeout:5e3},success:function(){var t=o.config.onReport;"function"==typeof t&&e.forEach(function(e){t(e)}),"function"==typeof n&&n([])}})}],O.LOG)(e)}},ee=function(){},r=(Object.defineProperty(N.prototype,"__version__",{get:function(){return console.warn("__version__ has discard, please use version"),"1.36.4"},enumerable:!1,configurable:!0}),Object.defineProperty(N.prototype,"LogType",{get:function(){return console.warn("LogType has discard, please use logType"),b},enumerable:!1,configurable:!0}),N.prototype.init=function(e){this.setConfig(e);for(var t=0;t<N.installedPlugins.length;t++)try{N.installedPlugins[t].patch(this)}catch(e){this.sendSDKError(e)}this.lifeCycle.emit("onInited")},N.prototype.setConfig=function(e){Object.assign(this.config,e);var e=this.config,t=e.id,n=e.uin,o=e.version,i=e.ext1,r=e.ext2,s=e.ext3,l=e.aid,a=e.env,c=void 0===a?"production":a,a=e.pageUrl,e=this.bean.id!==t||this.bean.uin!==n||this.bean.aid!==l;return this.bean.id=t||"",this.bean.uin=n||"",this.bean.version=o||"1.36.4",this.bean.aid=l||"",this.bean.env=function(){switch(c){case R.production:case R.development:case R.gray:case R.pre:case R.daily:case R.local:case R.test:case R.others:return 1;default:return}}()?c:R.others,a&&this.extendBean("from",encodeURIComponent(a.slice(0,2048))),i&&this.extendBean("ext1",encodeURIComponent(i)),r&&this.extendBean("ext2",encodeURIComponent(r)),s&&this.extendBean("ext3",encodeURIComponent(s)),e&&this.lifeCycle.emit("onConfigChange",this.config),this.config},N.use=function(e){-1===N.installedPlugins.indexOf(e)&&e.aegisPlugin&&N.installedPlugins.push(e)},N.unuse=function(e){e=N.installedPlugins.indexOf(e);-1!==e&&N.installedPlugins.splice(e,1)},N.prototype.info=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.INFO,msg:e};1===e.length&&e[0].msg&&Object.assign(n,u({},e[0]),{level:b.INFO}),this.normalLogPipeline(n)},N.prototype.infoAll=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.INFO_ALL,msg:e};1===e.length&&e[0].msg&&Object.assign(n,u({},e[0]),{level:b.INFO_ALL}),this.normalLogPipeline(n)},N.prototype.report=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.REPORT,msg:e};1===e.length&&e[0].msg&&Object.assign(n,u({},e[0])),this.normalLogPipeline(n)},N.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n={level:b.ERROR,msg:e};1===e.length&&e[0].msg&&Object.assign(n,u({},e[0]),{level:b.ERROR}),this.normalLogPipeline(n)},N.prototype.speedLogPipeline=function(e){throw new Error('You need to override "speedLogPipeline" method')},N.prototype.reportPv=function(n){var o,i=this;n&&(console.warn("reportPv is deprecated, please use reportEvent"),o=""+Object.getOwnPropertyNames(this.bean).filter(function(e){return"id"!==e}).map(function(e){return e+"="+i.bean[e]}).join("&"),this.sendPipeline([function(e,t){t({url:i.config.url+"/"+n+"?"+o,addBean:!1,type:O.CUSTOM_PV})}],O.CUSTOM_PV)(null))},N.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?this.eventPipeline(e):console.warn("reportEvent params error"))},N.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")},N.prototype.reportT=function(e){var t=e.name,n=e.duration,o=e.ext1,o=void 0===o?"":o,i=e.ext2,i=void 0===i?"":i,r=e.ext3,r=void 0===r?"":r,e=e.from;if("string"==typeof t&&"number"==typeof n&&"string"==typeof o&&"string"==typeof i&&"string"==typeof r){if(!(n<0||6e4<n))return this.submitCustomTime(t,n,o,i,r,void 0===e?"":e);console.warn("reportTime: duration must between 0 and 60000")}else console.warn("reportTime: params error")},N.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")},N.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")},N.prototype.submitCustomTime=function(e,t,n,o,i,r){this.customTimePipeline({name:e,duration:t,ext1:n||this.config.ext1,ext2:o||this.config.ext2,ext3:i||this.config.ext3,from:r||void 0})},N.prototype.extendBean=function(e,t){this.bean[e]=t},N.prototype.sendPipeline=function(e,t){var n,r=this;return y(l([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}},H(n=this,t)],e,[a(this),function(o,i){r.request(o,function(){for(var e,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];r.failRequestCount=0,i({isErr:!1,result:t,logType:null==o?void 0:o.type,logs:null==o?void 0:o.log}),null!=(e=null==o?void 0:o.success)&&e.call.apply(e,l([o],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(),i({isErr:!0,result:t,logType:null==o?void 0:o.type,logs:null==o?void 0:o.log}),null!=(e=null==o?void 0:o.fail)&&e.call.apply(e,l([o],t))})},c(this)]))},N.prototype.send=function(e,i,r){var t=this;return y([a(this),function(n,o){t.request(n,function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o({isErr:!1,result:e,logType:n.type,logs:n.log}),null!=i&&i.apply(void 0,e)},function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];o({isErr:!0,result:e,logType:n.type,logs:n.log}),null!=r&&r.apply(void 0,e)})},c(this)])(e)},N.prototype.ready=function(e,t,n){throw new Error('You need to override "ready" method')},N.prototype.request=function(e,t,n){throw new Error('You need to override "request" method')},N.prototype.sendSDKError=function(e){var n=this;this.sendPipeline([function(e,t){t({url:n.config.url+"?id=1085&msg[0]="+encodeURIComponent(w(e))+"&level[0]=2&from="+n.config.id+"&count=1&version="+n.config.id+"(1.36.4)",addBean:!1,method:"get",type:O.SDK_ERROR,log:e})}],O.SDK_ERROR)(e)},N.prototype.destroy=function(e){void 0===e&&(e=!1);var t,n,o=N.instances.indexOf(this);-1!==o&&N.instances.splice(o,1);for(var i=N.installedPlugins.length-1;0<=i;i--)try{N.installedPlugins[i].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&&v(r,this),r=Object.getPrototypeOf(r););0===N.instances.length&&(o=Object.getPrototypeOf(this).constructor,v(o),v(N))}},N.version="1.36.4",N.instances=[],N.logType=b,N.environment=R,N.installedPlugins=[],N),L=(I.prototype.patch=function(e){this.canUse(e)&&this.exist(e)&&(this.instances.push(e),this.triggerInit(e),this.triggerOnNewAegis(e))},I.prototype.unpatch=function(e){var t=this.instances.indexOf(e);-1!==t&&(this.instances.splice(t,1),0===this.instances.length)&&this.uninstall(e)},I.prototype.countInstance=function(){return this.instances.length},I.prototype.uninstall=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.destroy)&&t.apply(this,[e])},I.prototype.walk=function(n){var o=this;this.instances.forEach(function(e){var t=o.canUse(e);t&&n(e,t)})},I.prototype.canUse=function(e){e=this.getConfig(e);return!(!e||"object"!=typeof e)||!!e},I.prototype.getConfig=function(e){return null==(e=e.config)?void 0:e[this.name]},I.prototype.exist=function(e){return-1===this.instances.indexOf(e)},I.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))},I.prototype.triggerOnNewAegis=function(e){var t;null!=(t=null==(t=this.option)?void 0:t.onNewAegis)&&t.call(this.option,e,this.getConfig(e))},I),te=new L({name:"offlineLog",onNewAegis:function(t){M(t),t.lifeCycle.on("onConfigChange",function(e){M(t)})}}),S="undefined"!=typeof weex&&(null===weex||void 0===weex?void 0:weex.requireModule("stream")),C=null==S?void 0:S.fetch,j=function(e){var t=e.ok,n=e.status,o=e.statusText,i=e.data,r=e.headers;return{ok:t,status:n,statusText:o,body:i,headers:r,clone:function(){return j(e)},text:function(){return new Promise(function(e){return e(i)})},json:function(){return new Promise(function(e,t){try{e(JSON.parse(i))}catch(e){t(new Error("response body is not JSON"))}})}}},A=[],_={},ne=weex,r=(n(t=U,S=V=r),t.prototype=null===S?Object.create(S):(ie.prototype=S.prototype,new ie),U.prototype.getPlatform=function(){var e=((null==(e=null==(e=null==(e=this.weex)?void 0:e.config)?void 0:e.env)?void 0:e.osName)||"").toLowerCase();return"android"===e?1:"ios"===e?2:100},U.prototype.initOfflineLog=function(){U.use(te)},Object.defineProperty(U.prototype,"getBean",{get:function(){var t=this;return Object.getOwnPropertyNames(this.bean).map(function(e){return e+"="+t.bean[e]}).join("&")},enumerable:!1,configurable:!0}),U.prototype.reportSpeed=function(e){var t,n,o,i,r;this.send({url:""+this.config.speedUrl,method:"post",data:(t=e,n=this.bean,i={fetch:[],static:[],bridge:[]},r={},Array.isArray(t)?t.forEach(function(e){var t;null!=(t=i[e.type])&&t.push(e)}):null!=(o=i[t.type])&&o.push(t),r.payload=JSON.stringify(u({duration:i},n)),r),contentType:"application/json",type:O.SPEED,log:e})},U.prototype.retcode=function(e){var t=this;"object"==typeof e?e.url?400<=Object.keys(_).length||(_[e.url]||(_[e.url]=0),_[e.url]+=1,3<_[e.url])||(e=Object.assign({},{url:"",isHttps:!0,method:"GET",type:"fetch",duration:0,ret:0,status:200},e),A.push(e),1===A.length&&setTimeout(function(){t.reportSpeed(A),A=[]},1e3)):console.error("param url can not be empty!"):console.error("retcode params should be an object")},U.prototype.uploadLogs=function(e,t){this.lifeCycle.emit("uploadLogs",e=void 0===e?{}:e,t=void 0===t?{}:t)},U.prototype.getOfflineLog=function(){},U.prototype.uploadOfflineLogs=function(e){},U.prototype.getCurrentPageUrl=function(e){e=e.pageUrl||(null==(e=null==(e=this.weex)?void 0:e.config)?void 0:e.bundleUrl)||"";return encodeURIComponent(e.slice(0,2048))},U.sessionID="session-"+Date.now(),U),S=new L({name:"aid",onNewAegis:function(t){var e,n=this;this.aid&&!0!==this.aid?(t.bean.aid=this.aid,t.config.aid=this.aid):e=setTimeout(function(){n.getAid(function(e){n.aid=e,t.bean.aid=n.aid,t.config.aid=n.aid}),clearTimeout(e)},0)},getAid:function(n){return s(this,void 0,void 0,function(){var t;return f(this,function(e){switch(e.label){case 0:return e.trys.push([0,2,,3]),[4,localStorage.getItem("AEGIS_ID")];case 1:return(t=e.sent())||(t="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)}),localStorage.setItem("AEGIS_ID",t)),null!=n&&n(t||""),[3,3];case 2:return e.sent(),null!=n&&n(""),[3,3];case 3:return[2]}})})}}),oe=new L({name:"onError",listening:!1,init:function(){this.startListen()},startListen:function(){var t=this;if(!this.listening){this.listening=!0;try{var n,e=Vue;void 0!==e&&e&&(n=e.config.errorHandler,e.config.errorHandler=function(e){e&&t.publishErrorLog({msg:e,level:b.ERROR}),"function"==typeof n&&n(e)})}catch(t){this.publishErrorLog({msg:t,level:b.ERROR})}}},publishErrorLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})}}),L=new L({name:"reportApiSpeed",override:!1,fetch:null,weexFetch:null,onNewAegis:function(e){var t,n;this.override||(this.override=!0,this.fetch=e.fetch,this.weexFetch=e.weexFetch,t=(n=this.overrideFetch(e.config)).fetch,n=n.weexFetch,e.fetch=t,e.weexFetch=n)},publishSpeed:function(t){this.$walk(function(e){e.speedLogPipeline(t)})},publishNormalLog:function(t){this.$walk(function(e){e.normalLogPipeline(t)})},overrideFetch:function(u){var e,t,l,n,f=this;if("function"==typeof this.fetch)return e=this.fetch,t=this.weexFetch,l=function(r,s,l,a){var c,e,t,n;g(l,u.hostUrl)||(c={url:l,isHttps:d(l),method:(null==a?void 0:a.method)||"get",duration:s,nextHopProtocol:"",type:"fetch",status:r.status},"function"==typeof(null==(n=u.api)?void 0:n.resourceTypeHandler)&&(e=null==(n=u.api)?void 0:n.resourceTypeHandler(r.url)),-1===D.indexOf(e)&&(n=r.headers&&r.headers.get("content-type")||"",e=r.ok&&(void 0===(t=n)&&(t=""),n=(void 0===l?"":l).split("?")[0],K.test(n)||W.some(function(e){return-1!==String(t).indexOf(e)}))?"static":"fetch"),"fetch"===e?r.clone().text().then(function(e){var t=function(e,t,n){var o,i;try{if("function"==typeof(null==t?void 0:t.retCodeHandler))return{code:void 0===(r=(i=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:i.isErr};"string"==typeof e&&(e=JSON.parse(e)),"function"==typeof(null==(o=null==t?void 0:t.ret)?void 0:o.join)&&($=[].concat(t.ret.map(function(e){return e.toLowerCase()})));var r,s=Object.getOwnPropertyNames(e).filter(function(e){return-1!==$.indexOf(e.toLowerCase())});return s.length?{code:""+(r=e[s[0]]),isErr:0!==r&&"0"!==r}:{code:"unknown",isErr:!1}}catch(e){return{code:"unknown",isErr:!1}}}(e,u.api,{url:r.url,ctx:r,payload:null==a?void 0:a.body})||{},n=t.code,t=t.isErr,o=null==(o=u.api)?void 0:o.apiDetail,i=o?h(null==a?void 0:a.body,null==(i=u.api)?void 0:i.reqParamHandler,{url:l}):"",e=o?h(e,null==(o=u.api)?void 0:o.resBodyHandler,{url:l}):"",o="req url: "+l+" \n \nres status: "+(r.status||0)+"\n \nres duration: "+s+"ms \n \nreq method: "+((null==a?void 0:a.method)||"get")+" \n \nreq param: "+i+" \n \nres retcode: "+n+"\n \nres data: "+e;f.publishNormalLog({msg:o,level:b.API_RESPONSE}),c.payload=null==a?void 0:a.body,c.ret=n,c.isErr=+t,t&&f.publishNormalLog({msg:o,level:b.RET_ERROR})}):Object.assign(c,{type:"static",urlQuery:(n=r.url,e=!0,"string"==typeof n?n.split("?")[e?1:0]||"":n),domainLookup:o.number,connectTime:o.number}),f.publishSpeed(c))},n=function(e,t,n,o){var i;throw g(n,u.hostUrl)||(i={url:n,isHttps:d(n),method:(null==o?void 0:o.method)||"get",duration:t,nextHopProtocol:"",type:"fetch",status:0},f.publishSpeed(i),i=null!=(i=u.api)&&i.apiDetail?h(null==o?void 0:o.body,null==(i=u.api)?void 0:i.reqParamHandler,{url:n}):"",n="AJAX_ERROR: "+e+"\n \nreq url: "+n+"\n \nres status: 0\n \nres duration: "+t+"ms\n \nreq method: "+((null==o?void 0:o.method)||"get")+"\n \nreq param: "+i,f.publishNormalLog({msg:n,level:b.AJAX_ERROR})),e},{fetch:function(o,i){var r=Date.now();return e(o,i).then(function(e){var t=Date.now()-r,n=e;try{l(n,t,o,i)}catch(e){}return e}).catch(function(e){var t=Date.now()-r;try{n(e,t,o,i)}catch(e){}throw e})},weexFetch:function(o,i,e){var r=o.url,s=Date.now();try{t(o,function(e){var t=Date.now()-s,n=j(e);try{l(n,t,r,o)}catch(e){}"function"==typeof i&&i(e)},e)}catch(i){e=Date.now()-s;try{n(i,e,r,o)}catch(o){}throw i}}}}});function U(e){var s,l=V.call(this,e)||this;l.weex=ne,l.originRequest=J,l.fetch=J,l.weexFetch=C,l.speedLogPipeline=y([(s=l.config,function(e,t){var n,o,i,r="number"==typeof s.repeat?s.repeat:60;!s.speedSample||r<=0?t(e):(n=(null==s?void 0:s.id)||"0",o=P[n]||{},Array.isArray(e)?(i=e.filter(function(e){var t=!o[e.url]||o[e.url]<r;return t?(o[e.url]=1+~~o[e.url],P[n]=o):E[n]||T(n),t})).length&&t(i):!o[e.url]||o[e.url]<r?(o[e.url]=1+~~o[e.url],P[n]=o,t(e)):E[n]||T(n))}),m(l),function(e,t){l.lifeCycle.emit("beforeReportSpeed",e);var n=l.config.beforeReportSpeed;if((e="function"==typeof n?e.filter(function(e){return!1!==n(e)}):e).length)return t(e)},function(e){l.reportSpeed(e)}]),l.request=function(o,i,r){var e,t,n,s;o&&"string"==typeof o.url&&""!==o.url&&l.bean.id&&(e=o.url,!1!==o.addBean&&(e=e+(-1===e.indexOf("?")?"?":"&")+l.getBean),("get"===(o.method||"get").toLocaleLowerCase()?l.originRequest((t=e,n=o.data,"string"!=typeof t?"":"object"==typeof n&&n?(s=Object.getOwnPropertyNames(n).map(function(e){var t=n[e];return e+"="+("string"==typeof t?encodeURIComponent(t):encodeURIComponent(JSON.stringify(t)))}).join("&").replace(/eval/gi,"evaI"),t+(-1===t.indexOf("?")?"?":"&")+s):t),u({method:"GET",headers:{}},o.requestConfig)):("string"==typeof o.data?o.data=o.data.replace(/eval/gi,"evaI"):o.data=JSON.stringify(o.data),l.originRequest(e,u({method:"POST",body:o.data,headers:o.contentType?{"Content-Type":o.contentType}:{}},o.requestConfig)))).then(function(e){var t,n;String(e.status).match(/^20\d+/g)?null!=i&&i(e):null!=r&&r(e),null!=(n=(t=l.config).reqCallback)&&n.call(t,e,o)}).catch(function(e){null!=r&&r(e)}))};try{e.offlineLog&&l.initOfflineLog(),l.init(e),l.extendBean("sessionId",U.sessionID),l.extendBean("platform",l.getPlatform()),l.extendBean("from",l.getCurrentPageUrl(e)),l.extendBean("referer",encodeURIComponent(e.referrer||""))}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 aegis-helper for feedback and thank you for your support.","color: red"),l.sendSDKError(e)}return l}function ie(){this.constructor=t}function I(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 N(e){var n,t,o,i,s,r,l,a,c,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:"",webVitalsUrl:"",eventUrl:"",setDataReportUrl:"",reportImmediately:!0},this.isWhiteList=!1,this.lifeCycle=new k,this.bean={},this.originFireUrl="",this.normalLogPipeline=y([m(this,5),B,function(e,t){var o=n.config;t(e=e.map(function(e){var t,n=o.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=w(e.msg).substring(0,o.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 o=(null==h?void 0:h.id)+"_error",i=P[o]||{};t(e.filter(function(e){if(e.level===b.ERROR||e.level===b.PROMISE_ERROR||e.level===b.AJAX_ERROR||e.level===b.SCRIPT_ERROR||e.level===b.IMAGE_ERROR||e.level===b.CSS_ERROR||e.level===b.MEDIA_ERROR||e.level===b.RET_ERROR||e.level===b.BRIDGE_ERROR||e.level===b.PAGE_NOT_FOUND_ERROR||e.level===b.WEBSOCKET_ERROR){e=e.msg.slice(0,200);if(i[e]>n)return E[o]||T(o),!1;i[e]=1+~~i[e],P[o]=i}return!0}))}),(p=this.lifeCycle.emit,d=this.config,function(e,t){var n,o=d.logCreated;return"function"==typeof o?(n=e.filter(function(e){return!1!==o(e)}),p("beforeWrite",n),t(n)):(p("beforeWrite",e),t(e))}),(f=this,setTimeout(function(){var e=f.config.pvUrl,n=void 0===e?"":e,e="undefined"!=typeof location?(null===location||void 0===location?void 0:location.pathname)+(null===location||void 0===location?void 0:location.hash):void 0;n&&e!==f.originFireUrl&&(f.sendPipeline([function(e,t){t({url:n,type:O.PV})}],O.PV)(null),e)&&location&&(f.originFireUrl=e)},100),function(e,t){t(e)}),(c=a=l=!1,u=[],(s=this).lifeCycle.on("onConfigChange",function(){r&&clearTimeout(r),r=setTimeout(function(){var e,n;!c&&s.config&&(c=!0,e=s.config.whiteListUrl,(n=void 0===e?"":e)&&s.sendPipeline([function(e,t){t({url:n,type:O.WHITE_LIST,success:function(e){a=!0;try{var t=e.data||JSON.parse(e),n=t.retcode,o=t.result,i=void 0===o?{}:o,r=(0===n&&(l=i.is_in_white_list,s.isWhiteList=l,0<=i.rate)&&i.rate<=1&&(s.config.random=i.rate,s.isGetSample=!1),s.isWhiteList&&u.length?Z(s)(u.splice(0),function(){}):!s.isWhiteList&&u.length&&(u.length=0),s.config.onWhitelist);"function"==typeof r&&r(l)}catch(e){}},fail:function(){a=!0}})}],O.WHITE_LIST)(null),c=!1)},s.config.uin?50:500)}),s.lifeCycle.on("destroy",function(){u.length=0}),function(e,t){var n;l||null!=(n=null==(n=s.config)?void 0:n.api)&&n.reportRequest?t(e.concat(u.splice(0)).map(function(e){return Y(e),e})):(n=e.filter(function(e){return e.level!==b.INFO&&e.level!==b.API_RESPONSE?(Y(e),!0):(a||(u.push(e),200<=u.length&&(u.length=200)),!1)})).length&&t(n)}),function(e,t){try{var n=JSON.parse(JSON.stringify(e)),o=(g.lifeCycle.emit("beforeReport",n),g.config.beforeReport);(e="function"==typeof o?e.filter(function(e){return!1!==o(e)}):e).length&&t(e)}catch(e){}},Z(this)]),this.eventPipeline=y([m(this,10),(i=this,function(e){i.sendPipeline([function(e,t){var n=e.map(function(e){return{name:e.name,ext1:e.ext1||i.config.ext1||"",ext2:e.ext2||i.config.ext2||"",ext3:e.ext3||i.config.ext3||""}});t({url:i.config.eventUrl+"?payload="+encodeURIComponent(JSON.stringify(n)),type:O.EVENT,log:e})}],O.EVENT)(e)})]),this.timeMap={},this.failRequestCount=0,this.customTimePipeline=y([m(this,10),(o=this,function(e){return o.sendPipeline([function(e,t){t({url:o.config.customTimeUrl+"?payload="+encodeURIComponent(JSON.stringify({custom:e})),type:O.CUSTOM,log:e})}],O.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),N.instances.push(this)}return r.use(oe),r.use(L),r.use(S),r});