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