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.js CHANGED
@@ -103,6 +103,13 @@ 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;
@@ -661,21 +668,40 @@ const PerformancePlugin = (options = {}) => {
661
668
  }
662
669
  const threshold = options.loafThreshold ?? DEFAULT_LOAF_THRESHOLD;
663
670
  if (entry.duration > threshold) {
664
- context?.emit(EMIT_TYPE.PERFORMANCE_LOAF, {
665
- duration: entry.duration,
666
- startTime: entry.startTime,
667
- renderStart: entry.renderStart,
668
- styleAndLayoutStart: entry.styleAndLayoutStart,
669
- hadRecentInput: entry.hadRecentInput,
670
- scripts: entry.scripts.map((s) => ({
671
- duration: s.duration,
672
- invoker: s.invoker,
673
- invokerType: s.invokerType,
674
- sourceURL: s.sourceURL,
675
- functionName: s.functionName,
676
- startTime: s.startTime
677
- }))
678
- });
671
+ const scripts = Array.isArray(entry.scripts) ? entry.scripts : [];
672
+ let isUserTriggered = false;
673
+ let allIgnored = true;
674
+ for (let i = 0; i < scripts.length; i++) {
675
+ const s = scripts[i];
676
+ if (!s)
677
+ continue;
678
+ if (!isUserTriggered && s.invokerType === "user-callback")
679
+ isUserTriggered = true;
680
+ if (allIgnored && !isIgnoredScriptSource(s.sourceURL)) {
681
+ allIgnored = false;
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
+ });
704
+ }
679
705
  }
680
706
  }
681
707
  };