/** * ============================================================================= * @tencent/aegis-web-sdk-v2@2.5.38 (c) 2025 TencentCloud Real User Monitoring. * Last Release Time Tue Mar 04 2025 18:53:30 GMT+0800 (China Standard Time). * Released under the MIT License. * ============================================================================= **/ !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,A;function _(e){this.name="__st"+(1e9*Math.random()>>>0)+N+"__",null!=e&&e.forEach(this.add,this),N+=1}Array.prototype.find||Object.defineProperty(Array.prototype,"find",{configurable:!0,writable:!0,value:function(e){if(null===this)throw new TypeError('"this" is null or not defined');var t=Object(this),n=t.length>>>0;if("function"!=typeof e)throw new TypeError("predicate must be a function");for(var r=arguments[1],o=0;oa[0]&&t[1]>e/4).toString(16)})}var v={generateTraceId:te(16),generateSpanId:te(8)},ee=Array(32);function te(t){return function(){for(var e=0;e<2*t;e++)ee[e]=Math.floor(16*Math.random())+48,58<=ee[e]&&(ee[e]+=39);return String.fromCharCode.apply(null,ee.slice(0,2*t))}}function ne(e){var t,n=["",""];return n="object"==typeof e&&(t=(e=function(e){for(var t=0,n=Object.keys(re);te)}),[2,o(r)]):(a=a.concat(i),p.hasNotFetched!==u.fetchSampleStatus?[3,2]:[4,s()]);case 1:return e.sent(),[2,o([])];case 2:return p.fetching===u.fetchSampleStatus?[2,o([])]:[2]}})})})}}},Oe={name:"throttle",create:function(n,r){var o,i=[],s=n.config;return n.event.on(b.destroy,function(){i.length=0}),function(t){return new Promise(function(e){if(i=i.concat(t),r&&i.length>=r||n.sendNow&&0n)&&delete o.action,j(j({},e),{plugin:s.name,aegisv2_goto:v.generateSpanId(),type:null!=(r=e.type)?r:K.NORMAL,level:null!=(n=e.level)?n:G.INFO,timestamp:t,snapshootInfo:d(j(j({},o),{type:null!=(r=e.type)?r:K.NORMAL,level:null!=(n=e.level)?n:G.INFO,plugin:s.name}))})}),[4,f(i.config.onCollected,i,t)]):[2,!1];case 1:return 0===(t=e.sent()).length?[2,!1]:((n=t.filter(le)).length&&i.event.emit(b.errorOccurred,n),null!=(c=this.option.pipes)&&c.length?(this.pipeline||(n=this.option.pipes.map(function(e){return s.wrapPipe(e,i)}),o=function(r){return U(s,void 0,void 0,function(){var t,n;return W(this,function(e){switch(e.label){case 0:return n=(t=Promise).resolve,[4,f(i.config.onBeforeProcess,i,r)];case 1:return[2,n.apply(t,[e.sent()])]}})})},r=function(r){return U(s,void 0,void 0,function(){var t,n;return W(this,function(e){switch(e.label){case 0:return n=(t=Promise).resolve,[4,f(i.config.onProcessed,i,r)];case 1:return[2,n.apply(t,[e.sent()])]}})})},n.unshift(o),n.push(r),o=function(t){return new Promise(function(e){i.send(t),e(t)})},n.push(o),this.pipeline=Se(n)),this.pipeline(t)):i.send(t),[2,!0])}})})},je.prototype.wrapPipe=function(t,e){var n,r,o,i;return"string"==typeof t?null!=(o=null==(o=e.pipes.find(function(e){return e.name===t}))?void 0:o.create(e))?o:Ae:(o=null!=(o=t)?o:{},n=o.name,r=o.option,o=o.create,"string"!=typeof n?t:(i=e.pipes.find(function(e){return e.name===n}),null!=(o=null!=(o=null==o?void 0:o(e,r))?o:null==i?void 0:i.create(e,r))?o:Ae))},je),He=new i({name:g.AID,aid:"",init:function(n){var r;return U(this,void 0,void 0,function(){var t;return W(this,function(e){switch(e.label){case 0:return e.trys.push([0,1,,3]),t=null==(r=n.config.plugin)?void 0:r.aid,(t="string"==typeof t?t:window.localStorage.getItem("AEGIS_ID"))||(t=M(),window.localStorage.setItem("AEGIS_ID",t)),this.aid=t,[3,3];case 1:return t=e.sent(),[4,n.sendSDKError({msg:l(t)})];case 2:return e.sent(),[3,3];case 3:return[2]}})})},onNewAegis:function(e){e.bean.aid=this.aid,e.config.aid=this.aid}}),Fe=(new i({name:g.ASSET_SPEED}),new i({name:g.ASSET_SPEED,pipes:["repeatLimit","networkRefresh"],collectCur:0,collectEntryType:"resource",ASSETS_INITIATOR_TYPE:["img","css","script","link","audio","video"],observer:null,onNewAegis:function(e){var t=this;_e()&&(this.collectSuccessLog(e),this.collectFailLog(e),performance.onresourcetimingbufferfull=function(){"function"==typeof performance.clearResourceTimings&&(t.collectCur=0,performance.clearResourceTimings())})},publishMany:function(e,t){for(var n=t.config,r=0,o=e.length;rr[1]?"poor":e>r[0]?"needs-improvement":"good",t(n))}}function Ke(e){requestAnimationFrame(function(){return requestAnimationFrame(function(){return e()})})}function Xe(e){document.addEventListener("visibilitychange",function(){"hidden"===document.visibilityState&&e()})}function Ve(e){var t=!1;return function(){t||(e(),t=!0)}}function Je(){return Ot<0&&(Ot=Tt(),Pt(),bt(function(){setTimeout(function(){Ot=Tt(),Pt()},0)})),{get firstHiddenTime(){return Ot}}}function ze(e){document.prerendering?addEventListener("prerenderingchange",function(){return e()},!0):e()}function Qe(i,s){s=s||{},ze(function(){var t,n=Je(),r=h("FCP"),o=Rt("paint",function(e){e.forEach(function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTimen.latency)&&(e?t.duration>e.latency?(e.entries=[t],e.latency=t.duration):t.duration===e.latency&&t.startTime===e.entries[0].startTime&&e.entries.push(t):(n={id:t.interactionId,latency:t.duration,entries:[t]},xt.set(n.id,n),S.push(n)),S.sort(function(e,t){return t.latency-e.latency}),10r&&f.isInFirstScreen(e.roots[t])&&(r=e.rootsDomNum[t],n=e.time,c.setFirstScreenInfo(a,n,e.roots[t]))}),d.length=0,Object.keys(p).forEach(function(e){p[e]=p[e].map(function(e){var t={tagName:e.tagName},n=e.attributes;if(!n)return e;for(var r=0;rn.value&&(n.value=r,n.entries=o,t())}var t,n=h("CLS",0),r=0,o=[],i=Rt("layout-shift",e);i&&(t=m(s,n,Lt,a.reportAllChanges),Xe(function(){e(i.takeRecords()),t(!0)}),bt(function(){n=h("CLS",r=0),t=m(s,n,Lt,a.reportAllChanges),Ke(function(){return t()})}),setTimeout(t,0))})),et(ot),ke(this.publishVitals.bind(this,e),!0)}catch(e){}var s,a,u,c,l,f},publishVitals:function(e){var t=this;setTimeout(function(){t.publish(j({type:K.WEB_VITALS,msg:"web_vitals"},Gt),e)},10)},destroy:function(){this.publish=function(){}}}),Xt=(new i({name:g.SPA}),new i({name:g.SPA,originFireUrl:"",onNewAegis:function(t){var e,n,r,o=this;this.sendPv=this.sendPv.bind(this),null!=(e=null==(e=t.config)?void 0:e.plugin)&&e.spa&&this.sendPv(t);try{null!=(n=Object.getOwnPropertyDescriptor(History.prototype,"pushState"))&&n.writable&&(history.pushState=this.wr("pushState")||history.pushState),null!=(r=Object.getOwnPropertyDescriptor(History.prototype,"replaceState"))&&r.writable&&(history.replaceState=this.wr("replaceState")||history.replaceState)}catch(t){}["replaceState","pushState","hashchange","popstate"].forEach(function(e){return window.addEventListener(e,function(){return o.sendPv.call(o,t)})})},wr:function(n){var r=history[n],e="__"+n+"__hasWrittenByTamSpa";return"function"==typeof r&&!history[e]&&(Object.defineProperty(history,e,{value:!0,enumerable:!1}),function(){var e=r.apply(this,arguments),t=null;return"function"==typeof Event?t=new Event(n):(t=document.createEvent("HTMLEvents")).initEvent(n,!1,!0),window.dispatchEvent(t),e})},sendPv:function(t){var n=this;setTimeout(function(){var e=location.pathname+location.hash+t.config.id;e&&e!==t.originFireUrl&&(t.updateSnapshootInfo({from:t.getCurrentPageUrl()}),t.timeOrigin=Date.now(),n.publish({msg:"spa",type:K.PV},t),t.originFireUrl=e)},0)},destroy:function(){this.sendPv=function(){}}})),Vt={name:"networkRefresh",create:function(r){return function(n){return new Promise(function(t){pt(function(e){r.extendBean({netType:e}),t(n)})})}}},o=(k(ft=R,o=lt=o),ft.prototype=null===o?Object.create(o):(Jt.prototype=o.prototype,new Jt),R.prototype.getCurrentPageUrl=function(){var e=this.config.pageUrl||location.href||"";return(e="function"==typeof this.config.urlHandler?this.config.urlHandler():e).slice(0,2048)},R.prototype.ready=function(){function i(){var e,n,r,o;t.reportRequestQueue.length&&(e=t.reportRequestQueue.splice(0,1)[0],n=e.options,r=e.success,o=e.fail,t.$request(n,function(){for(var e=[],t=0;tr.sampleMap[g.SESSION]&&n.stopSessionPlugin()}),function(e,t){n.publishSessionDataWithAegis({session_type:e,is_active:t,session_from:o},r)}),s=function(e){function t(e){void 0===e&&(e=!1),a=hn(),u=hn()+9e5,i(e),o=setInterval(r,1e3)}function n(){c()?u=hn()+9e5:t(!0)}function r(){c()||(s(),clearInterval(o))}var o,i=e.onCreateOrRebuild,s=e.onExpire,a=hn(),u=hn()+9e5,c=function(){return hn()-Number(a)<144e5&&hn()