cwj_monitoring 0.0.24 → 0.0.26

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
@@ -109,13 +109,19 @@
109
109
  }
110
110
  };
111
111
  }
112
+ const isIgnoredScriptSource = (sourceURL) => {
113
+ if (!sourceURL || typeof sourceURL !== "string")
114
+ return false;
115
+ if (/node_modules/.test(sourceURL))
116
+ return true;
117
+ return false;
118
+ };
112
119
 
113
120
  const MAX_CACHE_LEN = 5;
114
121
  const MAX_WAITING_TIME = 3e4;
115
122
  const UUID = "track_uuid";
116
- const DEFAULT_LONG_TASK_THRESHOLD = 100;
117
123
  const DEFAULT_RESOURCE_THRESHOLD = 1e3;
118
- const DEFAULT_INP_THRESHOLD = 200;
124
+ const DEFAULT_LOAF_THRESHOLD = 50;
119
125
 
120
126
  var __defProp$3 = Object.defineProperty;
121
127
  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 +327,7 @@
321
327
  EMIT_TYPE2["PERFORMANCE_INP"] = "performance_inp";
322
328
  EMIT_TYPE2["PERFORMANCE_LONGTASK"] = "performance_longtask";
323
329
  EMIT_TYPE2["PERFORMANCE_RESOURCE"] = "performance_resource";
330
+ EMIT_TYPE2["PERFORMANCE_LOAF"] = "performance_loaf";
324
331
  EMIT_TYPE2["XHR"] = "xhr";
325
332
  EMIT_TYPE2["FETCH"] = "fetch";
326
333
  EMIT_TYPE2["CUSTOM"] = "custom";
@@ -614,10 +621,8 @@
614
621
  let context;
615
622
  let paintObserver = null;
616
623
  let lcpObserver = null;
617
- let inpObserver = null;
618
- let longTaskObserver = null;
619
624
  let resourceObserver = null;
620
- const interactionMap = /* @__PURE__ */ new Map();
625
+ let loafObserver = null;
621
626
  const monitorPaintMetrics = () => {
622
627
  const entryHandler = (list) => {
623
628
  for (const entry of list.getEntries()) {
@@ -661,63 +666,56 @@
661
666
  console.warn("[CWJ Monitor] LCP observation not supported:", e);
662
667
  }
663
668
  };
664
- const monitorINP = () => {
669
+ const monitorLoAF = () => {
665
670
  const entryHandler = (list) => {
666
671
  for (const entry of list.getEntries()) {
667
- if (!entry.interactionId)
672
+ if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LOAF, entry)) {
668
673
  continue;
669
- const existing = interactionMap.get(entry.interactionId);
670
- if (existing) {
671
- clearTimeout(existing.timeoutId);
672
674
  }
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;
675
+ const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
676
+ if (entry.duration > threshold) {
677
+ const scripts = Array.isArray(entry.scripts) ? entry.scripts : [];
678
+ let isUserTriggered = false;
679
+ let allIgnored = true;
680
+ for (let i = 0; i < scripts.length; i++) {
681
+ const s = scripts[i];
682
+ if (!s)
683
+ continue;
684
+ if (!isUserTriggered && s.invokerType === "user-callback")
685
+ isUserTriggered = true;
686
+ if (allIgnored && !isIgnoredScriptSource(s.sourceURL)) {
687
+ allIgnored = false;
688
+ }
689
+ if (isUserTriggered && !allIgnored)
690
+ break;
678
691
  }
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
692
+ if (isUserTriggered && !allIgnored) {
693
+ context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
694
+ duration: entry.duration,
695
+ startTime: entry.startTime,
696
+ renderStart: entry.renderStart,
697
+ styleAndLayoutStart: entry.styleAndLayoutStart,
698
+ hadRecentInput: entry.hadRecentInput,
699
+ scripts: entry.scripts.map((s) => ({
700
+ duration: s.duration,
701
+ invoker: s.invoker,
702
+ invokerType: s.invokerType,
703
+ sourceURL: s.sourceURL,
704
+ functionName: s.functionName,
705
+ sourceFunctionName: s.sourceFunctionName,
706
+ sourceCharPosition: s.sourceCharPosition,
707
+ startTime: s.startTime
708
+ }))
686
709
  });
687
710
  }
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;
706
- if (entry.duration > threshold) {
707
- context?.emit(EMIT_TYPE.PERFORMANCE_LONGTASK, {
708
- startTime: entry.startTime,
709
- duration: entry.duration,
710
- name: entry.name,
711
- attribution: entry.attribution
712
- });
713
711
  }
714
712
  }
715
713
  };
716
714
  try {
717
- longTaskObserver = new PerformanceObserver(entryHandler);
718
- longTaskObserver.observe({ type: "longtask", buffered: true });
715
+ loafObserver = new PerformanceObserver(entryHandler);
716
+ loafObserver.observe({ type: "long-animation-frame", buffered: true });
719
717
  } catch (e) {
720
- console.warn("[CWJ Monitor] Long Task observation not supported:", e);
718
+ console.warn("[CWJ Monitor] LoAF observation not supported:", e);
721
719
  }
722
720
  };
723
721
  const monitorResource = () => {
@@ -757,18 +755,14 @@
757
755
  context = ctx;
758
756
  monitorPaintMetrics();
759
757
  monitorLCP();
760
- monitorINP();
761
- monitorLongTask();
762
758
  monitorResource();
759
+ monitorLoAF();
763
760
  },
764
761
  uninstall: () => {
765
762
  paintObserver?.disconnect();
766
763
  lcpObserver?.disconnect();
767
- inpObserver?.disconnect();
768
- longTaskObserver?.disconnect();
769
764
  resourceObserver?.disconnect();
770
- interactionMap.forEach((value) => clearTimeout(value.timeoutId));
771
- interactionMap.clear();
765
+ loafObserver?.disconnect();
772
766
  }
773
767
  };
774
768
  };