cwj_monitoring 0.0.25 → 0.0.26

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.cjs CHANGED
@@ -105,6 +105,13 @@ function throttle(fn, delay) {
105
105
  }
106
106
  };
107
107
  }
108
+ const isIgnoredScriptSource = (sourceURL) => {
109
+ if (!sourceURL || typeof sourceURL !== "string")
110
+ return false;
111
+ if (/node_modules/.test(sourceURL))
112
+ return true;
113
+ return false;
114
+ };
108
115
 
109
116
  const MAX_CACHE_LEN = 5;
110
117
  const MAX_WAITING_TIME = 3e4;
@@ -663,21 +670,40 @@ const PerformancePlugin = (options = {}) => {
663
670
  }
664
671
  const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
665
672
  if (entry.duration > threshold) {
666
- context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
667
- duration: entry.duration,
668
- startTime: entry.startTime,
669
- renderStart: entry.renderStart,
670
- styleAndLayoutStart: entry.styleAndLayoutStart,
671
- hadRecentInput: entry.hadRecentInput,
672
- scripts: entry.scripts.map((s) => ({
673
- duration: s.duration,
674
- invoker: s.invoker,
675
- invokerType: s.invokerType,
676
- sourceURL: s.sourceURL,
677
- functionName: s.functionName,
678
- startTime: s.startTime
679
- }))
680
- });
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
+ 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
+ });
706
+ }
681
707
  }
682
708
  }
683
709
  };