cwj_monitoring 0.0.24 → 0.0.25

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/index.umd.js CHANGED
@@ -113,9 +113,8 @@
113
113
  const MAX_CACHE_LEN = 5;
114
114
  const MAX_WAITING_TIME = 3e4;
115
115
  const UUID = "track_uuid";
116
- const DEFAULT_LONG_TASK_THRESHOLD = 100;
117
116
  const DEFAULT_RESOURCE_THRESHOLD = 1e3;
118
- const DEFAULT_INP_THRESHOLD = 200;
117
+ const DEFAULT_LOAF_THRESHOLD = 50;
119
118
 
120
119
  var __defProp$3 = Object.defineProperty;
121
120
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -321,6 +320,7 @@
321
320
  EMIT_TYPE2["PERFORMANCE_INP"] = "performance_inp";
322
321
  EMIT_TYPE2["PERFORMANCE_LONGTASK"] = "performance_longtask";
323
322
  EMIT_TYPE2["PERFORMANCE_RESOURCE"] = "performance_resource";
323
+ EMIT_TYPE2["PERFORMANCE_LOAF"] = "performance_loaf";
324
324
  EMIT_TYPE2["XHR"] = "xhr";
325
325
  EMIT_TYPE2["FETCH"] = "fetch";
326
326
  EMIT_TYPE2["CUSTOM"] = "custom";
@@ -614,10 +614,8 @@
614
614
  let context;
615
615
  let paintObserver = null;
616
616
  let lcpObserver = null;
617
- let inpObserver = null;
618
- let longTaskObserver = null;
619
617
  let resourceObserver = null;
620
- const interactionMap = /* @__PURE__ */ new Map();
618
+ let loafObserver = null;
621
619
  const monitorPaintMetrics = () => {
622
620
  const entryHandler = (list) => {
623
621
  for (const entry of list.getEntries()) {
@@ -661,63 +659,37 @@
661
659
  console.warn("[CWJ Monitor] LCP observation not supported:", e);
662
660
  }
663
661
  };
664
- const monitorINP = () => {
662
+ const monitorLoAF = () => {
665
663
  const entryHandler = (list) => {
666
664
  for (const entry of list.getEntries()) {
667
- if (!entry.interactionId)
665
+ if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LOAF, entry)) {
668
666
  continue;
669
- const existing = interactionMap.get(entry.interactionId);
670
- if (existing) {
671
- clearTimeout(existing.timeoutId);
672
667
  }
673
- const maxEntry = existing && existing.entry.duration > entry.duration ? existing.entry : entry;
674
- const timeoutId = setTimeout(() => {
675
- interactionMap.delete(maxEntry.interactionId);
676
- if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_INP, maxEntry)) {
677
- return;
678
- }
679
- const threshold = options.inpThreshold ?? DEFAULT_INP_THRESHOLD;
680
- if (maxEntry.duration > threshold) {
681
- context?.emit(EMIT_TYPE.PERFORMANCE_INP, {
682
- value: maxEntry.duration,
683
- startTime: maxEntry.startTime,
684
- name: maxEntry.name,
685
- interactionId: maxEntry.interactionId
686
- });
687
- }
688
- }, 200);
689
- interactionMap.set(entry.interactionId, { entry: maxEntry, timeoutId });
690
- }
691
- };
692
- try {
693
- inpObserver = new PerformanceObserver(entryHandler);
694
- inpObserver.observe({ type: "event", buffered: true });
695
- } catch (e) {
696
- console.warn("[CWJ Monitor] INP observation not supported:", e);
697
- }
698
- };
699
- const monitorLongTask = () => {
700
- const entryHandler = (list) => {
701
- for (const entry of list.getEntries()) {
702
- if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LONGTASK, entry)) {
703
- continue;
704
- }
705
- const threshold = options.longTaskThreshold ?? DEFAULT_LONG_TASK_THRESHOLD;
668
+ const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
706
669
  if (entry.duration > threshold) {
707
- context?.emit(EMIT_TYPE.PERFORMANCE_LONGTASK, {
708
- startTime: entry.startTime,
670
+ context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
709
671
  duration: entry.duration,
710
- name: entry.name,
711
- attribution: entry.attribution
672
+ startTime: entry.startTime,
673
+ renderStart: entry.renderStart,
674
+ styleAndLayoutStart: entry.styleAndLayoutStart,
675
+ hadRecentInput: entry.hadRecentInput,
676
+ scripts: entry.scripts.map((s) => ({
677
+ duration: s.duration,
678
+ invoker: s.invoker,
679
+ invokerType: s.invokerType,
680
+ sourceURL: s.sourceURL,
681
+ functionName: s.functionName,
682
+ startTime: s.startTime
683
+ }))
712
684
  });
713
685
  }
714
686
  }
715
687
  };
716
688
  try {
717
- longTaskObserver = new PerformanceObserver(entryHandler);
718
- longTaskObserver.observe({ type: "longtask", buffered: true });
689
+ loafObserver = new PerformanceObserver(entryHandler);
690
+ loafObserver.observe({ type: "long-animation-frame", buffered: true });
719
691
  } catch (e) {
720
- console.warn("[CWJ Monitor] Long Task observation not supported:", e);
692
+ console.warn("[CWJ Monitor] LoAF observation not supported:", e);
721
693
  }
722
694
  };
723
695
  const monitorResource = () => {
@@ -757,18 +729,14 @@
757
729
  context = ctx;
758
730
  monitorPaintMetrics();
759
731
  monitorLCP();
760
- monitorINP();
761
- monitorLongTask();
762
732
  monitorResource();
733
+ monitorLoAF();
763
734
  },
764
735
  uninstall: () => {
765
736
  paintObserver?.disconnect();
766
737
  lcpObserver?.disconnect();
767
- inpObserver?.disconnect();
768
- longTaskObserver?.disconnect();
769
738
  resourceObserver?.disconnect();
770
- interactionMap.forEach((value) => clearTimeout(value.timeoutId));
771
- interactionMap.clear();
739
+ loafObserver?.disconnect();
772
740
  }
773
741
  };
774
742
  };