UNPKG

@mtdt.temp/browser-rum-core

Version:
42 lines 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNavigationEntry = getNavigationEntry; exports.computeTimingsFromDeprecatedPerformanceTiming = computeTimingsFromDeprecatedPerformanceTiming; const browser_core_1 = require("@mtdt.temp/browser-core"); const performanceObservable_1 = require("./performanceObservable"); function getNavigationEntry() { if ((0, performanceObservable_1.supportPerformanceTimingEvent)(performanceObservable_1.RumPerformanceEntryType.NAVIGATION)) { const navigationEntry = performance.getEntriesByType(performanceObservable_1.RumPerformanceEntryType.NAVIGATION)[0]; if (navigationEntry) { return navigationEntry; } } const timings = computeTimingsFromDeprecatedPerformanceTiming(); const entry = { entryType: performanceObservable_1.RumPerformanceEntryType.NAVIGATION, initiatorType: 'navigation', name: window.location.href, startTime: 0, duration: timings.loadEventEnd, decodedBodySize: 0, encodedBodySize: 0, transferSize: 0, workerStart: 0, toJSON: () => ({ ...entry, toJSON: undefined }), ...timings, }; return entry; } function computeTimingsFromDeprecatedPerformanceTiming() { const result = {}; const timing = performance.timing; for (const key in timing) { if ((0, browser_core_1.isNumber)(timing[key])) { const numberKey = key; const timingElement = timing[numberKey]; result[numberKey] = timingElement === 0 ? 0 : (0, browser_core_1.getRelativeTime)(timingElement); } } return result; } //# sourceMappingURL=performanceUtils.js.map