@openreplay/tracker 17.2.1 → 17.2.3

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.
package/dist/cjs/index.js CHANGED
@@ -438,6 +438,23 @@ function deprecationWarn(nameOfFeature, useInstead, docsPath = '/') {
438
438
  console.warn(`OpenReplay: ${nameOfFeature} is deprecated. ${useInstead ? `Please, use ${useInstead} instead.` : ''} Visit ${DOCS_HOST}${docsPath} for more information.`);
439
439
  warnedFeatures[nameOfFeature] = true;
440
440
  }
441
+ function getCustomAttributeLabel(e, customAttributes) {
442
+ if (!customAttributes || customAttributes.length === 0)
443
+ return '';
444
+ const parts = [];
445
+ for (const attr of customAttributes) {
446
+ const value = e.getAttribute(attr);
447
+ if (value !== null) {
448
+ parts.push(`[${attr}=${value}]`);
449
+ }
450
+ }
451
+ return parts.join('');
452
+ }
453
+ function getClassSelector(e) {
454
+ if (!e.classList || e.classList.length === 0)
455
+ return '';
456
+ return '.' + Array.from(e.classList).join('.');
457
+ }
441
458
  function getLabelAttribute(e) {
442
459
  let value = e.getAttribute('data-openreplay-label');
443
460
  if (value !== null) {
@@ -3409,7 +3426,10 @@ class TopObserver extends Observer {
3409
3426
  this.app.debug.info('doc already observed for', id);
3410
3427
  return;
3411
3428
  }
3412
- const observer = new IFrameObserver(this.app, false, {});
3429
+ const observer = new IFrameObserver(this.app, false, {
3430
+ disableSprites: this.options.disableSprites,
3431
+ ...getInlineOptions(this.options.inlineCss, console.warn),
3432
+ });
3413
3433
  this.iframeObservers.set(iframe, observer);
3414
3434
  this.docObservers.set(currentDoc, observer);
3415
3435
  this.iframeObserversArr.push(observer);
@@ -3431,7 +3451,10 @@ class TopObserver extends Observer {
3431
3451
  handle();
3432
3452
  }
3433
3453
  handleShadowRoot(shRoot) {
3434
- const observer = new ShadowRootObserver(this.app);
3454
+ const observer = new ShadowRootObserver(this.app, false, {
3455
+ disableSprites: this.options.disableSprites,
3456
+ ...getInlineOptions(this.options.inlineCss, console.warn),
3457
+ });
3435
3458
  this.shadowRootObservers.set(shRoot, observer);
3436
3459
  observer.observe(shRoot.host);
3437
3460
  }
@@ -3467,7 +3490,10 @@ class TopObserver extends Observer {
3467
3490
  };
3468
3491
  this.app.nodes.clear();
3469
3492
  this.app.nodes.crossdomainMode(frameLevel, frameOder);
3470
- const iframeObserver = new IFrameObserver(this.app);
3493
+ const iframeObserver = new IFrameObserver(this.app, false, {
3494
+ disableSprites: this.options.disableSprites,
3495
+ ...getInlineOptions(this.options.inlineCss, console.warn),
3496
+ });
3471
3497
  this.iframeObservers.set(window.document, iframeObserver);
3472
3498
  iframeObserver.syntheticObserve(rootNodeId, window.document);
3473
3499
  }
@@ -3826,7 +3852,7 @@ class App {
3826
3852
  this.stopCallbacks = [];
3827
3853
  this.commitCallbacks = [];
3828
3854
  this.activityState = ActivityState.NotActive;
3829
- this.version = '17.2.1'; // TODO: version compatability check inside each plugin.
3855
+ this.version = '17.2.3'; // TODO: version compatability check inside each plugin.
3830
3856
  this.socketMode = false;
3831
3857
  this.compressionThreshold = 24 * 1000;
3832
3858
  this.bc = null;
@@ -4256,9 +4282,6 @@ class App {
4256
4282
  window.addEventListener('message', this.parentCrossDomainFrameListener);
4257
4283
  window.addEventListener('message', this.crossDomainIframeListener);
4258
4284
  setInterval(() => {
4259
- if (document.hidden) {
4260
- return;
4261
- }
4262
4285
  window.parent.postMessage({
4263
4286
  line: proto.polling,
4264
4287
  context: this.contextId,
@@ -5728,19 +5751,21 @@ const labelElementFor = IN_BROWSER && 'labels' in HTMLInputElement.prototype
5728
5751
  }
5729
5752
  }
5730
5753
  };
5731
- function getInputLabel(node) {
5732
- let label = getLabelAttribute(node);
5733
- if (label === null) {
5734
- const labelElement = labelElementFor(node);
5735
- label =
5736
- (labelElement && labelElement.innerText) ||
5737
- node.placeholder ||
5738
- node.name ||
5739
- node.id ||
5740
- node.className ||
5741
- node.type;
5742
- }
5743
- return normSpaces(label).slice(0, 100);
5754
+ function getInputLabel(node, customAttributes) {
5755
+ const openreplayLabel = getLabelAttribute(node);
5756
+ if (openreplayLabel !== null)
5757
+ return normSpaces(openreplayLabel).slice(0, 100);
5758
+ const customAttributeLabel = getCustomAttributeLabel(node, customAttributes);
5759
+ if (customAttributeLabel)
5760
+ return customAttributeLabel;
5761
+ if (node.id)
5762
+ return `#${node.id}`;
5763
+ const classLabel = getClassSelector(node);
5764
+ if (classLabel)
5765
+ return classLabel;
5766
+ const labelElement = labelElementFor(node);
5767
+ const label = node.name || node.placeholder || (labelElement && labelElement.innerText) || node.type;
5768
+ return normSpaces(label || '').slice(0, 100);
5744
5769
  }
5745
5770
  const InputMode = {
5746
5771
  Plain: 0,
@@ -5821,7 +5846,7 @@ function Input (app, opts) {
5821
5846
  }, 3);
5822
5847
  function sendInputChange(id, node, hesitationTime, inputTime) {
5823
5848
  const { value, mask } = getInputValue(id, node);
5824
- let label = getInputLabel(node);
5849
+ let label = getInputLabel(node, options.customAttributes);
5825
5850
  if (app.sanitizer.privateMode) {
5826
5851
  label = label.replaceAll(/./g, '*');
5827
5852
  }
@@ -5930,21 +5955,28 @@ function _getTarget(target, document) {
5930
5955
  return target === document.documentElement ? null : target;
5931
5956
  }
5932
5957
  function Mouse (app, options) {
5933
- const { disableClickmaps = false } = options || {};
5958
+ const { disableClickmaps = false, customAttributes } = options || {};
5934
5959
  function getTargetLabel(target) {
5935
5960
  const dl = getLabelAttribute(target);
5936
5961
  if (dl !== null) {
5937
5962
  return dl;
5938
5963
  }
5939
5964
  if (hasTag(target, 'input')) {
5940
- return getInputLabel(target);
5941
- }
5965
+ return getInputLabel(target, customAttributes);
5966
+ }
5967
+ const customAttributeLabel = getCustomAttributeLabel(target, customAttributes);
5968
+ if (customAttributeLabel)
5969
+ return customAttributeLabel;
5970
+ if (target.id)
5971
+ return `#${target.id}`;
5972
+ const classLabel = getClassSelector(target);
5973
+ if (classLabel)
5974
+ return classLabel;
5942
5975
  if (isClickable(target)) {
5943
5976
  let label = '';
5944
5977
  if (target instanceof HTMLElement) {
5945
5978
  label = app.sanitizer.getInnerTextSecure(target);
5946
5979
  }
5947
- label = label || target.id || target.className;
5948
5980
  return normSpaces(label).slice(0, 100);
5949
5981
  }
5950
5982
  return '';
@@ -6088,6 +6120,11 @@ function getCSSPath(el) {
6088
6120
  return false;
6089
6121
  if (el.id)
6090
6122
  return `#${cssEscape(el.id)}`;
6123
+ // if has data attributes - use them as they are more likely to be stable and unique
6124
+ const dataAttr = Array.from(el.attributes).find(attr => attr.name.startsWith('data-'));
6125
+ if (dataAttr) {
6126
+ return `[${dataAttr.name}="${cssEscape(dataAttr.value)}"]`;
6127
+ }
6091
6128
  const parts = [];
6092
6129
  while (el && el.nodeType === 1 && el !== el.ownerDocument) {
6093
6130
  if (el.id) {
@@ -6139,7 +6176,7 @@ function getUniqueSiblingClass(el) {
6139
6176
  return null;
6140
6177
  }
6141
6178
 
6142
- var e,o=-1,a=function(e){addEventListener("pageshow",(function(n){n.persisted&&(o=n.timeStamp,e(n));}),true);},c=function(){var e=self.performance&&performance.getEntriesByType&&performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},u=function(){var e=c();return e&&e.activationStart||0},f=function(e,n){var t=c(),r="navigate";o>=0?r="back-forward-cache":t&&(document.prerendering||u()>0?r="prerender":document.wasDiscarded?r="restore":t.type&&(r=t.type.replace(/_/g,"-")));return {name:e,value:void 0===n?-1:n,rating:"good",delta:0,entries:[],id:"v4-".concat(Date.now(),"-").concat(Math.floor(8999999999999*Math.random())+1e12),navigationType:r}},s=function(e,n,t){try{if(PerformanceObserver.supportedEntryTypes.includes(e)){var r=new PerformanceObserver((function(e){Promise.resolve().then((function(){n(e.getEntries());}));}));return r.observe(Object.assign({type:e,buffered:!0},t||{})),r}}catch(e){}},d=function(e,n,t,r){var i,o;return function(a){n.value>=0&&(a||r)&&((o=n.value-(i||0))||void 0===i)&&(i=n.value,n.delta=o,n.rating=function(e,n){return e>n[1]?"poor":e>n[0]?"needs-improvement":"good"}(n.value,t),e(n));}},l=function(e){requestAnimationFrame((function(){return requestAnimationFrame((function(){return e()}))}));},p=function(e){document.addEventListener("visibilitychange",(function(){"hidden"===document.visibilityState&&e();}));},v=function(e){var n=false;return function(){n||(e(),n=true);}},m=-1,h=function(){return "hidden"!==document.visibilityState||document.prerendering?1/0:0},g=function(e){"hidden"===document.visibilityState&&m>-1&&(m="visibilitychange"===e.type?e.timeStamp:0,T());},y=function(){addEventListener("visibilitychange",g,true),addEventListener("prerenderingchange",g,true);},T=function(){removeEventListener("visibilitychange",g,true),removeEventListener("prerenderingchange",g,true);},E=function(){return m<0&&(m=h(),y(),a((function(){setTimeout((function(){m=h(),y();}),0);}))),{get firstHiddenTime(){return m}}},C=function(e){document.prerendering?addEventListener("prerenderingchange",(function(){return e()}),true):e();},b=[1800,3e3],S=function(e,n){n=n||{},C((function(){var t,r=E(),i=f("FCP"),o=s("paint",(function(e){e.forEach((function(e){"first-contentful-paint"===e.name&&(o.disconnect(),e.startTime<r.firstHiddenTime&&(i.value=Math.max(e.startTime-u(),0),i.entries.push(e),t(true)));}));}));o&&(t=d(e,i,b,n.reportAllChanges),a((function(r){i=f("FCP"),t=d(e,i,b,n.reportAllChanges),l((function(){i.value=performance.now()-r.timeStamp,t(true);}));})));}));},L=[.1,.25],w=function(e,n){n=n||{},S(v((function(){var t,r=f("CLS",0),i=0,o=[],c=function(e){e.forEach((function(e){if(!e.hadRecentInput){var n=o[0],t=o[o.length-1];i&&e.startTime-t.startTime<1e3&&e.startTime-n.startTime<5e3?(i+=e.value,o.push(e)):(i=e.value,o=[e]);}})),i>r.value&&(r.value=i,r.entries=o,t());},u=s("layout-shift",c);u&&(t=d(e,r,L,n.reportAllChanges),p((function(){c(u.takeRecords()),t(true);})),a((function(){i=0,r=f("CLS",0),t=d(e,r,L,n.reportAllChanges),l((function(){return t()}));})),setTimeout(t,0));})));},A=0,I=1/0,P=0,M=function(e){e.forEach((function(e){e.interactionId&&(I=Math.min(I,e.interactionId),P=Math.max(P,e.interactionId),A=P?(P-I)/7+1:0);}));},k=function(){return e?A:performance.interactionCount||0},F=function(){"interactionCount"in performance||e||(e=s("event",M,{type:"event",buffered:true,durationThreshold:0}));},D=[],x=new Map,R=0,B=function(){var e=Math.min(D.length-1,Math.floor((k()-R)/50));return D[e]},H=[],q=function(e){if(H.forEach((function(n){return n(e)})),e.interactionId||"first-input"===e.entryType){var n=D[D.length-1],t=x.get(e.interactionId);if(t||D.length<10||e.duration>n.latency){if(t)e.duration>t.latency?(t.entries=[e],t.latency=e.duration):e.duration===t.latency&&e.startTime===t.entries[0].startTime&&t.entries.push(e);else {var r={id:e.interactionId,latency:e.duration,entries:[e]};x.set(r.id,r),D.push(r);}D.sort((function(e,n){return n.latency-e.latency})),D.length>10&&D.splice(10).forEach((function(e){return x.delete(e.id)}));}}},O=function(e){var n=self.requestIdleCallback||self.setTimeout,t=-1;return e=v(e),"hidden"===document.visibilityState?e():(t=n(e),p(e)),t},N=[200,500],j=function(e,n){"PerformanceEventTiming"in self&&"interactionId"in PerformanceEventTiming.prototype&&(n=n||{},C((function(){var t;F();var r,i=f("INP"),o=function(e){O((function(){e.forEach(q);var n=B();n&&n.latency!==i.value&&(i.value=n.latency,i.entries=n.entries,r());}));},c=s("event",o,{durationThreshold:null!==(t=n.durationThreshold)&&void 0!==t?t:40});r=d(e,i,N,n.reportAllChanges),c&&(c.observe({type:"first-input",buffered:true}),p((function(){o(c.takeRecords()),r(true);})),a((function(){R=k(),D.length=0,x.clear(),i=f("INP"),r=d(e,i,N,n.reportAllChanges);})));})));},_=[2500,4e3],z={},G=function(e,n){n=n||{},C((function(){var t,r=E(),i=f("LCP"),o=function(e){n.reportAllChanges||(e=e.slice(-1)),e.forEach((function(e){e.startTime<r.firstHiddenTime&&(i.value=Math.max(e.startTime-u(),0),i.entries=[e],t());}));},c=s("largest-contentful-paint",o);if(c){t=d(e,i,_,n.reportAllChanges);var m=v((function(){z[i.id]||(o(c.takeRecords()),c.disconnect(),z[i.id]=true,t(true));}));["keydown","click"].forEach((function(e){addEventListener(e,(function(){return O(m)}),{once:true,capture:true});})),p(m),a((function(r){i=f("LCP"),t=d(e,i,_,n.reportAllChanges),l((function(){i.value=performance.now()-r.timeStamp,z[i.id]=true,t(true);}));}));}}));},J=[800,1800],K=function e(n){document.prerendering?C((function(){return e(n)})):"complete"!==document.readyState?addEventListener("load",(function(){return e(n)}),true):setTimeout(n,0);},Q=function(e,n){n=n||{};var t=f("TTFB"),r=d(e,t,J,n.reportAllChanges);K((function(){var i=c();i&&(t.value=Math.max(i.responseStart-u(),0),t.entries=[i],r(true),a((function(){t=f("TTFB",0),(r=d(e,t,J,n.reportAllChanges))(true);})));}));};
6179
+ let e=-1;const t=t=>{addEventListener("pageshow",(n=>{n.persisted&&(e=n.timeStamp,t(n));}),true);},n=(e,t,n,i)=>{let s,o;return r=>{t.value>=0&&(r||i)&&(o=t.value-(s??0),(o||void 0===s)&&(s=t.value,t.delta=o,t.rating=((e,t)=>e>t[1]?"poor":e>t[0]?"needs-improvement":"good")(t.value,n),e(t)));}},i=e=>{requestAnimationFrame((()=>requestAnimationFrame((()=>e()))));},s=()=>{const e=performance.getEntriesByType("navigation")[0];if(e&&e.responseStart>0&&e.responseStart<performance.now())return e},o=()=>{const e=s();return e?.activationStart??0},r=(t,n=-1)=>{const i=s();let r="navigate";e>=0?r="back-forward-cache":i&&(document.prerendering||o()>0?r="prerender":document.wasDiscarded?r="restore":i.type&&(r=i.type.replace(/_/g,"-")));return {name:t,value:n,rating:"good",delta:0,entries:[],id:`v5-${Date.now()}-${Math.floor(8999999999999*Math.random())+1e12}`,navigationType:r}},c=new WeakMap;function a(e,t){return c.get(e)||c.set(e,new t),c.get(e)}class d{t;i=0;o=[];h(e){if(e.hadRecentInput)return;const t=this.o[0],n=this.o.at(-1);this.i&&t&&n&&e.startTime-n.startTime<1e3&&e.startTime-t.startTime<5e3?(this.i+=e.value,this.o.push(e)):(this.i=e.value,this.o=[e]),this.t?.(e);}}const h=(e,t,n={})=>{try{if(PerformanceObserver.supportedEntryTypes.includes(e)){const i=new PerformanceObserver((e=>{Promise.resolve().then((()=>{t(e.getEntries());}));}));return i.observe({type:e,buffered:!0,...n}),i}}catch{}},f=e=>{let t=false;return ()=>{t||(e(),t=true);}};let u=-1;const l=new Set,m=()=>"hidden"!==document.visibilityState||document.prerendering?1/0:0,p=e=>{if("hidden"===document.visibilityState){if("visibilitychange"===e.type)for(const e of l)e();isFinite(u)||(u="visibilitychange"===e.type?e.timeStamp:0,removeEventListener("prerenderingchange",p,true));}},v=()=>{if(u<0){const e=o(),n=document.prerendering?void 0:globalThis.performance.getEntriesByType("visibility-state").filter((t=>"hidden"===t.name&&t.startTime>e))[0]?.startTime;u=n??m(),addEventListener("visibilitychange",p,true),addEventListener("prerenderingchange",p,true),t((()=>{setTimeout((()=>{u=m();}));}));}return {get firstHiddenTime(){return u},onHidden(e){l.add(e);}}},g=e=>{document.prerendering?addEventListener("prerenderingchange",(()=>e()),true):e();},y=[1800,3e3],E=(e,s={})=>{g((()=>{const c=v();let a,d=r("FCP");const f=h("paint",(e=>{for(const t of e)"first-contentful-paint"===t.name&&(f.disconnect(),t.startTime<c.firstHiddenTime&&(d.value=Math.max(t.startTime-o(),0),d.entries.push(t),a(true)));}));f&&(a=n(e,d,y,s.reportAllChanges),t((t=>{d=r("FCP"),a=n(e,d,y,s.reportAllChanges),i((()=>{d.value=performance.now()-t.timeStamp,a(true);}));})));}));},b=[.1,.25],L=(e,s={})=>{const o=v();E(f((()=>{let c,f=r("CLS",0);const u=a(s,d),l=e=>{for(const t of e)u.h(t);u.i>f.value&&(f.value=u.i,f.entries=u.o,c());},m=h("layout-shift",l);m&&(c=n(e,f,b,s.reportAllChanges),o.onHidden((()=>{l(m.takeRecords()),c(true);})),t((()=>{u.i=0,f=r("CLS",0),c=n(e,f,b,s.reportAllChanges),i((()=>c()));})),setTimeout(c));})));};let P=0,T=1/0,_=0;const M=e=>{for(const t of e)t.interactionId&&(T=Math.min(T,t.interactionId),_=Math.max(_,t.interactionId),P=_?(_-T)/7+1:0);};let w;const C=()=>w?P:performance.interactionCount??0,I=()=>{"interactionCount"in performance||w||(w=h("event",M,{type:"event",buffered:true,durationThreshold:0}));};let F=0;class k{u=[];l=new Map;m;p;v(){F=C(),this.u.length=0,this.l.clear();}L(){const e=Math.min(this.u.length-1,Math.floor((C()-F)/50));return this.u[e]}h(e){if(this.m?.(e),!e.interactionId&&"first-input"!==e.entryType)return;const t=this.u.at(-1);let n=this.l.get(e.interactionId);if(n||this.u.length<10||e.duration>t.P){if(n?e.duration>n.P?(n.entries=[e],n.P=e.duration):e.duration===n.P&&e.startTime===n.entries[0].startTime&&n.entries.push(e):(n={id:e.interactionId,entries:[e],P:e.duration},this.l.set(n.id,n),this.u.push(n)),this.u.sort(((e,t)=>t.P-e.P)),this.u.length>10){const e=this.u.splice(10);for(const t of e)this.l.delete(t.id);}this.p?.(n);}}}const A=e=>{const t=globalThis.requestIdleCallback||setTimeout;"hidden"===document.visibilityState?e():(e=f(e),addEventListener("visibilitychange",e,{once:true,capture:true}),t((()=>{e(),removeEventListener("visibilitychange",e,{capture:true});})));},B=[200,500],S=(e,i={})=>{if(!globalThis.PerformanceEventTiming||!("interactionId"in PerformanceEventTiming.prototype))return;const s=v();g((()=>{I();let o,c=r("INP");const d=a(i,k),f=e=>{A((()=>{for(const t of e)d.h(t);const t=d.L();t&&t.P!==c.value&&(c.value=t.P,c.entries=t.entries,o());}));},u=h("event",f,{durationThreshold:i.durationThreshold??40});o=n(e,c,B,i.reportAllChanges),u&&(u.observe({type:"first-input",buffered:true}),s.onHidden((()=>{f(u.takeRecords()),o(true);})),t((()=>{d.v(),c=r("INP"),o=n(e,c,B,i.reportAllChanges);})));}));};class N{m;h(e){this.m?.(e);}}const q=[2500,4e3],x=(e,s={})=>{g((()=>{const c=v();let d,u=r("LCP");const l=a(s,N),m=e=>{s.reportAllChanges||(e=e.slice(-1));for(const t of e)l.h(t),t.startTime<c.firstHiddenTime&&(u.value=Math.max(t.startTime-o(),0),u.entries=[t],d());},p=h("largest-contentful-paint",m);if(p){d=n(e,u,q,s.reportAllChanges);const o=f((()=>{m(p.takeRecords()),p.disconnect(),d(true);})),c=e=>{e.isTrusted&&(A(o),removeEventListener(e.type,c,{capture:true}));};for(const e of ["keydown","click","visibilitychange"])addEventListener(e,c,{capture:true});t((t=>{u=r("LCP"),d=n(e,u,q,s.reportAllChanges),i((()=>{u.value=performance.now()-t.timeStamp,d(true);}));}));}}));},H=[800,1800],O=e=>{document.prerendering?g((()=>O(e))):"complete"!==document.readyState?addEventListener("load",(()=>O(e)),true):setTimeout(e);},$=(e,i={})=>{let c=r("TTFB"),a=n(e,c,H,i.reportAllChanges);O((()=>{const d=s();d&&(c.value=Math.max(d.responseStart-o(),0),c.entries=[d],a(true),t((()=>{c=r("TTFB",0),a=n(e,c,H,i.reportAllChanges),a(true);})));}));};
6143
6180
 
6144
6181
  function getPaintBlocks(resources) {
6145
6182
  const paintBlocks = [];
@@ -6272,10 +6309,10 @@ function Timing (app, opts) {
6272
6309
  // onINP(): Chromium
6273
6310
  // onLCP(): Chromium, Firefox
6274
6311
  // onTTFB(): Chromium, Firefox, Safari
6275
- w(onVitalsSignal);
6276
- j(onVitalsSignal);
6277
- G(onVitalsSignal);
6278
- Q(onVitalsSignal);
6312
+ L(onVitalsSignal);
6313
+ S(onVitalsSignal);
6314
+ x(onVitalsSignal);
6315
+ $(onVitalsSignal);
6279
6316
  });
6280
6317
  app.attachStopCallback(function () {
6281
6318
  observer.disconnect();
@@ -7076,7 +7113,9 @@ class NetworkMessage {
7076
7113
  });
7077
7114
  if (!messageInfo)
7078
7115
  return null;
7079
- const isGraphql = messageInfo.url.includes("/graphql");
7116
+ const gqlHeader = "application/graphql-response";
7117
+ const isGraphql = messageInfo.url.includes("/graphql")
7118
+ || Object.values(messageInfo.request.headers).some(v => v.includes(gqlHeader));
7080
7119
  if (isGraphql && messageInfo.response.body && typeof messageInfo.response.body === 'string') {
7081
7120
  const isError = messageInfo.response.body.includes("errors");
7082
7121
  messageInfo.status = isError ? 400 : 200;
@@ -7382,6 +7421,7 @@ class FetchProxyHandler {
7382
7421
  this.tokenUrlMatcher = tokenUrlMatcher;
7383
7422
  }
7384
7423
  apply(target, _, argsList) {
7424
+ var _a;
7385
7425
  const input = argsList[0];
7386
7426
  const init = argsList[1];
7387
7427
  if (!input ||
@@ -7397,6 +7437,31 @@ class FetchProxyHandler {
7397
7437
  }
7398
7438
  const item = new NetworkMessage(this.ignoredHeaders, this.setSessionTokenHeader, this.sanitize);
7399
7439
  this.beforeFetch(item, input, init);
7440
+ const signal = (argsList[0] instanceof Request ? argsList[0].signal : undefined) ||
7441
+ ((_a = argsList[1]) === null || _a === void 0 ? void 0 : _a.signal);
7442
+ // guard to avoid double-send
7443
+ let abortedNotified = false;
7444
+ const notifyAbort = () => {
7445
+ if (abortedNotified)
7446
+ return;
7447
+ abortedNotified = true;
7448
+ item.endTime = performance.now();
7449
+ item.duration = item.endTime - (item.startTime || item.endTime);
7450
+ item.status = 0;
7451
+ item.statusText = "Aborted";
7452
+ item.readyState = 0;
7453
+ const msg = item.getMessage();
7454
+ if (msg)
7455
+ this.sendMessage(msg);
7456
+ };
7457
+ if (signal) {
7458
+ if (signal.aborted) {
7459
+ notifyAbort();
7460
+ }
7461
+ else {
7462
+ signal.addEventListener("abort", notifyAbort, { once: true });
7463
+ }
7464
+ }
7400
7465
  this.setSessionTokenHeader((name, value) => {
7401
7466
  if (this.tokenUrlMatcher !== undefined) {
7402
7467
  if (!this.tokenUrlMatcher(item.url)) {
@@ -7425,11 +7490,22 @@ class FetchProxyHandler {
7425
7490
  }
7426
7491
  });
7427
7492
  return target.apply(window, argsList)
7428
- .then(this.afterFetch(item))
7493
+ .then(this.afterFetch(item, () => {
7494
+ abortedNotified = true;
7495
+ }))
7429
7496
  .catch((e) => {
7430
- // mock finally
7431
7497
  item.endTime = performance.now();
7432
7498
  item.duration = item.endTime - (item.startTime || item.endTime);
7499
+ if (e && e.name === "AbortError") {
7500
+ item.status = 0;
7501
+ item.statusText = "Aborted";
7502
+ item.readyState = 0;
7503
+ if (!abortedNotified) {
7504
+ const msg = item.getMessage();
7505
+ if (msg)
7506
+ this.sendMessage(msg);
7507
+ }
7508
+ }
7433
7509
  throw e;
7434
7510
  });
7435
7511
  }
@@ -7481,8 +7557,10 @@ class FetchProxyHandler {
7481
7557
  item.requestData = genStringBody(init.body);
7482
7558
  }
7483
7559
  }
7484
- afterFetch(item) {
7560
+ afterFetch(item, onResolved) {
7485
7561
  return (resp) => {
7562
+ if (onResolved)
7563
+ onResolved === null || onResolved === void 0 ? void 0 : onResolved();
7486
7564
  item.endTime = performance.now();
7487
7565
  item.duration = item.endTime - (item.startTime || item.endTime);
7488
7566
  item.status = resp.status;
@@ -7518,7 +7596,15 @@ class FetchProxyHandler {
7518
7596
  }
7519
7597
  })
7520
7598
  .catch((e) => {
7521
- if (e.name !== "AbortError") {
7599
+ if (e.name === "AbortError") {
7600
+ item.status = 0;
7601
+ item.statusText = "Aborted";
7602
+ item.readyState = 0;
7603
+ const msg = item.getMessage();
7604
+ if (msg)
7605
+ this.sendMessage(msg);
7606
+ }
7607
+ else {
7522
7608
  throw e;
7523
7609
  }
7524
7610
  });
@@ -8619,7 +8705,7 @@ class ConstantProperties {
8619
8705
  user_id: this.user_id,
8620
8706
  distinct_id: this.deviceId,
8621
8707
  sdk_edition: 'web',
8622
- sdk_version: '17.2.1',
8708
+ sdk_version: '17.2.3',
8623
8709
  timezone: getUTCOffsetString(),
8624
8710
  search_engine: this.searchEngine,
8625
8711
  };
@@ -9062,9 +9148,12 @@ class Batcher {
9062
9148
  })
9063
9149
  .then((response) => {
9064
9150
  if ([403, 401].includes(response.status)) {
9065
- this.init().then(() => {
9066
- send();
9067
- });
9151
+ if (attempts < this.retryLimit) {
9152
+ return this.init().then(() => {
9153
+ send();
9154
+ });
9155
+ }
9156
+ return;
9068
9157
  }
9069
9158
  if (!response.ok) {
9070
9159
  throw new Error(`HTTP error! status: ${response.status}`);
@@ -9079,6 +9168,9 @@ class Batcher {
9079
9168
  void send();
9080
9169
  }
9081
9170
  startAutosend() {
9171
+ if (this.intervalId) {
9172
+ clearInterval(this.intervalId);
9173
+ }
9082
9174
  this.intervalId = setInterval(() => {
9083
9175
  this.flush();
9084
9176
  }, this.autosendInterval);
@@ -9127,7 +9219,9 @@ class Analytics {
9127
9219
  if (this.standalone) {
9128
9220
  return this.token;
9129
9221
  }
9130
- return this.getToken();
9222
+ else {
9223
+ return this.getToken();
9224
+ }
9131
9225
  };
9132
9226
  this._getTimestamp = () => {
9133
9227
  if (this.standalone) {
@@ -9263,7 +9357,7 @@ class API {
9263
9357
  this.signalStartIssue = (reason, missingApi) => {
9264
9358
  const doNotTrack = this.checkDoNotTrack();
9265
9359
  console.log("Tracker couldn't start due to:", JSON.stringify({
9266
- trackerVersion: '17.2.1',
9360
+ trackerVersion: '17.2.3',
9267
9361
  projectKey: this.options.projectKey,
9268
9362
  doNotTrack,
9269
9363
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,
@@ -9426,7 +9520,7 @@ class API {
9426
9520
  // no tabs in iframes yet
9427
9521
  Tabs(app);
9428
9522
  }
9429
- Mouse(app, options.mouse);
9523
+ Mouse(app, { ...options.mouse, customAttributes: options.customAttributes });
9430
9524
  // inside iframe, we ignore viewport scroll
9431
9525
  Scroll(app, this.crossdomainMode);
9432
9526
  CSSRules(app, options.css);