spy-client 2.1.15 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/.travis.yml +7 -4
  2. package/AGENTS.md +132 -0
  3. package/README.md +27 -19
  4. package/dist/head/base.d.ts +27 -26
  5. package/dist/head/error.d.ts +6 -6
  6. package/dist/head/observer.d.ts +5 -5
  7. package/dist/head/whitescreen.d.ts +6 -6
  8. package/dist/lib/data.d.ts +6 -6
  9. package/dist/lib/huffman.d.ts +9 -9
  10. package/dist/lib/interface.d.ts +209 -209
  11. package/dist/lib/spyHeadInterface.d.ts +36 -36
  12. package/dist/lib/util.d.ts +22 -22
  13. package/dist/module/fid.d.ts +15 -15
  14. package/dist/module/layoutShift.d.ts +18 -18
  15. package/dist/module/lcp.d.ts +17 -17
  16. package/dist/module/longtask.d.ts +46 -46
  17. package/dist/module/memory.d.ts +11 -11
  18. package/dist/module/navigatorInfo.d.ts +9 -9
  19. package/dist/module/resource.d.ts +39 -39
  20. package/dist/module/timing.d.ts +11 -11
  21. package/dist/module/tti.d.ts +19 -19
  22. package/dist/spy-client-basic.d.ts +118 -118
  23. package/dist/spy-client-basic.esm.js +298 -298
  24. package/dist/spy-client-basic.iife.js +298 -298
  25. package/dist/spy-client-basic.iife.min.js +1 -1
  26. package/dist/spy-client-basic.js +298 -298
  27. package/dist/spy-client-basic.min.js +1 -1
  28. package/dist/spy-client-basic.mjs +298 -298
  29. package/dist/spy-client.d.ts +32 -32
  30. package/dist/spy-client.esm.js +1430 -1423
  31. package/dist/spy-client.iife.js +1430 -1423
  32. package/dist/spy-client.iife.min.js +1 -1
  33. package/dist/spy-client.js +1430 -1423
  34. package/dist/spy-client.min.js +1 -1
  35. package/dist/spy-client.mjs +1430 -1423
  36. package/dist/spy-head.d.ts +6 -6
  37. package/dist/spy-head.js +359 -358
  38. package/dist/spy-head.min.js +1 -1
  39. package/dist/spy-local-cache.d.ts +18 -18
  40. package/dist/spy-local-cache.js +718 -711
  41. package/dist/spy-local-cache.min.js +1 -1
  42. package/package.json +26 -73
  43. package/test-results/.last-run.json +4 -0
  44. package/karma.conf.js +0 -111
