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/README.md CHANGED
@@ -91,22 +91,20 @@ interface TransportConfig {
91
91
  - **FP (First Paint)**: 首次绘制时间
92
92
  - **FCP (First Contentful Paint)**: 首次内容绘制时间
93
93
  - **LCP (Largest Contentful Paint)**: 最大内容绘制时间
94
- - **INP (Interaction to Next Paint)**: 交互到下一次绘制的延迟(关注交互响应性)
95
- - **Long Task**: 超过阈值的长任务(关注主线程阻塞)
94
+ - **LoAF (Long Animation Frame)**: 现代化的长任务监控,提供详尽的脚本级归因(Chrome 123+)
96
95
  - **Resource**: 仅监听 `fetch` 与 `xmlhttprequest` 的网络请求耗时
97
96
 
98
97
  **配置项:**
99
98
 
100
- - `longTaskThreshold`: 长任务阈值 (ms),默认 `100`
99
+ - `loafThreshold`: LoAF 阈值 (ms),默认 `50`
101
100
  - `resourceThreshold`: 资源加载阈值 (ms),默认 `1000`
102
- - `inpThreshold`: INP 阈值 (ms),默认 `200`
103
101
  - `filter`: 过滤函数,支持按类型过滤指标
104
102
 
105
103
  示例:
106
104
 
107
105
  ```typescript
108
106
  PerformancePlugin({
109
- longTaskThreshold: 200, // 仅记录超过 200ms 的长任务
107
+ loafThreshold: 150, // 仅记录超过 150ms 的 LoAF
110
108
  resourceThreshold: 2000, // 仅记录超过 2s 的请求
111
109
  });
112
110
  ```
package/dist/index.cjs CHANGED
@@ -109,9 +109,8 @@ function throttle(fn, delay) {
109
109
  const MAX_CACHE_LEN = 5;
110
110
  const MAX_WAITING_TIME = 3e4;
111
111
  const UUID = "track_uuid";
112
- const DEFAULT_LONG_TASK_THRESHOLD = 100;
113
112
  const DEFAULT_RESOURCE_THRESHOLD = 1e3;
114
- const DEFAULT_INP_THRESHOLD = 200;
113
+ const DEFAULT_LOAF_THRESHOLD = 50;
115
114
 
116
115
  var __defProp$3 = Object.defineProperty;
117
116
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -317,6 +316,7 @@ var EMIT_TYPE = /* @__PURE__ */ ((EMIT_TYPE2) => {
317
316
  EMIT_TYPE2["PERFORMANCE_INP"] = "performance_inp";
318
317
  EMIT_TYPE2["PERFORMANCE_LONGTASK"] = "performance_longtask";
319
318
  EMIT_TYPE2["PERFORMANCE_RESOURCE"] = "performance_resource";
319
+ EMIT_TYPE2["PERFORMANCE_LOAF"] = "performance_loaf";
320
320
  EMIT_TYPE2["XHR"] = "xhr";
321
321
  EMIT_TYPE2["FETCH"] = "fetch";
322
322
  EMIT_TYPE2["CUSTOM"] = "custom";
@@ -610,10 +610,8 @@ const PerformancePlugin = (options = {}) => {
610
610
  let context;
611
611
  let paintObserver = null;
612
612
  let lcpObserver = null;
613
- let inpObserver = null;
614
- let longTaskObserver = null;
615
613
  let resourceObserver = null;
616
- const interactionMap = /* @__PURE__ */ new Map();
614
+ let loafObserver = null;
617
615
  const monitorPaintMetrics = () => {
618
616
  const entryHandler = (list) => {
619
617
  for (const entry of list.getEntries()) {
@@ -657,63 +655,37 @@ const PerformancePlugin = (options = {}) => {
657
655
  console.warn("[CWJ Monitor] LCP observation not supported:", e);
658
656
  }
659
657
  };
660
- const monitorINP = () => {
658
+ const monitorLoAF = () => {
661
659
  const entryHandler = (list) => {
662
660
  for (const entry of list.getEntries()) {
663
- if (!entry.interactionId)
661
+ if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LOAF, entry)) {
664
662
  continue;
665
- const existing = interactionMap.get(entry.interactionId);
666
- if (existing) {
667
- clearTimeout(existing.timeoutId);
668
663
  }
669
- const maxEntry = existing && existing.entry.duration > entry.duration ? existing.entry : entry;
670
- const timeoutId = setTimeout(() => {
671
- interactionMap.delete(maxEntry.interactionId);
672
- if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_INP, maxEntry)) {
673
- return;
674
- }
675
- const threshold = options.inpThreshold ?? DEFAULT_INP_THRESHOLD;
676
- if (maxEntry.duration > threshold) {
677
- context?.emit(EMIT_TYPE.PERFORMANCE_INP, {
678
- value: maxEntry.duration,
679
- startTime: maxEntry.startTime,
680
- name: maxEntry.name,
681
- interactionId: maxEntry.interactionId
682
- });
683
- }
684
- }, 200);
685
- interactionMap.set(entry.interactionId, { entry: maxEntry, timeoutId });
686
- }
687
- };
688
- try {
689
- inpObserver = new PerformanceObserver(entryHandler);
690
- inpObserver.observe({ type: "event", buffered: true });
691
- } catch (e) {
692
- console.warn("[CWJ Monitor] INP observation not supported:", e);
693
- }
694
- };
695
- const monitorLongTask = () => {
696
- const entryHandler = (list) => {
697
- for (const entry of list.getEntries()) {
698
- if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LONGTASK, entry)) {
699
- continue;
700
- }
701
- const threshold = options.longTaskThreshold ?? DEFAULT_LONG_TASK_THRESHOLD;
664
+ const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
702
665
  if (entry.duration > threshold) {
703
- context?.emit(EMIT_TYPE.PERFORMANCE_LONGTASK, {
704
- startTime: entry.startTime,
666
+ context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
705
667
  duration: entry.duration,
706
- name: entry.name,
707
- attribution: entry.attribution
668
+ startTime: entry.startTime,
669
+ renderStart: entry.renderStart,
670
+ styleAndLayoutStart: entry.styleAndLayoutStart,
671
+ hadRecentInput: entry.hadRecentInput,
672
+ scripts: entry.scripts.map((s) => ({
673
+ duration: s.duration,
674
+ invoker: s.invoker,
675
+ invokerType: s.invokerType,
676
+ sourceURL: s.sourceURL,
677
+ functionName: s.functionName,
678
+ startTime: s.startTime
679
+ }))
708
680
  });
709
681
  }
710
682
  }
711
683
  };
712
684
  try {
713
- longTaskObserver = new PerformanceObserver(entryHandler);
714
- longTaskObserver.observe({ type: "longtask", buffered: true });
685
+ loafObserver = new PerformanceObserver(entryHandler);
686
+ loafObserver.observe({ type: "long-animation-frame", buffered: true });
715
687
  } catch (e) {
716
- console.warn("[CWJ Monitor] Long Task observation not supported:", e);
688
+ console.warn("[CWJ Monitor] LoAF observation not supported:", e);
717
689
  }
718
690
  };
719
691
  const monitorResource = () => {
@@ -753,18 +725,14 @@ const PerformancePlugin = (options = {}) => {
753
725
  context = ctx;
754
726
  monitorPaintMetrics();
755
727
  monitorLCP();
756
- monitorINP();
757
- monitorLongTask();
758
728
  monitorResource();
729
+ monitorLoAF();
759
730
  },
760
731
  uninstall: () => {
761
732
  paintObserver?.disconnect();
762
733
  lcpObserver?.disconnect();
763
- inpObserver?.disconnect();
764
- longTaskObserver?.disconnect();
765
734
  resourceObserver?.disconnect();
766
- interactionMap.forEach((value) => clearTimeout(value.timeoutId));
767
- interactionMap.clear();
735
+ loafObserver?.disconnect();
768
736
  }
769
737
  };
770
738
  };