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/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare enum EMIT_TYPE {
|
|
|
12
12
|
PERFORMANCE_INP = "performance_inp",
|
|
13
13
|
PERFORMANCE_LONGTASK = "performance_longtask",
|
|
14
14
|
PERFORMANCE_RESOURCE = "performance_resource",
|
|
15
|
+
PERFORMANCE_LOAF = "performance_loaf",
|
|
15
16
|
XHR = "xhr",
|
|
16
17
|
FETCH = "fetch",
|
|
17
18
|
CUSTOM = "custom"
|
|
@@ -273,6 +274,8 @@ interface PerformanceOptions {
|
|
|
273
274
|
resourceThreshold?: number;
|
|
274
275
|
/** INP 阈值 (ms),超过此值则上报,默认 200 */
|
|
275
276
|
inpThreshold?: number;
|
|
277
|
+
/** LoAF 阈值 (ms),超过此值则上报,默认 100 */
|
|
278
|
+
loafThreshold?: number;
|
|
276
279
|
}
|
|
277
280
|
declare const PerformancePlugin: (options?: PerformanceOptions) => IPlugin;
|
|
278
281
|
|
package/dist/index.js
CHANGED
|
@@ -107,9 +107,8 @@ function throttle(fn, delay) {
|
|
|
107
107
|
const MAX_CACHE_LEN = 5;
|
|
108
108
|
const MAX_WAITING_TIME = 3e4;
|
|
109
109
|
const UUID = "track_uuid";
|
|
110
|
-
const DEFAULT_LONG_TASK_THRESHOLD = 100;
|
|
111
110
|
const DEFAULT_RESOURCE_THRESHOLD = 1e3;
|
|
112
|
-
const
|
|
111
|
+
const DEFAULT_LOAF_THRESHOLD = 50;
|
|
113
112
|
|
|
114
113
|
var __defProp$3 = Object.defineProperty;
|
|
115
114
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -315,6 +314,7 @@ var EMIT_TYPE = /* @__PURE__ */ ((EMIT_TYPE2) => {
|
|
|
315
314
|
EMIT_TYPE2["PERFORMANCE_INP"] = "performance_inp";
|
|
316
315
|
EMIT_TYPE2["PERFORMANCE_LONGTASK"] = "performance_longtask";
|
|
317
316
|
EMIT_TYPE2["PERFORMANCE_RESOURCE"] = "performance_resource";
|
|
317
|
+
EMIT_TYPE2["PERFORMANCE_LOAF"] = "performance_loaf";
|
|
318
318
|
EMIT_TYPE2["XHR"] = "xhr";
|
|
319
319
|
EMIT_TYPE2["FETCH"] = "fetch";
|
|
320
320
|
EMIT_TYPE2["CUSTOM"] = "custom";
|
|
@@ -608,10 +608,8 @@ const PerformancePlugin = (options = {}) => {
|
|
|
608
608
|
let context;
|
|
609
609
|
let paintObserver = null;
|
|
610
610
|
let lcpObserver = null;
|
|
611
|
-
let inpObserver = null;
|
|
612
|
-
let longTaskObserver = null;
|
|
613
611
|
let resourceObserver = null;
|
|
614
|
-
|
|
612
|
+
let loafObserver = null;
|
|
615
613
|
const monitorPaintMetrics = () => {
|
|
616
614
|
const entryHandler = (list) => {
|
|
617
615
|
for (const entry of list.getEntries()) {
|
|
@@ -655,63 +653,37 @@ const PerformancePlugin = (options = {}) => {
|
|
|
655
653
|
console.warn("[CWJ Monitor] LCP observation not supported:", e);
|
|
656
654
|
}
|
|
657
655
|
};
|
|
658
|
-
const
|
|
656
|
+
const monitorLoAF = () => {
|
|
659
657
|
const entryHandler = (list) => {
|
|
660
658
|
for (const entry of list.getEntries()) {
|
|
661
|
-
if (!entry
|
|
659
|
+
if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LOAF, entry)) {
|
|
662
660
|
continue;
|
|
663
|
-
const existing = interactionMap.get(entry.interactionId);
|
|
664
|
-
if (existing) {
|
|
665
|
-
clearTimeout(existing.timeoutId);
|
|
666
661
|
}
|
|
667
|
-
const
|
|
668
|
-
const timeoutId = setTimeout(() => {
|
|
669
|
-
interactionMap.delete(maxEntry.interactionId);
|
|
670
|
-
if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_INP, maxEntry)) {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
const threshold = options.inpThreshold ?? DEFAULT_INP_THRESHOLD;
|
|
674
|
-
if (maxEntry.duration > threshold) {
|
|
675
|
-
context?.emit(EMIT_TYPE.PERFORMANCE_INP, {
|
|
676
|
-
value: maxEntry.duration,
|
|
677
|
-
startTime: maxEntry.startTime,
|
|
678
|
-
name: maxEntry.name,
|
|
679
|
-
interactionId: maxEntry.interactionId
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
}, 200);
|
|
683
|
-
interactionMap.set(entry.interactionId, { entry: maxEntry, timeoutId });
|
|
684
|
-
}
|
|
685
|
-
};
|
|
686
|
-
try {
|
|
687
|
-
inpObserver = new PerformanceObserver(entryHandler);
|
|
688
|
-
inpObserver.observe({ type: "event", buffered: true });
|
|
689
|
-
} catch (e) {
|
|
690
|
-
console.warn("[CWJ Monitor] INP observation not supported:", e);
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
const monitorLongTask = () => {
|
|
694
|
-
const entryHandler = (list) => {
|
|
695
|
-
for (const entry of list.getEntries()) {
|
|
696
|
-
if (options.filter && !options.filter(EMIT_TYPE.PERFORMANCE_LONGTASK, entry)) {
|
|
697
|
-
continue;
|
|
698
|
-
}
|
|
699
|
-
const threshold = options.longTaskThreshold ?? DEFAULT_LONG_TASK_THRESHOLD;
|
|
662
|
+
const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
|
|
700
663
|
if (entry.duration > threshold) {
|
|
701
|
-
context?.emit(EMIT_TYPE.
|
|
702
|
-
startTime: entry.startTime,
|
|
664
|
+
context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
|
|
703
665
|
duration: entry.duration,
|
|
704
|
-
|
|
705
|
-
|
|
666
|
+
startTime: entry.startTime,
|
|
667
|
+
renderStart: entry.renderStart,
|
|
668
|
+
styleAndLayoutStart: entry.styleAndLayoutStart,
|
|
669
|
+
hadRecentInput: entry.hadRecentInput,
|
|
670
|
+
scripts: entry.scripts.map((s) => ({
|
|
671
|
+
duration: s.duration,
|
|
672
|
+
invoker: s.invoker,
|
|
673
|
+
invokerType: s.invokerType,
|
|
674
|
+
sourceURL: s.sourceURL,
|
|
675
|
+
functionName: s.functionName,
|
|
676
|
+
startTime: s.startTime
|
|
677
|
+
}))
|
|
706
678
|
});
|
|
707
679
|
}
|
|
708
680
|
}
|
|
709
681
|
};
|
|
710
682
|
try {
|
|
711
|
-
|
|
712
|
-
|
|
683
|
+
loafObserver = new PerformanceObserver(entryHandler);
|
|
684
|
+
loafObserver.observe({ type: "long-animation-frame", buffered: true });
|
|
713
685
|
} catch (e) {
|
|
714
|
-
console.warn("[CWJ Monitor]
|
|
686
|
+
console.warn("[CWJ Monitor] LoAF observation not supported:", e);
|
|
715
687
|
}
|
|
716
688
|
};
|
|
717
689
|
const monitorResource = () => {
|
|
@@ -751,18 +723,14 @@ const PerformancePlugin = (options = {}) => {
|
|
|
751
723
|
context = ctx;
|
|
752
724
|
monitorPaintMetrics();
|
|
753
725
|
monitorLCP();
|
|
754
|
-
monitorINP();
|
|
755
|
-
monitorLongTask();
|
|
756
726
|
monitorResource();
|
|
727
|
+
monitorLoAF();
|
|
757
728
|
},
|
|
758
729
|
uninstall: () => {
|
|
759
730
|
paintObserver?.disconnect();
|
|
760
731
|
lcpObserver?.disconnect();
|
|
761
|
-
inpObserver?.disconnect();
|
|
762
|
-
longTaskObserver?.disconnect();
|
|
763
732
|
resourceObserver?.disconnect();
|
|
764
|
-
|
|
765
|
-
interactionMap.clear();
|
|
733
|
+
loafObserver?.disconnect();
|
|
766
734
|
}
|
|
767
735
|
};
|
|
768
736
|
};
|