UNPKG

@mrporter/frontend-monitoring

Version:

Utils and Events for MRP front end monitoring

71 lines (63 loc) 2.9 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.pagePerformance = pagePerformance; exports.domPerformance = domPerformance; function pagePerformance() { if (typeof window.performance !== 'undefined') { var _window$performance$t = window.performance.timing, redirectStart = _window$performance$t.redirectStart, redirectEnd = _window$performance$t.redirectEnd, fetchStart = _window$performance$t.fetchStart, domainLookupStart = _window$performance$t.domainLookupStart, domainLookupEnd = _window$performance$t.domainLookupEnd, connectStart = _window$performance$t.connectStart, connectEnd = _window$performance$t.connectEnd, requestStart = _window$performance$t.requestStart, responseStart = _window$performance$t.responseStart, responseEnd = _window$performance$t.responseEnd, navigationStart = _window$performance$t.navigationStart; return { collection: 'page_performance', event_data: { redirect: redirectEnd - redirectStart, app_cache: domainLookupStart - fetchStart, dns: domainLookupEnd - domainLookupStart, tcp: connectEnd - connectStart, request: responseStart - requestStart, response: responseEnd - responseStart, ttfb: responseStart - navigationStart } }; } } function domPerformance() { if (typeof window.performance !== 'undefined') { var _window$performance$t2 = window.performance.timing, navigationStart = _window$performance$t2.navigationStart, msFirstPaint = _window$performance$t2.msFirstPaint, domLoading = _window$performance$t2.domLoading, domInteractive = _window$performance$t2.domInteractive, domContentLoadedEventEnd = _window$performance$t2.domContentLoadedEventEnd, domComplete = _window$performance$t2.domComplete; var firstPaint = void 0; if (window.chrome && window.chrome.loadTimes) { var _window$chrome$loadTi = window.chrome.loadTimes(), firstPaintTime = _window$chrome$loadTi.firstPaintTime, startLoadTime = _window$chrome$loadTi.startLoadTime; firstPaint = Math.round((firstPaintTime - startLoadTime) * 1000); } else if (msFirstPaint) { firstPaint = msFirstPaint - navigationStart; } return { collection: 'page_performance', event_data: { complete: domComplete - domLoading, interactive: domInteractive - domLoading, content_loaded: domContentLoadedEventEnd - domLoading, first_paint: firstPaint } }; } }