(options: IPerfumeOptions = {})
| 19 | import { setStepsMap } from './steps/setStepsMap'; |
| 20 | |
| 21 | export 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 | }; |
no test coverage detected