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 +3 -5
- package/dist/index.cjs +24 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +24 -56
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.umd.js +24 -56
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
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
|
-
- **
|
|
95
|
-
- **Long Task**: 超过阈值的长任务(关注主线程阻塞)
|
|
94
|
+
- **LoAF (Long Animation Frame)**: 现代化的长任务监控,提供详尽的脚本级归因(Chrome 123+)
|
|
96
95
|
- **Resource**: 仅监听 `fetch` 与 `xmlhttprequest` 的网络请求耗时
|
|
97
96
|
|
|
98
97
|
**配置项:**
|
|
99
98
|
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
658
|
+
const monitorLoAF = () => {
|
|
661
659
|
const entryHandler = (list) => {
|
|
662
660
|
for (const entry of list.getEntries()) {
|
|
663
|
-
if (!entry
|
|
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
|
|
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.
|
|
704
|
-
startTime: entry.startTime,
|
|
666
|
+
context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
|
|
705
667
|
duration: entry.duration,
|
|
706
|
-
|
|
707
|
-
|
|
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
|
-
|
|
714
|
-
|
|
685
|
+
loafObserver = new PerformanceObserver(entryHandler);
|
|
686
|
+
loafObserver.observe({ type: "long-animation-frame", buffered: true });
|
|
715
687
|
} catch (e) {
|
|
716
|
-
console.warn("[CWJ Monitor]
|
|
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
|
-
|
|
767
|
-
interactionMap.clear();
|
|
735
|
+
loafObserver?.disconnect();
|
|
768
736
|
}
|
|
769
737
|
};
|
|
770
738
|
};
|