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