MCPcopy
hub / github.com/Zizzamia/perfume.js / initPerfume

Function initPerfume

src/initPerfume.ts:21–67  ·  view source on GitHub ↗
(options: IPerfumeOptions = {})

Source from the content-addressed store, hash-verified

19import { setStepsMap } from './steps/setStepsMap';
20
21export const initPerfume = (options: IPerfumeOptions = {}) => {
22 // Extend default config with external options
23 config.analyticsTracker = options.analyticsTracker;
24 config.isResourceTiming = !!options.resourceTiming;
25 config.isElementTiming = !!options.elementTiming;
26 config.maxTime = options.maxMeasureTime || config.maxTime;
27 config.reportOptions = options.reportOptions || config.reportOptions;
28 config.steps = options.steps;
29 config.onMarkStep = options.onMarkStep;
30
31 // Exit from Perfume when basic Web Performance APIs aren't supported
32 if (!isPerformanceSupported()) {
33 return;
34 }
35 // Checks if use Performance or the EmulatedPerformance instance
36 if ('PerformanceObserver' in W) {
37 initPerformanceObserver();
38 }
39
40 // Init visibilitychange listener
41 if (typeof document.hidden !== 'undefined') {
42 // Opera 12.10 and Firefox 18 and later support
43 document.addEventListener('visibilitychange', didVisibilityChange);
44 }
45
46 const navigationTiming = getNavigationTiming();
47 // Log Navigation Timing
48 logData('navigationTiming', navigationTiming);
49 if (navigationTiming.redirectTime) {
50 logMetric({
51 attribution: {},
52 name: `RT`,
53 rating: getVitalsScore('RT', navigationTiming.redirectTime),
54 value: navigationTiming.redirectTime,
55 });
56 }
57 // Log Network Information
58 logData('networkInformation', getNetworkInformation());
59 // Let's estimate our storage capacity
60 if (WN && WN.storage && typeof WN.storage.estimate === 'function') {
61 WN.storage.estimate().then(reportStorageEstimate);
62 }
63 // initializing Steps if present
64 if (config.steps) {
65 setStepsMap();
66 }
67};

Callers 9

navSteps.spec.tsFile · 0.90
markNTBT.spec.tsFile · 0.85
markStep.spec.tsFile · 0.85

Calls 8

isPerformanceSupportedFunction · 0.90
initPerformanceObserverFunction · 0.90
getNavigationTimingFunction · 0.90
logDataFunction · 0.90
logMetricFunction · 0.90
getVitalsScoreFunction · 0.90
getNetworkInformationFunction · 0.90
setStepsMapFunction · 0.90

Tested by

no test coverage detected