reporting-lib 0.4.6 → 0.4.7

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.
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"AAyFA,sCAEC"}
1
+ {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"AA+FA,sCAEC"}
package/dist/api/fetch.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { lazyReportCache } from '../report/index.js';
2
- import { isValidOssVideoUrl, getRequestBodySize, normalizeMaterialResourceUrl } from '../util/tool.js';
2
+ import { isValidOssVideoUrl, getRequestBodySize, normalizeMaterialResourceUrl, getFetchRequestHeader } from '../util/tool.js';
3
3
  const originalFetch = window.fetch;
4
4
  function overWriteFetch() {
5
5
  window.fetch = function newFetch(url, config) {
@@ -10,6 +10,14 @@ function overWriteFetch() {
10
10
  method: config?.method || 'GET',
11
11
  // sub_type: 'fetch',
12
12
  };
13
+ try {
14
+ const uuid = getFetchRequestHeader(url, config, 'uuid');
15
+ if (uuid)
16
+ reportData.uuid = uuid;
17
+ }
18
+ catch (e) {
19
+ // ignore
20
+ }
13
21
  if (isValidOssVideoUrl(request_url)) {
14
22
  reportData.request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
15
23
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"fetch.js","sourceRoot":"","sources":["../../src/api/fetch.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAC,kBAAkB,EAAC,4BAA4B,EAAC,MAAM,iBAAiB,CAAC;AAEnG,MAAM,aAAa,GAAG,MAAM,CAAC,KAAK,CAAC;AAEnC,SAAS,cAAc;IACrB,MAAM,CAAC,KAAK,GAAG,SAAS,QAAQ,CAAC,GAAG,EAAE,M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AAC,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAC7E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,KAAK;IAC3B,cAAc,EAAE,CAAC;AACnB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"AAgFA,oCAEC"}
1
+ {"version":3,"file":"xhr.d.ts","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"AA0GA,oCAEC"}
package/dist/api/xhr.js CHANGED
@@ -8,6 +8,25 @@ function overWriteOpenAndSend() {
8
8
  try {
9
9
  this.url = args[1];
10
10
  this.method = args[0];
11
+ // 每次 open 重置缓存,避免复用同一个 xhr 实例时上一次请求的 uuid 串到下一次
12
+ this._reportHeaders = {};
13
+ // 方案 A:仅在该 xhr 实例上劫持 setRequestHeader,不污染 XMLHttpRequest.prototype
14
+ // 仅用于缓存请求头,真正写入仍交由原生方法处理,因此不会改变实际发出去的请求头
15
+ if (!this._reportHeaderHooked) {
16
+ this._reportHeaderHooked = true;
17
+ const instanceSetHeader = this.setRequestHeader.bind(this);
18
+ this.setRequestHeader = (name, value) => {
19
+ try {
20
+ if (!this._reportHeaders)
21
+ this._reportHeaders = {};
22
+ this._reportHeaders[String(name).toLowerCase()] = value;
23
+ }
24
+ catch (e) {
25
+ // ignore
26
+ }
27
+ return instanceSetHeader(name, value);
28
+ };
29
+ }
11
30
  }
12
31
  catch (e) {
13
32
  // ignore
@@ -49,6 +68,14 @@ function overWriteOpenAndSend() {
49
68
  endTime,
50
69
  // sub_type: 'xhr',
51
70
  };
71
+ try {
72
+ const uuid = this._reportHeaders && this._reportHeaders['uuid'];
73
+ if (uuid)
74
+ reportData.uuid = uuid;
75
+ }
76
+ catch (e) {
77
+ // ignore
78
+ }
52
79
  if (isValidOssVideoUrl(request_url)) {
53
80
  reportData.request_url = `https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video`;
54
81
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"xhr.js","sourceRoot":"","sources":["../../src/api/xhr.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAC,kBAAkB,EAAC,kBAAkB,EAAC,4BAA4B,EAAC,MAAM,iBAAiB,CAAC;AAEnG,MAAM,iBAAiB,GAAG,cAAc,CAAC,SAAS,CAAC;AACnD,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,CAAC;AAC5C,MAAM,YAAY,GAAG,iBAAiB,CAAC,IAAI,CAAC;AAE5C,SAAS,oBAAoB;IAC3B,iBAAiB,CAAC,IAAI,GAAG,SAAS,OAAO,CAAC,GAAG,IAAI;QAC/C,IAAI,CAAC;YACH,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QACD,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC,CAAA;IACD,iBAAiB,CAAC,IAAI,GAAG,SAAS,OAAO,CAAC,GAAG,IAAI;QAC/C,mDAAmD;QACnD,IAAI,CAAC;YACH,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC5B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;YACrB,IAAI,CAAC,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC9C,CAAC;QAAC,OAA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AAC;oBACvD,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;oBAEjB,CAAC;gBACH,CAAC;gBAED,eAAe,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,aAAa;YACf,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC;oBAAC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;gBAAC,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;YAC5E,CAAC;QACH,CAAC,CAAA;QAED,6CAA6C;QAC7C,IAAI,CAAC;YAAC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QAAC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;QACvE,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC,CAAA;AAGH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,GAAG;IACzB,oBAAoB,EAAE,CAAC;AACzB,CAAC"}
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var j={source:"mbp",userId:"",reportUrl:"http://localhost:3001/report/actions",trackerAll:false,slsProject:"",slsEndpoint:"",slsLogstore:"",history:null},I="",f=j;function ge(e){for(let t in j)e[t]&&(j[t]=e[t]);e.version&&(I=e.version);}var M=new Map,D=new Map;function Te(){return M}function ye(e,t){M.get(e)?M.get(e).push(t):M.set(e,[t]);}function ve(){M.clear();}function we(){return D}function Se(e,t){D.get(e)?D.get(e).push(t):D.set(e,[t]);}function Pe(){D.clear();}function et(e,t,r=false){if(f.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=JSON.stringify({user_id:Number(f.userId)||0,source:f.source,type:e,url:window.location.pathname,data:t});if(r){V(f.reportUrl,n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{V(f.reportUrl,n);},{timeout:3e3}):setTimeout(()=>{V(f.reportUrl,n);});}var Le=null;function p(e,t,r=3e3){ye(e,t),clearTimeout(Le),Le=setTimeout(()=>{let n=Te();if(n.size){for(let[o,i]of n)et(o,i);ve();}},r);}function V(e,t){navigator.sendBeacon?navigator.sendBeacon(e,t):tt(e,t);}function tt(e,t){let r=new XMLHttpRequest;r.open("POST",e,true),r.setRequestHeader("Content-Type","application/json"),r.send(t);}var nt=({samplePoints:e=6,whiteTags:t=["HTML","BODY","IFRAME"],onDetected:r=(o,i)=>{},threshold:n=.9}={})=>{let o=window.innerWidth,i=window.innerHeight,a=[];for(let u=1;u<=e;u++)a.push([o/2,i/(e+1)*u]);let s=0,c=[];a.forEach(([u,h])=>{let g=document.elementFromPoint(u,h),w=g?.tagName||"NULL";c.push({x:u,y:h,tag:w}),(!g||t.includes(w))&&s++;});let l=s/e>=n;r(l,c);},rt=(e,t=300,r=false)=>{let n=null;return function(...o){let i=this;n&&clearTimeout(n),r&&!n&&e.apply(i,o),n=setTimeout(()=>{r||e.apply(i,o),n=null;},t);}},ot=rt(e=>{nt({onDetected:(t,r)=>{e(t),$=null;}});},1e3),$=null,be=()=>($||($=new Promise(e=>{setTimeout(()=>{ot(e);},3e3);})),$),xe=()=>{let e=navigator.userAgent,t="Unknown",r="Unknown";return /edg/i.test(e)?(t="Edge",r=e.match(/edg\/([\d\.]+)/i)?.[1]):/opr/i.test(e)?(t="Opera",r=e.match(/opr\/([\d\.]+)/i)?.[1]):/chrome/i.test(e)?(t="Chrome",r=e.match(/chrome\/([\d\.]+)/i)?.[1]):/firefox/i.test(e)?(t="Firefox",r=e.match(/firefox\/([\d\.]+)/i)?.[1]):/safari/i.test(e)&&!/chrome/i.test(e)?(t="Safari",r=e.match(/version\/([\d\.]+)/i)?.[1]):(/msie/i.test(e)||/trident/i.test(e))&&(t="Internet Explorer",r=e.match(/(msie\s|rv:)([\d\.]+)/i)?.[2]),{name:t,version:r}},Ce=()=>{let e=navigator.userAgent||navigator.vendor||window.opera;return /windows phone/i.test(e)?"Windows Phone":/win/i.test(e)?"Windows":/android/i.test(e)?"Android":/iPad|iPhone|iPod/.test(e)&&!window.MSStream?"iOS":/Macintosh|MacIntel|MacPPC|Mac68K/.test(e)?"macOS":/Linux/.test(e)?"Linux":"Unknown OS"},A=e=>{try{let t=String(e),r=t.match(/^(https?:\/\/[^/]+)\/material_resource\/([^/?#]+)\/\d+\/[^/?#]+(?:[/?#].*)?$/i);if(r)return `${r[1]}/material_resource/${r[2]}`;let n=t.match(/^(https?:\/\/[^/]+)\/mbp\/\d+\/([^/?#]+)\/[^/?#]+(?:[/?#].*)?$/i);return n?`${n[1]}/mbp/${n[2]}`:e}catch{return e}},B=e=>{try{let t=new URL(e.indexOf("http")===-1?`https:${e}`:e);return /^\/mbp\/\d+\/video\/[^/?#]+\.[^/?#]+$/i.test(t.pathname)}catch{return false}},F=e=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},N=e=>{if(!e)return 0;try{if(typeof e=="string")return new TextEncoder().encode(e).length;if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(e instanceof FormData){let t=0;for(let[r,n]of e.entries())t+=new TextEncoder().encode(r).length,typeof n=="string"?t+=new TextEncoder().encode(n).length:n instanceof Blob&&(t+=n.size);return t}}catch{return 0}return 0};var it={browserInfo:xe(),platform:Ce()},R=it;var Ie=R.browserInfor,J={user_agent:Ie?.name+Ie?.version,platform:R.platform},at=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,st=10;function ct(e){let t=e.match(at);if(!t)return {};let r=t[2]||"<anonymous>",n=t[1]||"",o=parseInt(t[3],10)||void 0,i=parseInt(t[4],10)||void 0;return {filename:r,functionName:n,lineno:o,colno:i}}function Ee(e){let{stack:t}=e;if(!t)return [];let r=[];for(let n of t.split(`
2
- `).slice(1)){let o=ct(n);o.filename&&r.push(o);}return r.slice(0,st)}function X(){window.addEventListener("error",async function(e){let t=e.target;if(t&&(t.src||t.href)){let r={error_type:"resource",...J,msg:F(`\u52A0\u8F7D${t.tagName}\u5931\u8D25\uFF1A${t.src||t.href}`),version:I};p("error",r);}else {let r=Ee(e.error),n=e.message;if(r?.[0]){let{filename:a,functionName:s,lineno:c,colno:l}=r[0];n=`${e.message},${a},line:${c}:${l}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o),await be()&&p("error",{...o,error_type:"whiteScreen"});}},true),window.addEventListener("unhandledrejection",function(e){let t=e.reason,r=Ee(t),n=t;if(r?.[0]){let{filename:i,functionName:a,lineno:s,colno:c}=r[0];n=`${e?.reason?.message||e?.reason},${i},line:${s}:${c}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o);});}var Be=-1,C=e=>{addEventListener("pageshow",t=>{t.persisted&&(Be=t.timeStamp,e(t));},true);},T=(e,t,r,n)=>{let o,i;return a=>{t.value>=0&&(a||n)&&(i=t.value-(o??0),(i||o===void 0)&&(o=t.value,t.delta=i,t.rating=((s,c)=>s>c[1]?"poor":s>c[0]?"needs-improvement":"good")(t.value,r),e(t)));}},re=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()));},oe=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},O=()=>oe()?.activationStart??0,y=(e,t=-1)=>{let r=oe(),n="navigate";return Be>=0?n="back-forward-cache":r&&(document.prerendering||O()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},G=new WeakMap;function ie(e,t){return G.get(e)||G.set(e,new t),G.get(e)}var Y=class{t;i=0;o=[];h(t){if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t);}},k=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(o=>{Promise.resolve().then(()=>{t(o.getEntries());});});return n.observe({type:e,buffered:!0,...r}),n}}catch{}},ae=e=>{let t=false;return ()=>{t||(e(),t=true);}},x=-1,Fe=new Set,Me=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,Q=e=>{if(document.visibilityState==="hidden"){if(e.type==="visibilitychange")for(let t of Fe)t();isFinite(x)||(x=e.type==="visibilitychange"?e.timeStamp:0,removeEventListener("prerenderingchange",Q,true));}},z=()=>{if(x<0){let e=O();x=(document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>e)[0]?.startTime)??Me(),addEventListener("visibilitychange",Q,true),addEventListener("prerenderingchange",Q,true),C(()=>{setTimeout(()=>{x=Me();});});}return {get firstHiddenTime(){return x},onHidden(e){Fe.add(e);}}},H=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),true):e();},De=[1800,3e3],se=(e,t={})=>{H(()=>{let r=z(),n,o=y("FCP"),i=k("paint",a=>{for(let s of a)s.name==="first-contentful-paint"&&(i.disconnect(),s.startTime<r.firstHiddenTime&&(o.value=Math.max(s.startTime-O(),0),o.entries.push(s),n(true)));});i&&(n=T(e,o,De,t.reportAllChanges),C(a=>{o=y("FCP"),n=T(e,o,De,t.reportAllChanges),re(()=>{o.value=performance.now()-a.timeStamp,n(true);});}));});},Re=[.1,.25],Ne=(e,t={})=>{let r=z();se(ae(()=>{let n,o=y("CLS",0),i=ie(t,Y),a=c=>{for(let l of c)i.h(l);i.i>o.value&&(o.value=i.i,o.entries=i.o,n());},s=k("layout-shift",a);s&&(n=T(e,o,Re,t.reportAllChanges),r.onHidden(()=>{a(s.takeRecords()),n(true);}),C(()=>{i.i=0,o=y("CLS",0),n=T(e,o,Re,t.reportAllChanges),re(()=>n());}),setTimeout(n));}));},qe=0,K=1/0,q=0,lt=e=>{for(let t of e)t.interactionId&&(K=Math.min(K,t.interactionId),q=Math.max(q,t.interactionId),qe=q?(q-K)/7+1:0);},Z,Oe=()=>Z?qe:performance.interactionCount??0,ut=()=>{"interactionCount"in performance||Z||(Z=k("event",lt,{type:"event",buffered:true,durationThreshold:0}));},ke=0,ee=class{u=[];l=new Map;m;p;v(){ke=Oe(),this.u.length=0,this.l.clear();}L(){let t=Math.min(this.u.length-1,Math.floor((Oe()-ke)/50));return this.u[t]}h(t){if(this.m?.(t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.P){if(n?t.duration>n.P?(n.entries=[t],n.P=t.duration):t.duration===n.P&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],P:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((o,i)=>i.P-o.P),this.u.length>10){let o=this.u.splice(10);for(let i of o)this.l.delete(i.id);}this.p?.(n);}}},ze=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=ae(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:true});}));},_e=[200,500],He=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;let r=z();H(()=>{ut();let n,o=y("INP"),i=ie(t,ee),a=c=>{ze(()=>{for(let u of c)i.h(u);let l=i.L();l&&l.P!==o.value&&(o.value=l.P,o.entries=l.entries,n());});},s=k("event",a,{durationThreshold:t.durationThreshold??40});n=T(e,o,_e,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:true}),r.onHidden(()=>{a(s.takeRecords()),n(true);}),C(()=>{i.v(),o=y("INP"),n=T(e,o,_e,t.reportAllChanges);}));});},te=class{m;h(t){this.m?.(t);}},$e=[2500,4e3],Ue=(e,t={})=>{H(()=>{let r=z(),n,o=y("LCP"),i=ie(t,te),a=c=>{t.reportAllChanges||(c=c.slice(-1));for(let l of c)i.h(l),l.startTime<r.firstHiddenTime&&(o.value=Math.max(l.startTime-O(),0),o.entries=[l],n());},s=k("largest-contentful-paint",a);if(s){n=T(e,o,$e,t.reportAllChanges);let c=ae(()=>{a(s.takeRecords()),s.disconnect(),n(true);}),l=u=>{u.isTrusted&&(ze(c),removeEventListener(u.type,l,{capture:true}));};for(let u of ["keydown","click","visibilitychange"])addEventListener(u,l,{capture:true});C(u=>{o=y("LCP"),n=T(e,o,$e,t.reportAllChanges),re(()=>{o.value=performance.now()-u.timeStamp,n(true);});});}});},Ae=[800,1800],ne=e=>{document.prerendering?H(()=>ne(e)):document.readyState!=="complete"?addEventListener("load",()=>ne(e),true):setTimeout(e);},We=(e,t={})=>{let r=y("TTFB"),n=T(e,r,Ae,t.reportAllChanges);ne(()=>{let o=oe();o&&(r.value=Math.max(o.responseStart-O(),0),r.entries=[o],n(true),C(()=>{r=y("TTFB",0),n=T(e,r,Ae,t.reportAllChanges),n(true);}));});};function ce(){Ne(_),He(_),Ue(_),se(_),We(_);}function _(e){let t={name:e.name,value:e.value};p("performance",t);}var U=XMLHttpRequest.prototype,dt=U.open,mt=U.send;function ft(){U.open=function(...t){try{this.url=t[1],this.method=t[0];}catch{}dt.apply(this,t);},U.send=function(...t){try{this.startTime=Date.now();let n=t[0];this.requestSize=N(n);}catch{}let r=()=>{try{this.endTime=Date.now(),this.duration=this.endTime-this.startTime;let{status:n,duration:o,startTime:i,endTime:a,method:s,response:c,requestSize:l}=this,{url:u}=this,h=n,g=u;try{let P=JSON.parse(c);h=P&&typeof P=="object"?P.code:n;}catch{}let w={status:n,request_url:A(g),method:s||"GET",code:h,duration:o,startTime:i,endTime:a};if(B(g)){w.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{w.request_size=parseInt(l/1e3);}catch{}}p("api",w);}catch{}finally{try{this.removeEventListener("loadend",r,!0);}catch{}}};try{this.addEventListener("loadend",r,!0);}catch{}mt.apply(this,t);};}function le(){ft();}var pt=window.fetch;function ht(){window.fetch=function(t,r){let n=Date.now(),o=t,i={request_url:A(o),method:r?.method||"GET"};if(B(o)){i.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{i.request_size=parseInt(N(r?.body)/1e3);}catch{}}return pt(t,r).then(a=>{try{let s=Date.now();i.duration=s-n,i.startTime=n,i.endTime=s,i.status=a.status;let c=a.clone();gt(t)&&(c.ok?c.json().then(l=>{i.code=l&&typeof l=="object"?l.code:void 0,p("api",i);}).catch(()=>{p("api",i);}):(i.code=i.status,p("api",i)));}catch{}return a}).catch(a=>{try{let s=Date.now();i.duration=s-n,i.startTime=n,i.endTime=s,i.status=0,i.code=i.status,p("api",i);}catch{}return a})};}function gt(e){let t="";try{typeof e=="string"?t=e:e&&typeof e.url=="string"?t=e.url:t=String(e);}catch{return true}return !(t.indexOf(".js.map")!==-1||t.indexOf(".log.aliyuncs.com")!==-1)}function ue(){ht();}function de(){le(),ue();}async function je(e,{project:t,endpoint:r,logstore:n}){if(!t||!r||!n)return;let o=Math.floor(Date.now()/1e3),i={__logs__:e.map(u=>({__time__:o,...Object.keys(u).reduce((h,g)=>(h[g]=String(u[g]),h),{})})),__topic__:"default",__source__:"frontend"},a=JSON.stringify(i),s=`https://${t}.${r}/logstores/${n}/track?APIVersion=0.6.0`,c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","x-log-apiversion":"0.6.0","x-log-bodyrawsize":a.length.toString()},body:a}),l=await c.text();if(!c.ok)throw new Error(`SLS API error: ${c.status} ${c.statusText} - ${l}`);return c}function Tt(e,t,r=false){if(f.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=[{user_id:Number(f.userId)||0,source:f.source,type:e,url:window.location.pathname,data:t}];if(r){me(n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{me(n);},{timeout:3e3}):me(n);}var Ve=null;function W(e,t,r,n=3e3){if(t=JSON.stringify({...R,...t}),Se(e,t),r){Je(r);return}clearTimeout(Ve),Ve=setTimeout(()=>{Je();},n);}function Je(e=false){let t=we();if(t.size){for(let[r,n]of t)Tt(r,n,e);Pe();}}function me(e){je(e,{project:f.slsProject,endpoint:f.slsEndpoint,logstore:f.slsLogstore}).catch(t=>{console.error("[reporting-lib] SLS\u4E0A\u62A5\u5931\u8D25:",t);});}function Xe(e,t={}){let{minDuration:r=1e3,debounceMs:n=300}=t,o=false,i=null,a=Date.now(),s=(()=>{try{return window.location?.pathname||"/"}catch{return "/"}})(),c,l=false,u=(d,m,S)=>{o||(i&&clearTimeout(i),i=setTimeout(()=>{if(!o&&m>=r)try{e(m,d,S),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}},n));},h=()=>{if(document.visibilityState==="hidden"){let d=Date.now(),m=d-a;u("visibilitychange-hidden",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});}else if(document.visibilityState==="visible"){a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false;}};document.addEventListener("visibilitychange",h);let g=d=>{let m=Date.now(),S=m-a,b={startTime:a,endTime:m,pagePath:s,pageTag:c};d.persisted?u("pagehide-bfcache",S,b):u("pagehide",S,b);};window.addEventListener("pagehide",g);let w=()=>{if(!o){let d=Date.now(),m=d-a,S={startTime:a,endTime:d,pagePath:s,pageTag:c};if(m>=r)try{e(m,"beforeunload",S),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}}};window.addEventListener("beforeunload",w);let P=()=>{let d=Date.now(),m=d-a;u("popstate",m,{startTime:a,endTime:d,pagePath:s,pageTag:c});};window.addEventListener("popstate",P);let fe=()=>{a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false,i&&(clearTimeout(i),i=null);},pe=(d="manual")=>{let m=Date.now(),S=m-a;u(d,S,{startTime:a,endTime:m,pagePath:s,pageTag:c}),d==="route-change"&&setTimeout(()=>{fe();},n+50);},he=d=>{c=d||void 0,d&&(l=true);};return {manualLeave:pe,reset:fe,stop:()=>{i&&(clearTimeout(i),i=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",g),window.removeEventListener("beforeunload",w),window.removeEventListener("popstate",P);},getCurrentDuration:()=>{let d=Date.now();return document.visibilityState==="visible"?d-a:0},setPageTag:he,switchPageTag:(d,m="page-tag-change")=>{c&&c!==d?(o=false,pe(m),a=Date.now()):l||(a=Date.now(),o=false),he(d);}}}var yt=e=>{try{if(e)return e||"/";let{pathname:t="/"}=window.location||{};return t||"/"}catch{return "/"}},Ge=(e,t,r,n={})=>{let{startTime:o,endTime:i,pagePath:a,pageTag:s}=r,c=yt(a),l=s?`${c}#${s}`:c,{formatPageName:u}=n;return {pageName:typeof u=="function"?u(l,{duration:e,reason:t,...r}):l,duration:e,startTime:o,endTime:i}};var v=null,L=null;function vt(e={},t,r){let{enabled:n,minDuration:o,debounceMs:i,onLeave:a}=e;n?(v&&(v.stop(),v=null),v=Xe(a||r||((c,l,u)=>{}),{minDuration:o,debounceMs:i}),t&&t.listen&&(L&&(L(),L=null),L=t.listen(({location:c,action:l})=>{v&&(l==="PUSH"||l==="REPLACE")&&v.manualLeave("route-change");}))):v&&(v.stop(),v=null,L&&(L(),L=null));}function Ke(e,t){v?.switchPageTag(e,t);}function Ye(e,t){if(!e)return;vt(e,t,(n,o,i)=>{let a=Ge(n,o,i||{startTime:0,endTime:0},{formatPageName:e?.formatPageName});W("pd",a);});}function Qe(e,t){let r=t||f.history;return !r||!r.listen?(console.warn("[reporting-lib] No history instance available. Please provide history in init() or pass it as parameter."),()=>{}):r.listen(e)}var Ze=false,wt={init(e={}){ge(e),Ye(e.trackPageStayTime,e.history),Ze||(X(),ce(),de(),Ze=true);},reportToSLS(e,t={},r={}){let{immediate:n=false,timeout:o=3e3}=r;W(e,t,n,o);},switchPageTag(e,t="page-tag-change"){Ke(e,t);},listenRouteChange(e,t){return Qe(e,t)}},In=wt;
3
- module.exports=In;//# sourceMappingURL=index.cjs.map
1
+ 'use strict';var W={source:"mbp",userId:"",reportUrl:"http://localhost:3001/report/actions",trackerAll:false,slsProject:"",slsEndpoint:"",slsLogstore:"",history:null},I="",m=W;function ge(e){for(let t in W)e[t]&&(W[t]=e[t]);e.version&&(I=e.version);}var M=new Map,R=new Map;function Te(){return M}function ye(e,t){M.get(e)?M.get(e).push(t):M.set(e,[t]);}function ve(){M.clear();}function we(){return R}function Se(e,t){R.get(e)?R.get(e).push(t):R.set(e,[t]);}function Pe(){R.clear();}function nt(e,t,r=false){if(m.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=JSON.stringify({user_id:Number(m.userId)||0,source:m.source,type:e,url:window.location.pathname,data:t});if(r){V(m.reportUrl,n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{V(m.reportUrl,n);},{timeout:3e3}):setTimeout(()=>{V(m.reportUrl,n);});}var Le=null;function p(e,t,r=3e3){ye(e,t),clearTimeout(Le),Le=setTimeout(()=>{let n=Te();if(n.size){for(let[o,i]of n)nt(o,i);ve();}},r);}function V(e,t){navigator.sendBeacon?navigator.sendBeacon(e,t):rt(e,t);}function rt(e,t){let r=new XMLHttpRequest;r.open("POST",e,true),r.setRequestHeader("Content-Type","application/json"),r.send(t);}var ot=({samplePoints:e=6,whiteTags:t=["HTML","BODY","IFRAME"],onDetected:r=(o,i)=>{},threshold:n=.9}={})=>{let o=window.innerWidth,i=window.innerHeight,a=[];for(let l=1;l<=e;l++)a.push([o/2,i/(e+1)*l]);let s=0,c=[];a.forEach(([l,h])=>{let g=document.elementFromPoint(l,h),y=g?.tagName||"NULL";c.push({x:l,y:h,tag:y}),(!g||t.includes(y))&&s++;});let u=s/e>=n;r(u,c);},it=(e,t=300,r=false)=>{let n=null;return function(...o){let i=this;n&&clearTimeout(n),r&&!n&&e.apply(i,o),n=setTimeout(()=>{r||e.apply(i,o),n=null;},t);}},at=it(e=>{ot({onDetected:(t,r)=>{e(t),O=null;}});},1e3),O=null,xe=()=>(O||(O=new Promise(e=>{setTimeout(()=>{at(e);},3e3);})),O),Ce=()=>{let e=navigator.userAgent,t="Unknown",r="Unknown";return /edg/i.test(e)?(t="Edge",r=e.match(/edg\/([\d\.]+)/i)?.[1]):/opr/i.test(e)?(t="Opera",r=e.match(/opr\/([\d\.]+)/i)?.[1]):/chrome/i.test(e)?(t="Chrome",r=e.match(/chrome\/([\d\.]+)/i)?.[1]):/firefox/i.test(e)?(t="Firefox",r=e.match(/firefox\/([\d\.]+)/i)?.[1]):/safari/i.test(e)&&!/chrome/i.test(e)?(t="Safari",r=e.match(/version\/([\d\.]+)/i)?.[1]):(/msie/i.test(e)||/trident/i.test(e))&&(t="Internet Explorer",r=e.match(/(msie\s|rv:)([\d\.]+)/i)?.[2]),{name:t,version:r}},Ie=()=>{let e=navigator.userAgent||navigator.vendor||window.opera;return /windows phone/i.test(e)?"Windows Phone":/win/i.test(e)?"Windows":/android/i.test(e)?"Android":/iPad|iPhone|iPod/.test(e)&&!window.MSStream?"iOS":/Macintosh|MacIntel|MacPPC|Mac68K/.test(e)?"macOS":/Linux/.test(e)?"Linux":"Unknown OS"},A=e=>{try{let t=String(e),r=t.match(/^(https?:\/\/[^/]+)\/material_resource\/([^/?#]+)\/\d+\/[^/?#]+(?:[/?#].*)?$/i);if(r)return `${r[1]}/material_resource/${r[2]}`;let n=t.match(/^(https?:\/\/[^/]+)\/mbp\/\d+\/([^/?#]+)\/[^/?#]+(?:[/?#].*)?$/i);return n?`${n[1]}/mbp/${n[2]}`:e}catch{return e}},be=(e,t)=>{if(!e)return;let r=String(t).toLowerCase();try{if(typeof e.get=="function"){let n=e.get(t);return n??void 0}if(Array.isArray(e)){for(let n of e)if(Array.isArray(n)&&String(n[0]).toLowerCase()===r)return n[1];return}if(typeof e=="object"){for(let n of Object.keys(e))if(n.toLowerCase()===r)return e[n]}}catch{}},Ee=(e,t,r)=>{let n=be(t&&t.headers,r);if(n!=null)return n;try{if(e&&typeof e=="object"&&e.headers)return be(e.headers,r)}catch{}},q=e=>{try{let t=new URL(e.indexOf("http")===-1?`https:${e}`:e);return /^\/mbp\/\d+\/video\/[^/?#]+\.[^/?#]+$/i.test(t.pathname)}catch{return false}},F=e=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},$=e=>{if(!e)return 0;try{if(typeof e=="string")return new TextEncoder().encode(e).length;if(e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength;if(e instanceof URLSearchParams)return new TextEncoder().encode(e.toString()).length;if(e instanceof FormData){let t=0;for(let[r,n]of e.entries())t+=new TextEncoder().encode(r).length,typeof n=="string"?t+=new TextEncoder().encode(n).length:n instanceof Blob&&(t+=n.size);return t}}catch{return 0}return 0};var st={browserInfo:Ce(),platform:Ie()},_=st;var Me=_.browserInfor,J={user_agent:Me?.name+Me?.version,platform:_.platform},ct=/^\s*at (?:(.*?) ?\()?((?:file|https?|blob|chrome-extension|address|native|eval|webpack|<anonymous>|[-a-z]+:|.*bundle|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,ut=10;function lt(e){let t=e.match(ct);if(!t)return {};let r=t[2]||"<anonymous>",n=t[1]||"",o=parseInt(t[3],10)||void 0,i=parseInt(t[4],10)||void 0;return {filename:r,functionName:n,lineno:o,colno:i}}function Re(e){let{stack:t}=e;if(!t)return [];let r=[];for(let n of t.split(`
2
+ `).slice(1)){let o=lt(n);o.filename&&r.push(o);}return r.slice(0,ut)}function X(){window.addEventListener("error",async function(e){let t=e.target;if(t&&(t.src||t.href)){let r={error_type:"resource",...J,msg:F(`\u52A0\u8F7D${t.tagName}\u5931\u8D25\uFF1A${t.src||t.href}`),version:I};p("error",r);}else {let r=Re(e.error),n=e.message;if(r?.[0]){let{filename:a,functionName:s,lineno:c,colno:u}=r[0];n=`${e.message},${a},line:${c}:${u}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o),await xe()&&p("error",{...o,error_type:"whiteScreen"});}},true),window.addEventListener("unhandledrejection",function(e){let t=e.reason,r=Re(t),n=t;if(r?.[0]){let{filename:i,functionName:a,lineno:s,colno:c}=r[0];n=`${e?.reason?.message||e?.reason},${i},line:${s}:${c}`;}let o={error_type:"js",msg:F(n),...J,version:I};p("error",o);});}var $e=-1,C=e=>{addEventListener("pageshow",t=>{t.persisted&&($e=t.timeStamp,e(t));},true);},v=(e,t,r,n)=>{let o,i;return a=>{t.value>=0&&(a||n)&&(i=t.value-(o??0),(i||o===void 0)&&(o=t.value,t.delta=i,t.rating=((s,c)=>s>c[1]?"poor":s>c[0]?"needs-improvement":"good")(t.value,r),e(t)));}},re=e=>{requestAnimationFrame(()=>requestAnimationFrame(()=>e()));},oe=()=>{let e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},D=()=>oe()?.activationStart??0,w=(e,t=-1)=>{let r=oe(),n="navigate";return $e>=0?n="back-forward-cache":r&&(document.prerendering||D()>0?n="prerender":document.wasDiscarded?n="restore":r.type&&(n=r.type.replace(/_/g,"-"))),{name:e,value:t,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:n}},G=new WeakMap;function ie(e,t){return G.get(e)||G.set(e,new t),G.get(e)}var Y=class{t;i=0;o=[];h(t){if(t.hadRecentInput)return;let r=this.o[0],n=this.o.at(-1);this.i&&r&&n&&t.startTime-n.startTime<1e3&&t.startTime-r.startTime<5e3?(this.i+=t.value,this.o.push(t)):(this.i=t.value,this.o=[t]),this.t?.(t);}},k=(e,t,r={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){let n=new PerformanceObserver(o=>{Promise.resolve().then(()=>{t(o.getEntries());});});return n.observe({type:e,buffered:!0,...r}),n}}catch{}},ae=e=>{let t=false;return ()=>{t||(e(),t=true);}},x=-1,Be=new Set,_e=()=>document.visibilityState!=="hidden"||document.prerendering?1/0:0,Q=e=>{if(document.visibilityState==="hidden"){if(e.type==="visibilitychange")for(let t of Be)t();isFinite(x)||(x=e.type==="visibilitychange"?e.timeStamp:0,removeEventListener("prerenderingchange",Q,true));}},N=()=>{if(x<0){let e=D();x=(document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter(r=>r.name==="hidden"&&r.startTime>e)[0]?.startTime)??_e(),addEventListener("visibilitychange",Q,true),addEventListener("prerenderingchange",Q,true),C(()=>{setTimeout(()=>{x=_e();});});}return {get firstHiddenTime(){return x},onHidden(e){Be.add(e);}}},z=e=>{document.prerendering?addEventListener("prerenderingchange",()=>e(),true):e();},De=[1800,3e3],se=(e,t={})=>{z(()=>{let r=N(),n,o=w("FCP"),i=k("paint",a=>{for(let s of a)s.name==="first-contentful-paint"&&(i.disconnect(),s.startTime<r.firstHiddenTime&&(o.value=Math.max(s.startTime-D(),0),o.entries.push(s),n(true)));});i&&(n=v(e,o,De,t.reportAllChanges),C(a=>{o=w("FCP"),n=v(e,o,De,t.reportAllChanges),re(()=>{o.value=performance.now()-a.timeStamp,n(true);});}));});},ke=[.1,.25],Ne=(e,t={})=>{let r=N();se(ae(()=>{let n,o=w("CLS",0),i=ie(t,Y),a=c=>{for(let u of c)i.h(u);i.i>o.value&&(o.value=i.i,o.entries=i.o,n());},s=k("layout-shift",a);s&&(n=v(e,o,ke,t.reportAllChanges),r.onHidden(()=>{a(s.takeRecords()),n(true);}),C(()=>{i.i=0,o=w("CLS",0),n=v(e,o,ke,t.reportAllChanges),re(()=>n());}),setTimeout(n));}));},ze=0,K=1/0,B=0,dt=e=>{for(let t of e)t.interactionId&&(K=Math.min(K,t.interactionId),B=Math.max(B,t.interactionId),ze=B?(B-K)/7+1:0);},Z,He=()=>Z?ze:performance.interactionCount??0,ft=()=>{"interactionCount"in performance||Z||(Z=k("event",dt,{type:"event",buffered:true,durationThreshold:0}));},Oe=0,ee=class{u=[];l=new Map;m;p;v(){Oe=He(),this.u.length=0,this.l.clear();}L(){let t=Math.min(this.u.length-1,Math.floor((He()-Oe)/50));return this.u[t]}h(t){if(this.m?.(t),!t.interactionId&&t.entryType!=="first-input")return;let r=this.u.at(-1),n=this.l.get(t.interactionId);if(n||this.u.length<10||t.duration>r.P){if(n?t.duration>n.P?(n.entries=[t],n.P=t.duration):t.duration===n.P&&t.startTime===n.entries[0].startTime&&n.entries.push(t):(n={id:t.interactionId,entries:[t],P:t.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort((o,i)=>i.P-o.P),this.u.length>10){let o=this.u.splice(10);for(let i of o)this.l.delete(i.id);}this.p?.(n);}}},Ue=e=>{let t=globalThis.requestIdleCallback||setTimeout;document.visibilityState==="hidden"?e():(e=ae(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t(()=>{e(),removeEventListener("visibilitychange",e,{capture:true});}));},Ae=[200,500],je=(e,t={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;let r=N();z(()=>{ft();let n,o=w("INP"),i=ie(t,ee),a=c=>{Ue(()=>{for(let l of c)i.h(l);let u=i.L();u&&u.P!==o.value&&(o.value=u.P,o.entries=u.entries,n());});},s=k("event",a,{durationThreshold:t.durationThreshold??40});n=v(e,o,Ae,t.reportAllChanges),s&&(s.observe({type:"first-input",buffered:true}),r.onHidden(()=>{a(s.takeRecords()),n(true);}),C(()=>{i.v(),o=w("INP"),n=v(e,o,Ae,t.reportAllChanges);}));});},te=class{m;h(t){this.m?.(t);}},qe=[2500,4e3],We=(e,t={})=>{z(()=>{let r=N(),n,o=w("LCP"),i=ie(t,te),a=c=>{t.reportAllChanges||(c=c.slice(-1));for(let u of c)i.h(u),u.startTime<r.firstHiddenTime&&(o.value=Math.max(u.startTime-D(),0),o.entries=[u],n());},s=k("largest-contentful-paint",a);if(s){n=v(e,o,qe,t.reportAllChanges);let c=ae(()=>{a(s.takeRecords()),s.disconnect(),n(true);}),u=l=>{l.isTrusted&&(Ue(c),removeEventListener(l.type,u,{capture:true}));};for(let l of ["keydown","click","visibilitychange"])addEventListener(l,u,{capture:true});C(l=>{o=w("LCP"),n=v(e,o,qe,t.reportAllChanges),re(()=>{o.value=performance.now()-l.timeStamp,n(true);});});}});},Fe=[800,1800],ne=e=>{document.prerendering?z(()=>ne(e)):document.readyState!=="complete"?addEventListener("load",()=>ne(e),true):setTimeout(e);},Ve=(e,t={})=>{let r=w("TTFB"),n=v(e,r,Fe,t.reportAllChanges);ne(()=>{let o=oe();o&&(r.value=Math.max(o.responseStart-D(),0),r.entries=[o],n(true),C(()=>{r=w("TTFB",0),n=v(e,r,Fe,t.reportAllChanges),n(true);}));});};function ce(){Ne(H),je(H),We(H),se(H),Ve(H);}function H(e){let t={name:e.name,value:e.value};p("performance",t);}var U=XMLHttpRequest.prototype,mt=U.open,pt=U.send;function ht(){U.open=function(...t){try{if(this.url=t[1],this.method=t[0],this._reportHeaders={},!this._reportHeaderHooked){this._reportHeaderHooked=!0;let r=this.setRequestHeader.bind(this);this.setRequestHeader=(n,o)=>{try{this._reportHeaders||(this._reportHeaders={}),this._reportHeaders[String(n).toLowerCase()]=o;}catch{}return r(n,o)};}}catch{}mt.apply(this,t);},U.send=function(...t){try{this.startTime=Date.now();let n=t[0];this.requestSize=$(n);}catch{}let r=()=>{try{this.endTime=Date.now(),this.duration=this.endTime-this.startTime;let{status:n,duration:o,startTime:i,endTime:a,method:s,response:c,requestSize:u}=this,{url:l}=this,h=n,g=l;try{let T=JSON.parse(c);h=T&&typeof T=="object"?T.code:n;}catch{}let y={status:n,request_url:A(g),method:s||"GET",code:h,duration:o,startTime:i,endTime:a};try{let T=this._reportHeaders&&this._reportHeaders.uuid;T&&(y.uuid=T);}catch{}if(q(g)){y.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{y.request_size=parseInt(u/1e3);}catch{}}p("api",y);}catch{}finally{try{this.removeEventListener("loadend",r,!0);}catch{}}};try{this.addEventListener("loadend",r,!0);}catch{}pt.apply(this,t);};}function ue(){ht();}var gt=window.fetch;function Tt(){window.fetch=function(t,r){let n=Date.now(),o=t,i={request_url:A(o),method:r?.method||"GET"};try{let a=Ee(t,r,"uuid");a&&(i.uuid=a);}catch{}if(q(o)){i.request_url="https://sd-cms-bmp.oss-accelerate.aliyuncs.com:443/mbp/video";try{i.request_size=parseInt($(r?.body)/1e3);}catch{}}return gt(t,r).then(a=>{try{let s=Date.now();i.duration=s-n,i.startTime=n,i.endTime=s,i.status=a.status;let c=a.clone();yt(t)&&(c.ok?c.json().then(u=>{i.code=u&&typeof u=="object"?u.code:void 0,p("api",i);}).catch(()=>{p("api",i);}):(i.code=i.status,p("api",i)));}catch{}return a}).catch(a=>{try{let s=Date.now();i.duration=s-n,i.startTime=n,i.endTime=s,i.status=0,i.code=i.status,p("api",i);}catch{}return a})};}function yt(e){let t="";try{typeof e=="string"?t=e:e&&typeof e.url=="string"?t=e.url:t=String(e);}catch{return true}return !(t.indexOf(".js.map")!==-1||t.indexOf(".log.aliyuncs.com")!==-1)}function le(){Tt();}function de(){ue(),le();}async function Je(e,{project:t,endpoint:r,logstore:n}){if(!t||!r||!n)return;let o=Math.floor(Date.now()/1e3),i={__logs__:e.map(l=>({__time__:o,...Object.keys(l).reduce((h,g)=>(h[g]=String(l[g]),h),{})})),__topic__:"default",__source__:"frontend"},a=JSON.stringify(i),s=`https://${t}.${r}/logstores/${n}/track?APIVersion=0.6.0`,c=await fetch(s,{method:"POST",headers:{"Content-Type":"application/json","x-log-apiversion":"0.6.0","x-log-bodyrawsize":a.length.toString()},body:a}),u=await c.text();if(!c.ok)throw new Error(`SLS API error: ${c.status} ${c.statusText} - ${u}`);return c}function vt(e,t,r=false){if(m.reportUrl===null){console.error("\u8BF7\u5148\u914D\u7F6E\u4E0A\u62A5\u5730\u5740");return}let n=[{user_id:Number(m.userId)||0,source:m.source,type:e,url:window.location.pathname,data:t}];if(r){fe(n);return}window.requestIdleCallback?window.requestIdleCallback(()=>{fe(n);},{timeout:3e3}):fe(n);}var Xe=null;function j(e,t,r,n=3e3){if(t=JSON.stringify({..._,...t}),Se(e,t),r){Ge(r);return}clearTimeout(Xe),Xe=setTimeout(()=>{Ge();},n);}function Ge(e=false){let t=we();if(t.size){for(let[r,n]of t)vt(r,n,e);Pe();}}function fe(e){Je(e,{project:m.slsProject,endpoint:m.slsEndpoint,logstore:m.slsLogstore}).catch(t=>{console.error("[reporting-lib] SLS\u4E0A\u62A5\u5931\u8D25:",t);});}function Ke(e,t={}){let{minDuration:r=1e3,debounceMs:n=300}=t,o=false,i=null,a=Date.now(),s=(()=>{try{return window.location?.pathname||"/"}catch{return "/"}})(),c,u=false,l=(d,f,P)=>{o||(i&&clearTimeout(i),i=setTimeout(()=>{if(!o&&f>=r)try{e(f,d,P),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}},n));},h=()=>{if(document.visibilityState==="hidden"){let d=Date.now(),f=d-a;l("visibilitychange-hidden",f,{startTime:a,endTime:d,pagePath:s,pageTag:c});}else if(document.visibilityState==="visible"){a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false;}};document.addEventListener("visibilitychange",h);let g=d=>{let f=Date.now(),P=f-a,b={startTime:a,endTime:f,pagePath:s,pageTag:c};d.persisted?l("pagehide-bfcache",P,b):l("pagehide",P,b);};window.addEventListener("pagehide",g);let y=()=>{if(!o){let d=Date.now(),f=d-a,P={startTime:a,endTime:d,pagePath:s,pageTag:c};if(f>=r)try{e(f,"beforeunload",P),o=!0;}catch(b){console.error("[trackPageStayTime] onLeave callback error:",b);}}};window.addEventListener("beforeunload",y);let T=()=>{let d=Date.now(),f=d-a;l("popstate",f,{startTime:a,endTime:d,pagePath:s,pageTag:c});};window.addEventListener("popstate",T);let me=()=>{a=Date.now();try{s=window.location?.pathname||s;}catch{}o=false,i&&(clearTimeout(i),i=null);},pe=(d="manual")=>{let f=Date.now(),P=f-a;l(d,P,{startTime:a,endTime:f,pagePath:s,pageTag:c}),d==="route-change"&&setTimeout(()=>{me();},n+50);},he=d=>{c=d||void 0,d&&(u=true);};return {manualLeave:pe,reset:me,stop:()=>{i&&(clearTimeout(i),i=null),document.removeEventListener("visibilitychange",h),window.removeEventListener("pagehide",g),window.removeEventListener("beforeunload",y),window.removeEventListener("popstate",T);},getCurrentDuration:()=>{let d=Date.now();return document.visibilityState==="visible"?d-a:0},setPageTag:he,switchPageTag:(d,f="page-tag-change")=>{c&&c!==d?(o=false,pe(f),a=Date.now()):u||(a=Date.now(),o=false),he(d);}}}var wt=e=>{try{if(e)return e||"/";let{pathname:t="/"}=window.location||{};return t||"/"}catch{return "/"}},Ye=(e,t,r,n={})=>{let{startTime:o,endTime:i,pagePath:a,pageTag:s}=r,c=wt(a),u=s?`${c}#${s}`:c,{formatPageName:l}=n;return {pageName:typeof l=="function"?l(u,{duration:e,reason:t,...r}):u,duration:e,startTime:o,endTime:i}};var S=null,L=null;function St(e={},t,r){let{enabled:n,minDuration:o,debounceMs:i,onLeave:a}=e;n?(S&&(S.stop(),S=null),S=Ke(a||r||((c,u,l)=>{}),{minDuration:o,debounceMs:i}),t&&t.listen&&(L&&(L(),L=null),L=t.listen(({location:c,action:u})=>{S&&(u==="PUSH"||u==="REPLACE")&&S.manualLeave("route-change");}))):S&&(S.stop(),S=null,L&&(L(),L=null));}function Qe(e,t){S?.switchPageTag(e,t);}function Ze(e,t){if(!e)return;St(e,t,(n,o,i)=>{let a=Ye(n,o,i||{startTime:0,endTime:0},{formatPageName:e?.formatPageName});j("pd",a);});}function et(e,t){let r=t||m.history;return !r||!r.listen?(console.warn("[reporting-lib] No history instance available. Please provide history in init() or pass it as parameter."),()=>{}):r.listen(e)}var tt=false,Pt={init(e={}){ge(e),Ze(e.trackPageStayTime,e.history),tt||(X(),ce(),de(),tt=true);},reportToSLS(e,t={},r={}){let{immediate:n=false,timeout:o=3e3}=r;j(e,t,n,o);},switchPageTag(e,t="page-tag-change"){Qe(e,t);},listenRouteChange(e,t){return et(e,t)}},Mn=Pt;
3
+ module.exports=Mn;//# sourceMappingURL=index.cjs.map
4
4
  //# sourceMappingURL=index.cjs.map