@@ -1 +1 @@
1
- var SpyClient=(()=>{var i=function(t,e){return(i=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,e){t.__proto__=e}:function(t,e){for(var i in e)e.hasOwnProperty(i)&&(t[i]=e[i])}))(t,e)},l=function(){return(l=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,arguments)};function o(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return(Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}).apply(this,t)}function M(t){var e,i=(t=>{if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}})(t),t=(i||((e=document.createElement("a")).href=t,i={protocol:e.protocol,host:e.host||location.host,pathname:e.pathname,ext:""}),i.pathname.split("."));return i.ext=t[t.length-1],i}function u(t){return+t.toFixed(1)}function d(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}var t=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",N=t&&t[2]&&+t[2]<14;function f(t){console.error("[SpyClient_log]".concat(t))}function s(i){return Object.keys(i).map(function(t){var e=i[t];return void 0===e?e="":"string"!=typeof e&&(e=JSON.stringify(e)),encodeURIComponent(t)+"="+encodeURIComponent(e)}).join("&")}function a(t){return"[object Array]"===Object.prototype.toString.call(t)}function e(t){if(this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}e.prototype.handle=function(t){if(this.check(t)){if(t=o({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},e.prototype.send=function(t,e){void 0===e&&(e=!1);for(var i=[],o=0,n=a(t)?t:[t];o<n.length;o++){var r=n[o];(r=this.handle(r))&&(i.push(r),e||(r=this.option.logServer+s(r),this.request(r)))}e&&this.sendPost(i)},e.prototype.check=function(t){if(this.option.check){var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return f("type only is one of "+e.join(", ")),!1;if(t.group&&30<t.group.length)return f("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return f("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return f("info.".concat(r," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(30<s.length)return f("info.".concat(r," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof s)return f("info.".concat(r," value must be number")),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return f("dim key [".concat(h,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var p=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(p))return f("dim.".concat(h," value [").concat(p,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}}return!0},e.prototype.sendPerf=function(t){this.send(o({type:"perf"},t))},e.prototype.sendExcept=function(t){this.send(o({type:"except"},t))},e.prototype.sendDist=function(t){this.send(o({type:"dist"},t))},e.prototype.sendCount=function(t){this.send(o({type:"count"},t))},e.prototype.sendExceptForError=function(t,e){var i=o({},e);i.info=o({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(i)},e.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},e.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},e.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},e.prototype.getAllMark=function(){for(var t={},e=0,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},e.prototype.clearAllMark=function(){this.markCache={}},e.prototype.sendPost=function(t){var e=(a(t)?t:[t])[0],e={pid:e.pid,type:e.type,group:e.group},e=this.option.logServer+s(e);this.request(e,t)},e.prototype.request=function(t,e){!N&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},e.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):f("Global fetch method doesn't exist")},t=e;var n=window.__spyHead,r="first-input",_=(c.prototype.listenFID=function(t){this.cb=t,this.callCB()},c.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},c.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},c.prototype.handle=function(t){t=t.pop();t&&(this.finalValue=t.duration,this.callCB(),this.destroy())},c);function c(){var e=this;if(this.observer=null,window.PerformanceObserver){n&&n.entryMap&&n.entryMap[r]&&this.handle(n.entryMap[r]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[r]})}catch(t){}}}var h=window.__spyHead,p="layout-shift",q=(g.prototype.listenLayoutShift=function(t){this.cb=t},g.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},g.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},g.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},g.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},g);function g(){var e=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){h&&h.entryMap&&h.entryMap[p]&&this.handle(h.entryMap[p]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[p]})}catch(t){}}}var m={},v=window.__spyHead,y="largest-contentful-paint",F=(b.prototype.listenLCP=function(t){this.cb=t,this.callCB()},b.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},b.prototype.load=function(){var t,e;this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,t="lcp",e=this.value,m[t]=e,this.callCB(),this.destroy()},b.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},b.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime})},b);function b(){var e=this;if(this.observer=null,window.PerformanceObserver){v&&v.entryMap&&v.entryMap[y]&&this.handle(v.entryMap[y]);try{this.observer=new PerformanceObserver(function(t){e.handle(t.getEntries())}),this.observer.observe({entryTypes:[y]})}catch(t){}}}function A(t){return t.name.indexOf(".gif?")<0}k.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},k.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest)&&(this.filterRequest=e.filterRequest)},k.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},k.prototype.ttiCheck=function(){var t,e;!this.cb||(e=performance.now())-this.lastLongTask<this.interval||!1===(t=this.getNetworkSilenceAt())||e-t<this.interval||(clearTimeout(this.ttiTimer),e=(e=this.lastLongTask)||performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart,this.stopObserveLongTask(),this.cb({tti:e}))},k.prototype.observerCallback=function(t){t=t.getEntries(),t=t[t.length-1];this.lastLongTask=t.startTime+t.duration},k.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},k.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;t<o.responseEnd&&(t=o.responseEnd)}return t},k.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}};var D=k;function k(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=A,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}w.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},w.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},w.prototype.getMetric=function(){var t,i={},e=window.performance.timing,o=e.navigationStart;return i.dns=e.domainLookupEnd-e.domainLookupStart,i.tcp=e.connectEnd-e.connectStart,i.request=e.responseStart-e.requestStart,i.response=e.responseEnd-e.responseStart,i.parseHtml=e.domInteractive-e.domLoading,i.domReady=e.domContentLoadedEventEnd-o,i.loadEventHandle=e.loadEventEnd-e.loadEventStart,i.load=e.loadEventEnd-o,performance.getEntriesByType&&(t=performance.getEntriesByType("paint"))&&t.length&&t.forEach(function(t){var e=t.name,t=Math.ceil(t.duration+t.startTime);"first-paint"===e&&(i.fp=t),"first-contentful-paint"===e&&(i.fcp=t)}),e.domFirstPaint&&(i.t7FirstPaint=e.domFirstPaint-o),e.domFirstScreenPaint&&(i.t7FirstScreen=e.domFirstScreenPaint-o),i};var L,S,J=w;function w(){}(E=L=L||{}).JS="js",E.CSS="css",E.IMG="img",E.FONT="font",(E=S=S||{})[E.ttf=0]="ttf",E[E.eot=1]="eot",E[E.woff=2]="woff",E[E.woff2=3]="woff2";var V=["/mwb2.gif"];function T(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(-1<t.indexOf(n))return 1}}function C(t){return+t.toFixed(1)}O.prototype.check=function(){return performance&&performance.getEntriesByType},O.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=o(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},O.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=o(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},O.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=o(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},O.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=o(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},O.prototype.report=function(){var t,p=this,e=this.getMetric();e&&(t=e.metric,e=e.hostMetric,this.cb)&&this.cb(t,e),this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.bigImgList);t<e.length;t++)for(var i=e[t],o=0,n=p.bigImgList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('img[src="'+s.name+'"]');p.bigImgCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var t=0,e=Object.keys(p.httpResList);t<e.length;t++)for(var i=e[t],o=0,n=p.httpResList[i];o<n.length;o++){var r=n[o],s=r.timing,r=r.type;try{var a=document.body.querySelector('[src="'+s.name+'"]');p.httpResCB({msg:s.name,dur:s.duration,xpath:d(a).xpath,host:i,type:r})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var t,e=0,i=Object.keys(p.slowList);e<i.length;e++)for(var o=i[e],n=0,r=p.slowList[o];n<r.length;n++){var s=r[n],a=s.timing,s=s.type;try{var c=document.body.querySelector('[src="'+a.name+'"]'),h={wait:u((t=a).domainLookupStart-(t.navigationStart||t.fetchStart||t.startTime)),dns:u(t.domainLookupEnd-t.domainLookupStart),connect:u(t.connectEnd-t.connectStart),req:u(t.responseStart-t.requestStart),res:u(t.responseEnd-t.responseStart)};p.slowResCB(l(l({},h),{dur:a.duration,msg:a.name,xpath:d(c).xpath,host:o,type:s}))}catch(t){console.error(t)}}})},O.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},O.prototype.leave=function(){"leave"===this.trigger&&this.report()},O.prototype.push=function(t,e,i,o){T(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),T(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},O.prototype.pushWithHost=function(t,e,i,o){o=o.host;e[o]||(e[o]=[]),e[o].push({timing:i,type:t})},O.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||T(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},O.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},O.prototype.addResFromCss=function(t,e){e.ext&&S.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},O.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},O.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!T(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},O.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var o=t[i],n=M(o.name);if(!T(n.pathname,V))switch(t[i].initiatorType){case"script":this.addScript(o,n);break;case"css":this.addResFromCss(o,n);break;case"img":this.addImg(o,n);break;case"link":this.addLink(o,n);break;case"audio":this.collectHttpResInHttps("audio",o,n);break;case"video":this.collectHttpResInHttps("video",o,n)}}},O.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",t=t+"Duration",a=(i[o]=0,i[n]=0,i[r]=0);return e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,a+=t.duration}),i[t]=C(0<i[o]?a/i[o]:0),i[n]&&(i[s]=C(0<=(e=i[n]-i[r])?100*e/i[n]:0)),i[n]=C(i[n]),i[r]=C(i[r]),i},O.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],e=performance.getEntriesByType("resource");if(t&&e&&e.length){this.handleTimings(e);for(var e=l(l(l(l({},this.getNumAndSize(L.JS,this.jsList)),this.getNumAndSize(L.CSS,this.cssList)),this.getNumAndSize(L.IMG,this.imgList)),this.getNumAndSize(L.FONT,this.fontList)),i=(e.docSize=C(t.decodedBodySize/1024),e.docTransferSize=C(t.transferSize/1024),e.headerSize=C((t.transferSize-t.encodedBodySize||0)/1024),e.allSize=C(e.docSize+e.jsSize+e.cssSize+e.imgSize+e.fontSize),e.allTransferSize=C(e.docTransferSize+e.jsTransferSize+e.cssTransferSize+e.imgTransferSize+e.fontTransferSize),{}),o=0,n=Object.keys(this.hostList);o<n.length;o++){var r=n[o],s=this.hostList[r].map(function(t){return t.timing});i[r]=this.getNumAndSize("host",s)}return{metric:e,hostMetric:i}}};var Z=O;function O(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}var B=null,W=(window.performance&&window.performance.memory&&(B=window.performance.memory),R.prototype.listenMemory=function(t){this.cb=t},R.prototype.leave=function(){var t;!this.onceLeave&&B&&(this.onceLeave=!0,(t=window.performance.memory).usedJSHeapSize===B.usedJSHeapSize&&t.totalJSHeapSize===B.totalJSHeapSize||(t=window.performance.memory,this.cb&&this.cb({usedJSHeapSize:t.usedJSHeapSize/1024,totalJSHeapSize:t.totalJSHeapSize/1024,jsHeapSizeLimit:t.jsHeapSizeLimit/1024,usedJSHeapRate:100*t.usedJSHeapSize/t.totalJSHeapSize})))},R);function R(){this.onceLeave=!1}I.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},I.prototype.load=function(){};var U=I;function I(){}var G,z,E,P=window.__spyHead,j="longtask",$=(x.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},x.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},x.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},x.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},x.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},x.prototype.load=function(){var e,i=this;this.check()&&(e=this.getStatData(Date.now()),setTimeout(function(){var t;i.loadCB&&i.loadCB({loadLongtaskTime:e.time,loadTBT:e.tbt,loadTotalTime:e.totalTime,loadLongtaskRate:e.rate,loadLongtaskNum:e.num}),performance.timing&&performance.timing.domFirstScreenPaint&&(t=i.getStatData(performance.timing.domFirstScreenPaint),i.fspCB)&&i.fspCB({fspLongtaskTime:t.time,fspTBT:t.tbt,fspTotalTime:t.totalTime,fspLongtaskRate:t.rate,fspLongtaskNum:t.num}),m.lcp&&(t=i.getStatData(performance.timing.navigationStart+m.lcp),i.lcpCB)&&i.lcpCB({lcpLongtaskTime:t.time,lcpTBT:t.tbt,lcpTotalTime:t.totalTime,lcpLongtaskRate:t.rate,lcpLongtaskNum:t.num})},200))},x.prototype.leave=function(){var t;this.onceLeave||(this.onceLeave=!0,t=this.getStatData(Date.now()),this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum}))},x.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},x.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var h=this.lts[c],p=h.duration;e+h.startTime+p<t&&(i+=p,o+=0<p-50?p-50:0,n++,h.attribution)&&h.attribution[0]&&(h=h.attribution[0].containerSrc)&&h!==location.href&&(a[h]||(a[h]=[]),a[h].push(p),r+=p,s++)}var l=t-e;return{num:n,time:i,tbt:o,totalTime:l,rate:100*i/l,iframeTime:r,iframeNum:s,iframeRate:100*r/l,iframeLongtasks:a}},x);function x(){var e=this;this.lts=[],this.observer=null,this.onceLeave=!1,P&&P.entryMap&&P.entryMap[j]&&(this.lts=this.lts.concat(P.entryMap[j]));try{this.observer=new PerformanceObserver(function(t){e.lts=e.lts.concat(t.getEntries())}),this.observer.observe({entryTypes:[j]})}catch(t){}}function K(){this.constructor=z}function H(t){t=G.call(this,t)||this;return t.modules=[],t.register(new _),t.register(new F),t.register(new q),t.register(new D),t.register(new J),t.register(new Z),t.register(new W),t.register(new U),t.register(new $),t.visibilitychangeCB=t.visibilitychangeCB.bind(t),t.load=t.load.bind(t),t.leave=t.leave.bind(t),"complete"===document.readyState?t.load():window.addEventListener("load",t.load),document.addEventListener("visibilitychange",t.visibilitychangeCB),window.addEventListener("beforeunload",t.leave,!1),window.addEventListener("unload",t.leave,!1),t.handleHead(),t}return i(z=H,E=G=t),z.prototype=null===E?Object.create(E):(K.prototype=E.prototype,new K),H.prototype.handleHead=function(){var e=this;if(this.option.localCache){var t=window.__spyHead;if(t&&t.winerrors){for(var i=0;i<t.winerrors.length;i++){var o=t.winerrors[i];this.option.localCache.addLog(o)}t.interceptor=function(t){e.option.localCache.addLog(t)}}}},H.prototype.listenFID=function(t){this.invoke("listenFID",t)},H.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},H.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},H.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},H.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},H.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},H.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},H.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},H.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},H.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},H.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},H.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},H.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},H.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},H.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},H.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},H.prototype.register=function(t){this.modules.push(t)},H.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},H.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},H.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},H.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},H})();
1
+ var SpyClient=function(){"use strict";var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};var e=function(){return e=Object.assign||function(t){for(var e,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t},e.apply(this,arguments)};function i(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var i=Object.assign||function(t){for(var e=void 0,i=1,o=arguments.length;i<o;i++)for(var n in e=arguments[i])Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t};return i.apply(null,t)}function o(t){var e=function(t){if(URL&&t)try{var e=new URL(t);if(void 0!==e.host)return{protocol:e.protocol,host:e.host,pathname:e.pathname,ext:""}}catch(t){console.error(t)}}(t);if(!e){var i=document.createElement("a");i.href=t,e={protocol:i.protocol,host:i.host||location.host,pathname:i.pathname,ext:""}}var o=e.pathname.split(".");return e.ext=o[o.length-1],e}function n(t){return+t.toFixed(1)}function r(t){return{wait:n(t.domainLookupStart-(t.navigationStart||t.fetchStart||t.startTime)),dns:n(t.domainLookupEnd-t.domainLookupStart),connect:n(t.connectEnd-t.connectStart),req:n(t.responseStart-t.requestStart),res:n(t.responseEnd-t.responseStart)}}function s(t){if(!t)return{xpath:""};for(var e=[];t&&1===t.nodeType&&t!==t.parentNode;){var i=t.tagName.toLowerCase();if(t.getAttribute("id")?i+="[#"+t.getAttribute("id")+"]":t.classList&&t.classList.length&&(i+="[."+t.classList[t.classList.length-1]+"]"),e.push(i),t===document.body)break;t=t.parentNode}return{xpath:e.join("<")}}"function"==typeof SuppressedError&&SuppressedError;var a=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase().match(/cpu iphone os (.*?)_/):"",c=a&&a[2]&&+a[2]<14;function p(t){console.error("[SpyClient_log]".concat(t))}function h(t){return Object.keys(t).map(function(e){var i=t[e];return void 0===i?i="":"string"!=typeof i&&(i=JSON.stringify(i)),encodeURIComponent(e)+"="+encodeURIComponent(i)}).join("&")}function l(t){return"[object Array]"===Object.prototype.toString.call(t)}var u=function(){function t(t){if(this.sample={},this.markCache={},!t.pid)throw new Error("pid is required");this.option={pid:t.pid,lid:t.lid,check:!1!==t.check,sample:t.sample,localCache:t.localCache,logServer:t.logServer||"https://sp1.baidu.com/5b1ZeDe5KgQFm2e88IuM_a/mwb2.gif?"}}return t.prototype.handle=function(t){if(this.check(t)){if(t=i({pid:this.option.pid,lid:this.option.lid,ts:Date.now(),group:"common"},t),this.option.localCache&&this.option.localCache.addLog(t),"number"==typeof t.sample){if(Math.random()>t.sample)return}else if("number"==typeof this.option.sample&&Math.random()>this.option.sample)return;return delete t.sample,t}},t.prototype.send=function(t,e){void 0===e&&(e=!1);for(var i=[],o=0,n=l(t)?t:[t];o<n.length;o++){var r=n[o];if((r=this.handle(r))&&(i.push(r),!e)){var s=this.option.logServer+h(r);this.request(s)}}e&&this.sendPost(i)},t.prototype.check=function(t){if(!this.option.check)return!0;var e=["perf","except","dist","count"];if(-1===e.indexOf(t.type))return p("type only is one of "+e.join(", ")),!1;if(t.group&&t.group.length>30)return p("group length execeeds 30"),!1;var i=/^[a-zA-Z0-9-_]{0,30}$/;if("except"===t.type){if("string"!=typeof t.info.msg||!t.info.msg.length)return p("info.msg field must be not empty and is String"),!1}else for(var o=0,n=Object.keys(t.info);o<n.length;o++){var r=n[o];if(!i.test(r))return p("info.".concat(r," is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var s=t.info[r];if("dist"===t.type){if(s.length>30)return p("info.".concat(r," value length execeeds 30 when type == 'dist'")),!1}else if("number"!=typeof s)return p("info.".concat(r," value must be number")),!1}if(t.dim)for(var a=0,c=Object.keys(t.dim);a<c.length;a++){var h=c[a];if(!i.test(h))return p("dim key [".concat(h,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_"),!1;var l=t.dim[h];if(!/^[a-zA-Z0-9\-_\*\.\s\/#\+@\&\u4e00-\u9fa5]{0,30}$/.test(l))return p("dim.".concat(h," value [").concat(l,"] is unexpected. ")+"Length must be not more than 30. Supported chars: a-zA-Z0-9-_*. /#+@& and Chinese"),!1}return!0},t.prototype.sendPerf=function(t){this.send(i({type:"perf"},t))},t.prototype.sendExcept=function(t){this.send(i({type:"except"},t))},t.prototype.sendDist=function(t){this.send(i({type:"dist"},t))},t.prototype.sendCount=function(t){this.send(i({type:"count"},t))},t.prototype.sendExceptForError=function(t,e){var o=i({},e);o.info=i({},e.info||{},{msg:t.message,stack:t.stack}),this.sendExcept(o)},t.prototype.startMark=function(t){this.markCache[t]={start:Date.now()}},t.prototype.endMark=function(t){return this.markCache[t]?(this.markCache[t].total=Date.now()-this.markCache[t].start,this.markCache[t].total):0},t.prototype.clearMark=function(t){this.markCache[t]&&delete this.markCache[t]},t.prototype.getAllMark=function(){for(var t={},e=0,i=Object.keys(this.markCache);e<i.length;e++){var o=i[e];t[o]=this.markCache[o].total}return t},t.prototype.clearAllMark=function(){this.markCache={}},t.prototype.sendPost=function(t){var e=(l(t)?t:[t])[0],i={pid:e.pid,type:e.type,group:e.group},o=this.option.logServer+h(i);this.request(o,t)},t.prototype.request=function(t,e){!c&&navigator&&navigator.sendBeacon&&navigator.sendBeacon(t,e?JSON.stringify(e):void 0)||(e?this.fetch(t,e):(new Image).src=t)},t.prototype.fetch=function(t,e){fetch?fetch(t,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}):p("Global fetch method doesn't exist")},t}(),f=window.__spyHead,d="first-input",g=function(){function t(){var t=this;if(this.observer=null,window.PerformanceObserver){f&&f.entryMap&&f.entryMap[d]&&this.handle(f.entryMap[d]);try{this.observer=new PerformanceObserver(function(e){t.handle(e.getEntries())}),this.observer.observe({entryTypes:[d]})}catch(t){}}}return t.prototype.listenFID=function(t){this.cb=t,this.callCB()},t.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({fid:this.finalValue})},t.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},t.prototype.handle=function(t){var e=t.pop();e&&(this.finalValue=e.duration,this.callCB(),this.destroy())},t}(),m=window.__spyHead,v="layout-shift",y=function(){function t(){var t=this;if(this.observer=null,this.onceLeave=!1,window.PerformanceObserver){m&&m.entryMap&&m.entryMap[v]&&this.handle(m.entryMap[v]);try{this.observer=new PerformanceObserver(function(e){t.handle(e.getEntries())}),this.observer.observe({entryTypes:[v]})}catch(t){}}}return t.prototype.listenLayoutShift=function(t){this.cb=t},t.prototype.leave=function(){this.onceLeave||(this.onceLeave=!0,this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,this.callCB(),this.destroy())},t.prototype.callCB=function(){void 0!==this.finalValue&&this.cb&&this.cb({layoutShift:this.finalValue})},t.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},t.prototype.handle=function(t){var e=this;t.map(function(t){t.hadRecentInput||(e.value=(e.value||0)+(t.value||0))})},t}(),b={};function k(t){return b[t]}var S=window.__spyHead,w="largest-contentful-paint",L=function(){function t(){var t=this;if(this.observer=null,window.PerformanceObserver){S&&S.entryMap&&S.entryMap[w]&&this.handle(S.entryMap[w]);try{this.observer=new PerformanceObserver(function(e){t.handle(e.getEntries())}),this.observer.observe({entryTypes:[w]})}catch(t){}}}return t.prototype.listenLCP=function(t){this.cb=t,this.callCB()},t.prototype.callCB=function(){this.finalValue&&this.cb&&this.cb({lcp:this.finalValue})},t.prototype.load=function(){var t,e;this.observer&&this.observer.takeRecords&&this.observer.takeRecords(),this.finalValue=this.value,t="lcp",e=this.value,b[t]=e,this.callCB(),this.destroy()},t.prototype.destroy=function(){this.observer&&this.observer.disconnect(),this.observer=null},t.prototype.handle=function(t){var e=this;t.map(function(t){e.value=t.renderTime||t.loadTime||0})},t}();function T(t){return t.name.indexOf(".gif?")<0}var C,O,B=function(){function t(){this.lastLongTask=0,this.observer=null,this.interval=5e3,this.filterRequest=T,this.observerCallback=this.observerCallback.bind(this),this.ttiCheck=this.ttiCheck.bind(this)}return t.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},t.prototype.listenTTI=function(t,e){this.check()&&(this.observeLongtask(2e4),this.cb=t,(e=e||{}).interval&&(this.interval=e.interval),e.filterRequest&&(this.filterRequest=e.filterRequest))},t.prototype.load=function(){this.check()&&(this.ttiTimer=setInterval(this.ttiCheck,this.interval))},t.prototype.ttiCheck=function(){if(this.cb){var t=performance.now();if(!(t-this.lastLongTask<this.interval)){var e=this.getNetworkSilenceAt();if(!1!==e&&!(t-e<this.interval)){clearTimeout(this.ttiTimer);var i=this.lastLongTask;i||(i=performance.timing.domContentLoadedEventEnd-performance.timing.navigationStart),this.stopObserveLongTask(),this.cb({tti:i})}}}},t.prototype.observerCallback=function(t){var e=t.getEntries(),i=e[e.length-1];this.lastLongTask=i.startTime+i.duration},t.prototype.stopObserveLongTask=function(){this.observer&&(this.observer.disconnect(),this.observer=null),this.stopLongTaskTimeoutId&&clearTimeout(this.stopLongTaskTimeoutId)},t.prototype.getNetworkSilenceAt=function(){for(var t=0,e=0,i=performance.getEntriesByType("resource").filter(this.filterRequest);e<i.length;e++){var o=i[e];if(!o.responseEnd)return!1;o.responseEnd>t&&(t=o.responseEnd)}return t},t.prototype.observeLongtask=function(t){this.stopObserveLongTask();try{this.observer=new PerformanceObserver(this.observerCallback),this.observer.observe({entryTypes:["longtask"]}),this.stopLongTaskTimeoutId=setTimeout(this.stopObserveLongTask,t)}catch(t){}},t}(),R=function(){function t(){}return t.prototype.listenTiming=function(t){window.performance&&window.performance.timing&&(this.cb=t)},t.prototype.load=function(){var t=this;setTimeout(function(){t.cb&&t.cb(t.getMetric())},500)},t.prototype.getMetric=function(){var t={},e=window.performance.timing,i=e.navigationStart;if(t.dns=e.domainLookupEnd-e.domainLookupStart,t.tcp=e.connectEnd-e.connectStart,t.request=e.responseStart-e.requestStart,t.response=e.responseEnd-e.responseStart,t.parseHtml=e.domInteractive-e.domLoading,t.domReady=e.domContentLoadedEventEnd-i,t.loadEventHandle=e.loadEventEnd-e.loadEventStart,t.load=e.loadEventEnd-i,performance.getEntriesByType){var o=performance.getEntriesByType("paint");o&&o.length&&o.forEach(function(e){var i=e.name,o=e.duration,n=e.startTime,r=Math.ceil(o+n);"first-paint"===i&&(t.fp=r),"first-contentful-paint"===i&&(t.fcp=r)})}return e.domFirstPaint&&(t.t7FirstPaint=e.domFirstPaint-i),e.domFirstScreenPaint&&(t.t7FirstScreen=e.domFirstScreenPaint-i),t},t}();!function(t){t.JS="js",t.CSS="css",t.IMG="img",t.FONT="font"}(C||(C={})),function(t){t[t.ttf=0]="ttf",t[t.eot=1]="eot",t[t.woff=2]="woff",t[t.woff2=3]="woff2"}(O||(O={}));var I=["/mwb2.gif"];function z(t,e){for(var i=0,o=e;i<o.length;i++){var n=o[i];if(t.indexOf(n)>-1)return!0}return!1}function E(t){return+t.toFixed(1)}var P=function(){function t(){this.trigger="load",this.jsList=[],this.cssList=[],this.imgList=[],this.fontList=[],this.hostList={},this.bigImgList={},this.httpResList={},this.slowList={},this.resOption={ignorePaths:[],trigger:"load"},this.bigImgOption={ignorePaths:[],maxSize:153600,trigger:"load"},this.httpResOption={ignorePaths:[],trigger:"load"},this.slowOption={ignorePaths:[],trigger:"load",threshold:1e3}}return t.prototype.check=function(){return performance&&performance.getEntriesByType},t.prototype.listenResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.resOption=i(this.resOption,e),this.trigger=this.resOption.trigger,this.cb=t)},t.prototype.listenBigImg=function(t,e){void 0===e&&(e={}),this.check()&&(this.bigImgOption=i(this.bigImgOption,e),this.trigger=this.bigImgOption.trigger,this.bigImgCB=t)},t.prototype.listenHttpResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.httpResOption=i(this.httpResOption,e),this.trigger=this.httpResOption.trigger,this.httpResCB=t)},t.prototype.listenSlowResource=function(t,e){void 0===e&&(e={}),this.check()&&(this.slowOption=i(this.slowOption,e),this.trigger=this.slowOption.trigger,this.slowResCB=t)},t.prototype.report=function(){var t=this,i=this.getMetric();if(i){var o=i.metric,n=i.hostMetric;this.cb&&this.cb(o,n)}this.bigImgCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.bigImgList).length&&window.requestIdleCallback(function(){for(var e=0,i=Object.keys(t.bigImgList);e<i.length;e++)for(var o=i[e],n=0,r=t.bigImgList[o];n<r.length;n++){var a=r[n],c=a.timing,p=a.type;try{var h=document.body.querySelector('img[src="'+c.name+'"]');t.bigImgCB({msg:c.name,dur:c.duration,xpath:s(h).xpath,host:o,type:p})}catch(t){console.error(t)}}}),this.httpResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.httpResList).length&&window.requestIdleCallback(function(){for(var e=0,i=Object.keys(t.httpResList);e<i.length;e++)for(var o=i[e],n=0,r=t.httpResList[o];n<r.length;n++){var a=r[n],c=a.timing,p=a.type;try{var h=document.body.querySelector('[src="'+c.name+'"]');t.httpResCB({msg:c.name,dur:c.duration,xpath:s(h).xpath,host:o,type:p})}catch(t){console.error(t)}}}),this.slowResCB&&"function"==typeof window.requestIdleCallback&&Object.keys(this.slowList).length&&window.requestIdleCallback(function(){for(var i=0,o=Object.keys(t.slowList);i<o.length;i++)for(var n=o[i],a=0,c=t.slowList[n];a<c.length;a++){var p=c[a],h=p.timing,l=p.type;try{var u=document.body.querySelector('[src="'+h.name+'"]'),f=r(h);t.slowResCB(e(e({},f),{dur:h.duration,msg:h.name,xpath:s(u).xpath,host:n,type:l}))}catch(t){console.error(t)}}})},t.prototype.load=function(){var t=this;"load"===this.trigger&&this.check()&&setTimeout(function(){t.report()},500)},t.prototype.leave=function(){"leave"===this.trigger&&this.report()},t.prototype.push=function(t,e,i,o){z(o.pathname,this.resOption.ignorePaths||[])||(e.push(i),this.pushWithHost(t,this.hostList,i,o)),z(o.pathname,this.slowOption.ignorePaths||[])||i.duration>this.slowOption.threshold&&this.pushWithHost(t,this.slowList,i,o)},t.prototype.pushWithHost=function(t,e,i,o){var n=o.host;e[n]||(e[n]=[]),e[n].push({timing:i,type:t})},t.prototype.collectHttpResInHttps=function(t,e,i){"https:"!==location.protocol||0!==e.name.indexOf("http://")||z(i.pathname,this.httpResOption.ignorePaths||[])||this.pushWithHost(t,this.httpResList,e,i)},t.prototype.addScript=function(t,e){"js"===e.ext&&0!==t.decodedBodySize&&this.push("js",this.jsList,t,e)},t.prototype.addResFromCss=function(t,e){e.ext&&O.hasOwnProperty(e.ext)?this.push("font",this.fontList,t,e):this.addImg(t,e)},t.prototype.addLink=function(t,e){"css"===e.ext?this.push("css",this.cssList,t,e):"js"===e.ext&&this.push("js",this.jsList,t,e)},t.prototype.addImg=function(t,e){this.push("img",this.imgList,t,e),t.decodedBodySize>(this.bigImgOption.maxSize||0)&&!z(e.pathname,this.bigImgOption.ignorePaths||[])&&this.pushWithHost("img",this.bigImgList,t,e)},t.prototype.handleTimings=function(t){for(var e=t.length,i=0;i<e;i++){var n=t[i],r=o(n.name);if(!z(r.pathname,I))switch(t[i].initiatorType){case"script":this.addScript(n,r);break;case"css":this.addResFromCss(n,r);break;case"img":this.addImg(n,r);break;case"link":this.addLink(n,r);break;case"audio":this.collectHttpResInHttps("audio",n,r);break;case"video":this.collectHttpResInHttps("video",n,r)}}},t.prototype.getNumAndSize=function(t,e){var i={},o=t+"Num",n=t+"Size",r=t+"TransferSize",s=t+"CacheRate",a=t+"Duration";i[o]=0,i[n]=0,i[r]=0;var c=0;if(e.forEach(function(t){i[o]++,i[n]+=t.decodedBodySize/1024,i[r]+=t.transferSize/1024,c+=t.duration}),i[a]=E(i[o]>0?c/i[o]:0),i[n]){var p=i[n]-i[r];i[s]=E(p>=0?100*p/i[n]:0)}return i[n]=E(i[n]),i[r]=E(i[r]),i},t.prototype.getMetric=function(){var t=performance.getEntriesByType("navigation")[0],i=performance.getEntriesByType("resource");if(t&&i&&i.length){this.handleTimings(i);var o=e(e(e(e({},this.getNumAndSize(C.JS,this.jsList)),this.getNumAndSize(C.CSS,this.cssList)),this.getNumAndSize(C.IMG,this.imgList)),this.getNumAndSize(C.FONT,this.fontList)),n=t;o.docSize=E(n.decodedBodySize/1024),o.docTransferSize=E(n.transferSize/1024),o.headerSize=E((n.transferSize-n.encodedBodySize||0)/1024),o.allSize=E(o.docSize+o.jsSize+o.cssSize+o.imgSize+o.fontSize),o.allTransferSize=E(o.docTransferSize+o.jsTransferSize+o.cssTransferSize+o.imgTransferSize+o.fontTransferSize);for(var r={},s=0,a=Object.keys(this.hostList);s<a.length;s++){var c=a[s],p=this.hostList[c].map(function(t){return t.timing});r[c]=this.getNumAndSize("host",p)}return{metric:o,hostMetric:r}}},t}(),j=null;window.performance&&window.performance.memory&&(j=window.performance.memory);var x=function(){function t(){this.onceLeave=!1}return t.prototype.listenMemory=function(t){this.cb=t},t.prototype.leave=function(){if(!this.onceLeave&&j){this.onceLeave=!0;var t=window.performance.memory;if(t.usedJSHeapSize===j.usedJSHeapSize&&t.totalJSHeapSize===j.totalJSHeapSize)return;var e=window.performance.memory;this.cb&&this.cb({usedJSHeapSize:e.usedJSHeapSize/1024,totalJSHeapSize:e.totalJSHeapSize/1024,jsHeapSizeLimit:e.jsHeapSizeLimit/1024,usedJSHeapRate:100*e.usedJSHeapSize/e.totalJSHeapSize})}},t}(),H=function(){function t(){}return t.prototype.getNavigatorInfo=function(){var t={},e=navigator.connection;return"object"==typeof e&&(t={downlink:e.downlink,effectiveType:e.effectiveType,rtt:e.rtt,saveData:!!e.saveData}),navigator.deviceMemory&&(t.deviceMemory=navigator.deviceMemory),navigator.hardwareConcurrency&&(t.hardwareConcurrency=navigator.deviceMemory),t},t.prototype.load=function(){},t}(),M=window.__spyHead,N="longtask",_=function(){function t(){var t=this;this.lts=[],this.observer=null,this.onceLeave=!1,M&&M.entryMap&&M.entryMap[N]&&(this.lts=this.lts.concat(M.entryMap[N]));try{this.observer=new PerformanceObserver(function(e){t.lts=t.lts.concat(e.getEntries())}),this.observer.observe({entryTypes:[N]})}catch(t){}}return t.prototype.check=function(){return window.PerformanceObserver&&performance&&performance.timing&&performance.timing.navigationStart},t.prototype.listenFSPLongTask=function(t){this.check()&&(this.fspCB=t)},t.prototype.listenLCPLongTask=function(t){this.check()&&(this.lcpCB=t)},t.prototype.listenLoadLongTask=function(t){this.check()&&(this.loadCB=t)},t.prototype.listenPageLongTask=function(t){this.check()&&(this.pageCB=t)},t.prototype.load=function(){var t=this;if(this.check()){var e=this.getStatData(Date.now());setTimeout(function(){if(t.loadCB&&t.loadCB({loadLongtaskTime:e.time,loadTBT:e.tbt,loadTotalTime:e.totalTime,loadLongtaskRate:e.rate,loadLongtaskNum:e.num}),performance.timing&&performance.timing.domFirstScreenPaint){var i=t.getStatData(performance.timing.domFirstScreenPaint);t.fspCB&&t.fspCB({fspLongtaskTime:i.time,fspTBT:i.tbt,fspTotalTime:i.totalTime,fspLongtaskRate:i.rate,fspLongtaskNum:i.num})}if(k("lcp")){var o=t.getStatData(performance.timing.navigationStart+k("lcp"));t.lcpCB&&t.lcpCB({lcpLongtaskTime:o.time,lcpTBT:o.tbt,lcpTotalTime:o.totalTime,lcpLongtaskRate:o.rate,lcpLongtaskNum:o.num})}},200)}},t.prototype.leave=function(){if(!this.onceLeave){this.onceLeave=!0;var t=this.getStatData(Date.now());this.pageCB&&this.pageCB({pageLongtaskTime:t.time,pageTBT:t.tbt,pageTotalTime:t.totalTime,pageLongtaskRate:t.rate,pageLongtaskNum:t.num,pageIframeLongtaskTime:t.iframeTime,pageIframeLongtaskRate:t.iframeRate,pageIframeLongtaskNum:t.iframeNum})}},t.prototype.destroy=function(){this.lts=[],this.observer&&this.observer.disconnect(),this.observer=null},t.prototype.getStatData=function(t){for(var e=performance.timing.navigationStart,i=0,o=0,n=0,r=0,s=0,a={},c=0;c<this.lts.length;c++){var p=this.lts[c],h=p.duration;if(e+p.startTime+h<t&&(i+=h,o+=h-50>0?h-50:0,n++,p.attribution&&p.attribution[0])){var l=p.attribution[0].containerSrc;l&&l!==location.href&&(a[l]||(a[l]=[]),a[l].push(h),r+=h,s++)}}var u=t-e;return{num:n,time:i,tbt:o,totalTime:u,rate:100*i/u,iframeTime:r,iframeNum:s,iframeRate:100*r/u,iframeLongtasks:a}},t}();return function(e){function i(t){var i=e.call(this,t)||this;return i.modules=[],i.register(new g),i.register(new L),i.register(new y),i.register(new B),i.register(new R),i.register(new P),i.register(new x),i.register(new H),i.register(new _),i.visibilitychangeCB=i.visibilitychangeCB.bind(i),i.load=i.load.bind(i),i.leave=i.leave.bind(i),"complete"===document.readyState?i.load():window.addEventListener("load",i.load),document.addEventListener("visibilitychange",i.visibilitychangeCB),window.addEventListener("beforeunload",i.leave,!1),window.addEventListener("unload",i.leave,!1),i.handleHead(),i}return function(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function o(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}(i,e),i.prototype.handleHead=function(){var t=this;if(this.option.localCache){var e=window.__spyHead;if(e&&e.winerrors){for(var i=0;i<e.winerrors.length;i++){var o=e.winerrors[i];this.option.localCache.addLog(o)}e.interceptor=function(e){t.option.localCache.addLog(e)}}}},i.prototype.listenFID=function(t){this.invoke("listenFID",t)},i.prototype.listenLayoutShift=function(t){this.invoke("listenLayoutShift",t)},i.prototype.listenLCP=function(t){this.invoke("listenLCP",t)},i.prototype.listenFSPLongTask=function(t){this.invoke("listenFSPLongTask",t)},i.prototype.listenLCPLongTask=function(t){this.invoke("listenLCPLongTask",t)},i.prototype.listenLoadLongTask=function(t){this.invoke("listenLoadLongTask",t)},i.prototype.listenPageLongTask=function(t){this.invoke("listenPageLongTask",t)},i.prototype.listenMemory=function(t){this.invoke("listenMemory",t)},i.prototype.getNavigatorInfo=function(){return this.invoke("getNavigatorInfo")},i.prototype.listenResource=function(t,e){this.invoke("listenResource",t,e)},i.prototype.listenBigImg=function(t,e){this.invoke("listenBigImg",t,e)},i.prototype.listenHttpResource=function(t,e){this.invoke("listenHttpResource",t,e)},i.prototype.listenSlowResource=function(t,e){this.invoke("listenSlowResource",t,e)},i.prototype.listenTiming=function(t){this.invoke("listenTiming",t)},i.prototype.listenTTI=function(t,e){this.invoke("listenTTI",t,e)},i.prototype.invoke=function(t,e,i){for(var o=0;o<this.modules.length;o++){var n=this.modules[o];if("function"==typeof n[t])return n[t].apply(n,[e,i])}console.error("no method",t)},i.prototype.register=function(t){this.modules.push(t)},i.prototype.load=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.load&&e.load()}},i.prototype.leave=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.leave&&e.leave()}},i.prototype.destroy=function(){for(var t=0;t<this.modules.length;t++){var e=this.modules[t];e.destroy&&e.destroy()}document.removeEventListener("visibilitychange",this.visibilitychangeCB),window.removeEventListener("load",this.load),window.removeEventListener("beforeunload",this.leave),window.removeEventListener("unload",this.destroy)},i.prototype.visibilitychangeCB=function(){"hidden"===document.visibilityState&&this.leave()},i}(u)}();