cwj_monitoring 0.0.25 → 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 +64 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -4
- 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 +64 -4
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -103,12 +103,20 @@ function throttle(fn, delay) {
|
|
|
103
103
|
}
|
|
104
104
|
};
|
|
105
105
|
}
|
|
106
|
+
const isIgnoredScriptSource = (sourceURL) => {
|
|
107
|
+
if (!sourceURL || typeof sourceURL !== "string")
|
|
108
|
+
return false;
|
|
109
|
+
if (/node_modules/.test(sourceURL))
|
|
110
|
+
return true;
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
106
113
|
|
|
107
114
|
const MAX_CACHE_LEN = 5;
|
|
108
115
|
const MAX_WAITING_TIME = 3e4;
|
|
109
116
|
const UUID = "track_uuid";
|
|
110
117
|
const DEFAULT_RESOURCE_THRESHOLD = 1e3;
|
|
111
|
-
const DEFAULT_LOAF_THRESHOLD =
|
|
118
|
+
const DEFAULT_LOAF_THRESHOLD = 100;
|
|
119
|
+
const DEFAULT_LOAF_SINGLETIME = 50;
|
|
112
120
|
|
|
113
121
|
var __defProp$3 = Object.defineProperty;
|
|
114
122
|
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -660,8 +668,25 @@ const PerformancePlugin = (options = {}) => {
|
|
|
660
668
|
continue;
|
|
661
669
|
}
|
|
662
670
|
const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
|
|
663
|
-
if (entry.duration
|
|
664
|
-
|
|
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;
|
|
684
|
+
}
|
|
685
|
+
if (isUserTriggered && !allIgnored)
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
if (isUserTriggered && !allIgnored) {
|
|
689
|
+
const baseInfo = {
|
|
665
690
|
duration: entry.duration,
|
|
666
691
|
startTime: entry.startTime,
|
|
667
692
|
renderStart: entry.renderStart,
|
|
@@ -673,9 +698,44 @@ const PerformancePlugin = (options = {}) => {
|
|
|
673
698
|
invokerType: s.invokerType,
|
|
674
699
|
sourceURL: s.sourceURL,
|
|
675
700
|
functionName: s.functionName,
|
|
701
|
+
sourceFunctionName: s.sourceFunctionName,
|
|
702
|
+
sourceCharPosition: s.sourceCharPosition,
|
|
676
703
|
startTime: s.startTime
|
|
677
704
|
}))
|
|
678
|
-
}
|
|
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
|
+
})();
|
|
679
739
|
}
|
|
680
740
|
}
|
|
681
741
|
};
|