cwj_monitoring 0.0.26 → 0.0.27
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 +1 -1
- package/dist/index.cjs +69 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +69 -35
- 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 +69 -35
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -115,7 +115,8 @@ const MAX_CACHE_LEN = 5;
|
|
|
115
115
|
const MAX_WAITING_TIME = 3e4;
|
|
116
116
|
const UUID = "track_uuid";
|
|
117
117
|
const DEFAULT_RESOURCE_THRESHOLD = 1e3;
|
|
118
|
-
const DEFAULT_LOAF_THRESHOLD =
|
|
118
|
+
const DEFAULT_LOAF_THRESHOLD = 100;
|
|
119
|
+
const DEFAULT_LOAF_SINGLETIME = 50;
|
|
119
120
|
|
|
120
121
|
var __defProp$3 = Object.defineProperty;
|
|
121
122
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -667,41 +668,74 @@ const PerformancePlugin = (options = {}) => {
|
|
|
667
668
|
continue;
|
|
668
669
|
}
|
|
669
670
|
const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
|
|
670
|
-
if (entry.duration
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
if (isUserTriggered && !allIgnored)
|
|
684
|
-
break;
|
|
685
|
-
}
|
|
686
|
-
if (isUserTriggered && !allIgnored) {
|
|
687
|
-
context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
|
|
688
|
-
duration: entry.duration,
|
|
689
|
-
startTime: entry.startTime,
|
|
690
|
-
renderStart: entry.renderStart,
|
|
691
|
-
styleAndLayoutStart: entry.styleAndLayoutStart,
|
|
692
|
-
hadRecentInput: entry.hadRecentInput,
|
|
693
|
-
scripts: entry.scripts.map((s) => ({
|
|
694
|
-
duration: s.duration,
|
|
695
|
-
invoker: s.invoker,
|
|
696
|
-
invokerType: s.invokerType,
|
|
697
|
-
sourceURL: s.sourceURL,
|
|
698
|
-
functionName: s.functionName,
|
|
699
|
-
sourceFunctionName: s.sourceFunctionName,
|
|
700
|
-
sourceCharPosition: s.sourceCharPosition,
|
|
701
|
-
startTime: s.startTime
|
|
702
|
-
}))
|
|
703
|
-
});
|
|
671
|
+
if (typeof entry.duration !== "number" || entry.duration <= threshold)
|
|
672
|
+
continue;
|
|
673
|
+
const scripts = Array.isArray(entry.scripts) ? entry.scripts : [];
|
|
674
|
+
let isUserTriggered = false;
|
|
675
|
+
let allIgnored = true;
|
|
676
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
677
|
+
const s = scripts[i];
|
|
678
|
+
if (!s)
|
|
679
|
+
continue;
|
|
680
|
+
if (!isUserTriggered && s.invokerType === "user-callback")
|
|
681
|
+
isUserTriggered = true;
|
|
682
|
+
if (allIgnored && !isIgnoredScriptSource(s.sourceURL)) {
|
|
683
|
+
allIgnored = false;
|
|
704
684
|
}
|
|
685
|
+
if (isUserTriggered && !allIgnored)
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
if (isUserTriggered && !allIgnored) {
|
|
689
|
+
const baseInfo = {
|
|
690
|
+
duration: entry.duration,
|
|
691
|
+
startTime: entry.startTime,
|
|
692
|
+
renderStart: entry.renderStart,
|
|
693
|
+
styleAndLayoutStart: entry.styleAndLayoutStart,
|
|
694
|
+
hadRecentInput: entry.hadRecentInput,
|
|
695
|
+
scripts: entry.scripts.map((s) => ({
|
|
696
|
+
duration: s.duration,
|
|
697
|
+
invoker: s.invoker,
|
|
698
|
+
invokerType: s.invokerType,
|
|
699
|
+
sourceURL: s.sourceURL,
|
|
700
|
+
functionName: s.functionName,
|
|
701
|
+
sourceFunctionName: s.sourceFunctionName,
|
|
702
|
+
sourceCharPosition: s.sourceCharPosition,
|
|
703
|
+
startTime: s.startTime
|
|
704
|
+
}))
|
|
705
|
+
};
|
|
706
|
+
(async () => {
|
|
707
|
+
const longScripts = scripts.filter(
|
|
708
|
+
(s) => s && typeof s.duration === "number" && s.duration > DEFAULT_LOAF_SINGLETIME && s.sourceURL
|
|
709
|
+
);
|
|
710
|
+
const contexts = [];
|
|
711
|
+
for (const s of longScripts) {
|
|
712
|
+
try {
|
|
713
|
+
const url = String(s.sourceURL);
|
|
714
|
+
const resp = await fetch(url, { cache: "no-store" });
|
|
715
|
+
if (!resp.ok) {
|
|
716
|
+
contexts.push({ sourceURL: url, error: `http ${resp.status}` });
|
|
717
|
+
continue;
|
|
718
|
+
}
|
|
719
|
+
const text = await resp.text();
|
|
720
|
+
const pos = typeof s.sourceCharPosition === "number" ? s.sourceCharPosition : void 0;
|
|
721
|
+
if (pos !== void 0 && Number.isFinite(pos)) {
|
|
722
|
+
const start = Math.max(0, pos - 50);
|
|
723
|
+
const end = Math.min(text.length, pos + 50);
|
|
724
|
+
const snippet = text.substring(start, end);
|
|
725
|
+
contexts.push({ sourceURL: url, position: pos, snippet });
|
|
726
|
+
} else {
|
|
727
|
+
contexts.push({ sourceURL: url, error: "no-position" });
|
|
728
|
+
}
|
|
729
|
+
} catch (e) {
|
|
730
|
+
contexts.push({
|
|
731
|
+
sourceURL: s && s.sourceURL ? String(s.sourceURL) : "",
|
|
732
|
+
error: e?.message || String(e)
|
|
733
|
+
});
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
const info = { ...baseInfo, contexts };
|
|
737
|
+
context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, info);
|
|
738
|
+
})();
|
|
705
739
|
}
|
|
706
740
|
}
|
|
707
741
|
};
|