@sentry/browser-utils 11.0.0-alpha.0 → 11.0.0-alpha.1
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/build/cjs/index.js +29 -28
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/instrumentation/dom.js.map +1 -0
- package/build/cjs/instrumentation/history.js.map +1 -0
- package/build/cjs/instrumentation/location.js.map +1 -0
- package/build/cjs/{metrics/instrument.js → instrumentation/performanceObserver.js} +44 -32
- package/build/cjs/instrumentation/performanceObserver.js.map +1 -0
- package/build/cjs/instrumentation/xhr.js.map +1 -0
- package/build/cjs/{metrics → performance}/elementTiming.js +2 -2
- package/build/cjs/performance/elementTiming.js.map +1 -0
- package/build/cjs/{metrics/browserMetrics.js → performance/entries.js} +22 -175
- package/build/cjs/performance/entries.js.map +1 -0
- package/build/cjs/performance/resourceTiming.js.map +1 -0
- package/build/cjs/{metrics → performance}/userTiming.js +4 -3
- package/build/cjs/performance/userTiming.js.map +1 -0
- package/build/cjs/{metrics → performance}/utils.js +1 -27
- package/build/cjs/performance/utils.js.map +1 -0
- package/build/cjs/{metrics → web-vitals}/inp.js +4 -4
- package/build/cjs/web-vitals/inp.js.map +1 -0
- package/build/cjs/web-vitals/lcp.js.map +1 -0
- package/build/cjs/web-vitals/reportEvents.js +31 -0
- package/build/cjs/web-vitals/reportEvents.js.map +1 -0
- package/build/cjs/{metrics/webVitalSpans.js → web-vitals/spans.js} +11 -10
- package/build/cjs/web-vitals/spans.js.map +1 -0
- package/build/cjs/web-vitals/tracking.js +164 -0
- package/build/cjs/web-vitals/tracking.js.map +1 -0
- package/build/cjs/web-vitals/utils.js +99 -0
- package/build/cjs/web-vitals/utils.js.map +1 -0
- package/build/esm/index.js +14 -13
- package/build/esm/index.js.map +1 -1
- package/build/esm/instrumentation/dom.js.map +1 -0
- package/build/esm/instrumentation/history.js.map +1 -0
- package/build/esm/instrumentation/location.js.map +1 -0
- package/build/esm/{metrics/instrument.js → instrumentation/performanceObserver.js} +42 -30
- package/build/esm/instrumentation/performanceObserver.js.map +1 -0
- package/build/esm/instrumentation/xhr.js.map +1 -0
- package/build/esm/package.json +1 -1
- package/build/esm/{metrics → performance}/elementTiming.js +1 -1
- package/build/esm/performance/elementTiming.js.map +1 -0
- package/build/esm/{metrics/browserMetrics.js → performance/entries.js} +15 -166
- package/build/esm/performance/entries.js.map +1 -0
- package/build/esm/performance/resourceTiming.js.map +1 -0
- package/build/esm/{metrics → performance}/userTiming.js +4 -3
- package/build/esm/performance/userTiming.js.map +1 -0
- package/build/esm/{metrics → performance}/utils.js +3 -28
- package/build/esm/performance/utils.js.map +1 -0
- package/build/esm/{metrics → web-vitals}/inp.js +1 -1
- package/build/esm/web-vitals/inp.js.map +1 -0
- package/build/esm/web-vitals/lcp.js.map +1 -0
- package/build/esm/web-vitals/reportEvents.js +29 -0
- package/build/esm/web-vitals/reportEvents.js.map +1 -0
- package/build/esm/{metrics/webVitalSpans.js → web-vitals/spans.js} +7 -6
- package/build/esm/web-vitals/spans.js.map +1 -0
- package/build/esm/web-vitals/tracking.js +161 -0
- package/build/esm/web-vitals/tracking.js.map +1 -0
- package/build/esm/web-vitals/utils.js +91 -0
- package/build/esm/web-vitals/utils.js.map +1 -0
- package/build/types/index.d.ts +13 -12
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrumentation/dom.d.ts.map +1 -0
- package/build/types/instrumentation/history.d.ts.map +1 -0
- package/build/types/instrumentation/location.d.ts.map +1 -0
- package/build/types/{metrics/instrument.d.ts → instrumentation/performanceObserver.d.ts} +3 -3
- package/build/types/instrumentation/performanceObserver.d.ts.map +1 -0
- package/build/types/instrumentation/xhr.d.ts.map +1 -0
- package/build/types/performance/elementTiming.d.ts.map +1 -0
- package/build/types/{metrics/browserMetrics.d.ts → performance/entries.d.ts} +3 -46
- package/build/types/performance/entries.d.ts.map +1 -0
- package/build/types/performance/resourceTiming.d.ts.map +1 -0
- package/build/types/performance/userTiming.d.ts.map +1 -0
- package/build/types/{metrics → performance}/utils.d.ts +1 -17
- package/build/types/performance/utils.d.ts.map +1 -0
- package/build/types/web-vitals/inp.d.ts.map +1 -0
- package/build/types/web-vitals/lcp.d.ts.map +1 -0
- package/build/types/web-vitals/reportEvents.d.ts +18 -0
- package/build/types/web-vitals/reportEvents.d.ts.map +1 -0
- package/build/types/{metrics/webVitalSpans.d.ts → web-vitals/spans.d.ts} +3 -3
- package/build/types/web-vitals/spans.d.ts.map +1 -0
- package/build/types/web-vitals/tracking.d.ts +46 -0
- package/build/types/web-vitals/tracking.d.ts.map +1 -0
- package/build/types/{metrics/web-vitals/lib/globalListeners.d.ts → web-vitals/utils.d.ts} +16 -1
- package/build/types/web-vitals/utils.d.ts.map +1 -0
- package/package.json +4 -3
- package/build/cjs/instrument/dom.js.map +0 -1
- package/build/cjs/instrument/history.js.map +0 -1
- package/build/cjs/instrument/location.js.map +0 -1
- package/build/cjs/instrument/xhr.js.map +0 -1
- package/build/cjs/metrics/browserMetrics.js.map +0 -1
- package/build/cjs/metrics/elementTiming.js.map +0 -1
- package/build/cjs/metrics/inp.js.map +0 -1
- package/build/cjs/metrics/instrument.js.map +0 -1
- package/build/cjs/metrics/lcp.js.map +0 -1
- package/build/cjs/metrics/resourceTiming.js.map +0 -1
- package/build/cjs/metrics/userTiming.js.map +0 -1
- package/build/cjs/metrics/utils.js.map +0 -1
- package/build/cjs/metrics/web-vitals/getCLS.js +0 -46
- package/build/cjs/metrics/web-vitals/getCLS.js.map +0 -1
- package/build/cjs/metrics/web-vitals/getINP.js +0 -60
- package/build/cjs/metrics/web-vitals/getINP.js.map +0 -1
- package/build/cjs/metrics/web-vitals/getLCP.js +0 -62
- package/build/cjs/metrics/web-vitals/getLCP.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/InteractionManager.js +0 -87
- package/build/cjs/metrics/web-vitals/lib/InteractionManager.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/LCPEntryManager.js +0 -11
- package/build/cjs/metrics/web-vitals/lib/LCPEntryManager.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/LayoutShiftManager.js +0 -27
- package/build/cjs/metrics/web-vitals/lib/LayoutShiftManager.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/bindReporter.js +0 -31
- package/build/cjs/metrics/web-vitals/lib/bindReporter.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/generateUniqueID.js +0 -8
- package/build/cjs/metrics/web-vitals/lib/generateUniqueID.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/getActivationStart.js +0 -11
- package/build/cjs/metrics/web-vitals/lib/getActivationStart.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/getNavigationEntry.js +0 -17
- package/build/cjs/metrics/web-vitals/lib/getNavigationEntry.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/getVisibilityWatcher.js +0 -44
- package/build/cjs/metrics/web-vitals/lib/getVisibilityWatcher.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/globalListeners.js +0 -18
- package/build/cjs/metrics/web-vitals/lib/globalListeners.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/initMetric.js +0 -34
- package/build/cjs/metrics/web-vitals/lib/initMetric.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/initUnique.js +0 -16
- package/build/cjs/metrics/web-vitals/lib/initUnique.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/observe.js +0 -20
- package/build/cjs/metrics/web-vitals/lib/observe.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/onHidden.js +0 -16
- package/build/cjs/metrics/web-vitals/lib/onHidden.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.js +0 -32
- package/build/cjs/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/runOnce.js +0 -14
- package/build/cjs/metrics/web-vitals/lib/runOnce.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/whenActivated.js +0 -14
- package/build/cjs/metrics/web-vitals/lib/whenActivated.js.map +0 -1
- package/build/cjs/metrics/web-vitals/lib/whenIdleOrHidden.js +0 -22
- package/build/cjs/metrics/web-vitals/lib/whenIdleOrHidden.js.map +0 -1
- package/build/cjs/metrics/web-vitals/onFCP.js +0 -37
- package/build/cjs/metrics/web-vitals/onFCP.js.map +0 -1
- package/build/cjs/metrics/web-vitals/onTTFB.js +0 -35
- package/build/cjs/metrics/web-vitals/onTTFB.js.map +0 -1
- package/build/cjs/metrics/webVitalSpans.js.map +0 -1
- package/build/esm/instrument/dom.js.map +0 -1
- package/build/esm/instrument/history.js.map +0 -1
- package/build/esm/instrument/location.js.map +0 -1
- package/build/esm/instrument/xhr.js.map +0 -1
- package/build/esm/metrics/browserMetrics.js.map +0 -1
- package/build/esm/metrics/elementTiming.js.map +0 -1
- package/build/esm/metrics/inp.js.map +0 -1
- package/build/esm/metrics/instrument.js.map +0 -1
- package/build/esm/metrics/lcp.js.map +0 -1
- package/build/esm/metrics/resourceTiming.js.map +0 -1
- package/build/esm/metrics/userTiming.js.map +0 -1
- package/build/esm/metrics/utils.js.map +0 -1
- package/build/esm/metrics/web-vitals/getCLS.js +0 -43
- package/build/esm/metrics/web-vitals/getCLS.js.map +0 -1
- package/build/esm/metrics/web-vitals/getINP.js +0 -57
- package/build/esm/metrics/web-vitals/getINP.js.map +0 -1
- package/build/esm/metrics/web-vitals/getLCP.js +0 -59
- package/build/esm/metrics/web-vitals/getLCP.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/InteractionManager.js +0 -85
- package/build/esm/metrics/web-vitals/lib/InteractionManager.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/LCPEntryManager.js +0 -9
- package/build/esm/metrics/web-vitals/lib/LCPEntryManager.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/LayoutShiftManager.js +0 -25
- package/build/esm/metrics/web-vitals/lib/LayoutShiftManager.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/bindReporter.js +0 -29
- package/build/esm/metrics/web-vitals/lib/bindReporter.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/generateUniqueID.js +0 -6
- package/build/esm/metrics/web-vitals/lib/generateUniqueID.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/getActivationStart.js +0 -9
- package/build/esm/metrics/web-vitals/lib/getActivationStart.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/getNavigationEntry.js +0 -15
- package/build/esm/metrics/web-vitals/lib/getNavigationEntry.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/getVisibilityWatcher.js +0 -42
- package/build/esm/metrics/web-vitals/lib/getVisibilityWatcher.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/globalListeners.js +0 -15
- package/build/esm/metrics/web-vitals/lib/globalListeners.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/initMetric.js +0 -32
- package/build/esm/metrics/web-vitals/lib/initMetric.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/initUnique.js +0 -14
- package/build/esm/metrics/web-vitals/lib/initUnique.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/observe.js +0 -18
- package/build/esm/metrics/web-vitals/lib/observe.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/onHidden.js +0 -14
- package/build/esm/metrics/web-vitals/lib/onHidden.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.js +0 -29
- package/build/esm/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/runOnce.js +0 -12
- package/build/esm/metrics/web-vitals/lib/runOnce.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/whenActivated.js +0 -12
- package/build/esm/metrics/web-vitals/lib/whenActivated.js.map +0 -1
- package/build/esm/metrics/web-vitals/lib/whenIdleOrHidden.js +0 -20
- package/build/esm/metrics/web-vitals/lib/whenIdleOrHidden.js.map +0 -1
- package/build/esm/metrics/web-vitals/onFCP.js +0 -34
- package/build/esm/metrics/web-vitals/onFCP.js.map +0 -1
- package/build/esm/metrics/web-vitals/onTTFB.js +0 -32
- package/build/esm/metrics/web-vitals/onTTFB.js.map +0 -1
- package/build/esm/metrics/webVitalSpans.js.map +0 -1
- package/build/types/instrument/dom.d.ts.map +0 -1
- package/build/types/instrument/history.d.ts.map +0 -1
- package/build/types/instrument/location.d.ts.map +0 -1
- package/build/types/instrument/xhr.d.ts.map +0 -1
- package/build/types/metrics/browserMetrics.d.ts.map +0 -1
- package/build/types/metrics/elementTiming.d.ts.map +0 -1
- package/build/types/metrics/inp.d.ts.map +0 -1
- package/build/types/metrics/instrument.d.ts.map +0 -1
- package/build/types/metrics/lcp.d.ts.map +0 -1
- package/build/types/metrics/resourceTiming.d.ts.map +0 -1
- package/build/types/metrics/userTiming.d.ts.map +0 -1
- package/build/types/metrics/utils.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/getCLS.d.ts +0 -26
- package/build/types/metrics/web-vitals/getCLS.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/getINP.d.ts +0 -34
- package/build/types/metrics/web-vitals/getINP.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/getLCP.d.ts +0 -16
- package/build/types/metrics/web-vitals/getLCP.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/InteractionManager.d.ts +0 -37
- package/build/types/metrics/web-vitals/lib/InteractionManager.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/LCPEntryManager.d.ts +0 -5
- package/build/types/metrics/web-vitals/lib/LCPEntryManager.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/LayoutShiftManager.d.ts +0 -7
- package/build/types/metrics/web-vitals/lib/LayoutShiftManager.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/bindReporter.d.ts +0 -7
- package/build/types/metrics/web-vitals/lib/bindReporter.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/generateUniqueID.d.ts +0 -7
- package/build/types/metrics/web-vitals/lib/generateUniqueID.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/getActivationStart.d.ts +0 -2
- package/build/types/metrics/web-vitals/lib/getActivationStart.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/getNavigationEntry.d.ts +0 -2
- package/build/types/metrics/web-vitals/lib/getNavigationEntry.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/getVisibilityWatcher.d.ts +0 -5
- package/build/types/metrics/web-vitals/lib/getVisibilityWatcher.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/globalListeners.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/initMetric.d.ts +0 -21
- package/build/types/metrics/web-vitals/lib/initMetric.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/initUnique.d.ts +0 -7
- package/build/types/metrics/web-vitals/lib/initUnique.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/observe.d.ts +0 -23
- package/build/types/metrics/web-vitals/lib/observe.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/onHidden.d.ts +0 -15
- package/build/types/metrics/web-vitals/lib/onHidden.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.d.ts +0 -15
- package/build/types/metrics/web-vitals/lib/polyfills/interactionCountPolyfill.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/runOnce.d.ts +0 -2
- package/build/types/metrics/web-vitals/lib/runOnce.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/whenActivated.d.ts +0 -2
- package/build/types/metrics/web-vitals/lib/whenActivated.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/lib/whenIdleOrHidden.d.ts +0 -6
- package/build/types/metrics/web-vitals/lib/whenIdleOrHidden.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/onFCP.d.ts +0 -11
- package/build/types/metrics/web-vitals/onFCP.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/onTTFB.d.ts +0 -20
- package/build/types/metrics/web-vitals/onTTFB.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/base.d.ts +0 -103
- package/build/types/metrics/web-vitals/types/base.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/cls.d.ts +0 -58
- package/build/types/metrics/web-vitals/types/cls.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/fcp.d.ts +0 -47
- package/build/types/metrics/web-vitals/types/fcp.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/inp.d.ts +0 -150
- package/build/types/metrics/web-vitals/types/inp.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/lcp.d.ts +0 -74
- package/build/types/metrics/web-vitals/types/lcp.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types/ttfb.d.ts +0 -60
- package/build/types/metrics/web-vitals/types/ttfb.d.ts.map +0 -1
- package/build/types/metrics/web-vitals/types.d.ts +0 -78
- package/build/types/metrics/web-vitals/types.d.ts.map +0 -1
- package/build/types/metrics/webVitalSpans.d.ts.map +0 -1
- /package/build/cjs/{instrument → instrumentation}/dom.js +0 -0
- /package/build/cjs/{instrument → instrumentation}/history.js +0 -0
- /package/build/cjs/{instrument → instrumentation}/location.js +0 -0
- /package/build/cjs/{instrument → instrumentation}/xhr.js +0 -0
- /package/build/cjs/{metrics → performance}/resourceTiming.js +0 -0
- /package/build/cjs/{metrics → web-vitals}/lcp.js +0 -0
- /package/build/esm/{instrument → instrumentation}/dom.js +0 -0
- /package/build/esm/{instrument → instrumentation}/history.js +0 -0
- /package/build/esm/{instrument → instrumentation}/location.js +0 -0
- /package/build/esm/{instrument → instrumentation}/xhr.js +0 -0
- /package/build/esm/{metrics → performance}/resourceTiming.js +0 -0
- /package/build/esm/{metrics → web-vitals}/lcp.js +0 -0
- /package/build/types/{instrument → instrumentation}/dom.d.ts +0 -0
- /package/build/types/{instrument → instrumentation}/history.d.ts +0 -0
- /package/build/types/{instrument → instrumentation}/location.d.ts +0 -0
- /package/build/types/{instrument → instrumentation}/xhr.d.ts +0 -0
- /package/build/types/{metrics → performance}/elementTiming.d.ts +0 -0
- /package/build/types/{metrics → performance}/resourceTiming.d.ts +0 -0
- /package/build/types/{metrics → performance}/userTiming.d.ts +0 -0
- /package/build/types/{metrics → web-vitals}/inp.d.ts +0 -0
- /package/build/types/{metrics → web-vitals}/lcp.d.ts +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"elementTiming.js","sources":["../../../src/metrics/elementTiming.ts"],"sourcesContent":["import type { IntegrationFn } from '@sentry/core';\nimport { browserPerformanceTimeOrigin, defineIntegration, metrics } from '@sentry/core';\nimport { addPerformanceInstrumentationHandler } from './instrument';\nimport { getBrowserPerformanceAPI } from './utils';\n\n// ElementTiming interface based on the W3C spec\ninterface PerformanceElementTiming extends PerformanceEntry {\n renderTime: number;\n loadTime: number;\n intersectionRect: DOMRectReadOnly;\n identifier: string;\n naturalWidth: number;\n naturalHeight: number;\n id: string;\n element: Element | null;\n url?: string;\n}\n\nconst INTEGRATION_NAME = 'ElementTiming';\n\nconst _elementTimingIntegration = (() => {\n return {\n name: INTEGRATION_NAME,\n setup() {\n const performance = getBrowserPerformanceAPI();\n if (!performance || !browserPerformanceTimeOrigin()) {\n return;\n }\n\n addPerformanceInstrumentationHandler('element', ({ entries }) => {\n for (const entry of entries) {\n const elementEntry = entry as PerformanceElementTiming;\n\n if (!elementEntry.identifier) {\n continue;\n }\n\n const identifier = elementEntry.identifier;\n const paintType = elementEntry.name as 'image-paint' | 'text-paint' | undefined;\n const renderTime = elementEntry.renderTime;\n const loadTime = elementEntry.loadTime;\n\n const metricAttributes: Record<string, string | number> = {\n 'sentry.origin': 'auto.ui.browser.element_timing',\n 'ui.element.identifier': identifier,\n };\n\n if (paintType) {\n metricAttributes['ui.element.paint_type'] = paintType;\n }\n\n if (elementEntry.id) {\n metricAttributes['ui.element.id'] = elementEntry.id;\n }\n\n if (elementEntry.element) {\n metricAttributes['ui.element.type'] = elementEntry.element.tagName.toLowerCase();\n }\n\n if (elementEntry.url) {\n metricAttributes['ui.element.url'] = elementEntry.url;\n }\n\n if (elementEntry.naturalWidth) {\n metricAttributes['ui.element.width'] = elementEntry.naturalWidth;\n }\n\n if (elementEntry.naturalHeight) {\n metricAttributes['ui.element.height'] = elementEntry.naturalHeight;\n }\n\n if (renderTime > 0) {\n metrics.distribution(`ui.element.render_time`, renderTime, {\n unit: 'millisecond',\n attributes: metricAttributes,\n });\n }\n\n if (loadTime > 0) {\n metrics.distribution(`ui.element.load_time`, loadTime, {\n unit: 'millisecond',\n attributes: metricAttributes,\n });\n }\n }\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Captures [Element Timing API](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceElementTiming)\n * data as Sentry metrics.\n *\n * To mark an element for tracking, add the `elementtiming` HTML attribute:\n * ```html\n * <img src=\"hero.jpg\" elementtiming=\"hero-image\" />\n * <p elementtiming=\"hero-text\">Welcome!</p>\n * ```\n *\n * This emits `ui.element.render_time` and `ui.element.load_time` (for images)\n * as distribution metrics, tagged with the element's identifier and paint type.\n */\nexport const elementTimingIntegration = defineIntegration(_elementTimingIntegration);\n\n/**\n * @deprecated Use `elementTimingIntegration` instead. This function is a no-op and will be removed in a future version.\n */\nexport function startTrackingElementTiming(): () => void {\n return () => undefined;\n}\n"],"names":[],"mappings":";;;;AAkBA,MAAM,gBAAA,GAAmB,eAAA;AAEzB,MAAM,6BAA6B,MAAM;AACvC,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,KAAA,GAAQ;AACN,MAAA,MAAM,cAAc,wBAAA,EAAyB;AAC7C,MAAA,IAAI,CAAC,WAAA,IAAe,CAAC,4BAAA,EAA6B,EAAG;AACnD,QAAA;AAAA,MACF;AAEA,MAAA,oCAAA,CAAqC,SAAA,EAAW,CAAC,EAAE,OAAA,EAAQ,KAAM;AAC/D,QAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,UAAA,MAAM,YAAA,GAAe,KAAA;AAErB,UAAA,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A,CAAa,wBAAwB,QAAA,EAAU;AAAA,cACrD,IAAA,EAAM,aAAA;AAAA,cACN,UAAA,EAAY;AAAA,aACb,CAAA;AAAA,UACH;AAAA,QACF;AAAA,MACF,CAAC,CAAA;AAAA,IACH;AAAA,GACF;AACF,CAAA,CAAA;AAeO,MAAM,wBAAA,GAA2B,kBAAkB,yBAAyB;AAK5E,SAAS,0BAAA,GAAyC;AACvD,EAAA,OAAO,MAAM,MAAA;AACf;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inp.js","sources":["../../../src/metrics/inp.ts"],"sourcesContent":["import type { Span } from '@sentry/core';\nimport { getActiveSpan, getRootSpan, isBrowser } from '@sentry/core';\nimport { htmlTreeAsString } from '../htmlTreeAsString';\nimport { WINDOW } from '../types';\nimport { addPerformanceInstrumentationHandler, isPerformanceEventTiming } from './instrument';\n\ninterface InteractionContext {\n span: Span | undefined;\n elementName: string;\n}\n\nconst LAST_INTERACTIONS: number[] = [];\nconst INTERACTIONS_SPAN_MAP = new Map<number, InteractionContext>();\n\n// Map to store element names by timestamp, since we get the DOM event before the PerformanceObserver entry\nconst ELEMENT_NAME_TIMESTAMP_MAP = new Map<number, string>();\n\n/**\n * 60 seconds is the maximum for a plausible INP value\n * (source: Me)\n */\nexport const MAX_PLAUSIBLE_INP_DURATION = 60;\n\nexport const INP_ENTRY_MAP: Record<string, 'click' | 'hover' | 'drag' | 'press'> = {\n click: 'click',\n pointerdown: 'click',\n pointerup: 'click',\n mousedown: 'click',\n mouseup: 'click',\n touchstart: 'click',\n touchend: 'click',\n mouseover: 'hover',\n mouseout: 'hover',\n mouseenter: 'hover',\n mouseleave: 'hover',\n pointerover: 'hover',\n pointerout: 'hover',\n pointerenter: 'hover',\n pointerleave: 'hover',\n dragstart: 'drag',\n dragend: 'drag',\n drag: 'drag',\n dragenter: 'drag',\n dragleave: 'drag',\n dragover: 'drag',\n drop: 'drag',\n keydown: 'press',\n keyup: 'press',\n keypress: 'press',\n input: 'press',\n};\n\n/**\n * Look up a cached interaction context (element name + root span) by interactionId.\n * Returns undefined if no context was cached for this interaction.\n */\nexport function getCachedInteractionContext(interactionId: number | undefined): InteractionContext | undefined {\n return interactionId != null ? INTERACTIONS_SPAN_MAP.get(interactionId) : undefined;\n}\n\n/**\n * Register a listener to cache route information for INP interactions.\n */\nexport function registerInpInteractionListener(): void {\n // Listen for all interaction events that could contribute to INP\n const interactionEvents = Object.keys(INP_ENTRY_MAP);\n if (isBrowser()) {\n interactionEvents.forEach(eventType => {\n WINDOW.addEventListener(eventType, captureElementFromEvent, { capture: true, passive: true });\n });\n }\n\n /**\n * Captures the element name from a DOM event and stores it in the ELEMENT_NAME_TIMESTAMP_MAP.\n */\n function captureElementFromEvent(event: Event): void {\n const target = event.target as HTMLElement | null;\n if (!target) {\n return;\n }\n\n const elementName = htmlTreeAsString(target);\n const timestamp = Math.round(event.timeStamp);\n\n // Store the element name by timestamp so we can match it with the PerformanceEntry\n ELEMENT_NAME_TIMESTAMP_MAP.set(timestamp, elementName);\n\n // Clean up old\n if (ELEMENT_NAME_TIMESTAMP_MAP.size > 50) {\n const firstKey = ELEMENT_NAME_TIMESTAMP_MAP.keys().next().value;\n if (firstKey !== undefined) {\n ELEMENT_NAME_TIMESTAMP_MAP.delete(firstKey);\n }\n }\n }\n\n /**\n * Tries to get the element name from the timestamp map.\n */\n function resolveElementNameFromEntry(entry: PerformanceEntry): string {\n const timestamp = Math.round(entry.startTime);\n let elementName = ELEMENT_NAME_TIMESTAMP_MAP.get(timestamp);\n\n // try nearby timestamps (±5ms)\n if (!elementName) {\n for (let offset = -5; offset <= 5; offset++) {\n const nearbyName = ELEMENT_NAME_TIMESTAMP_MAP.get(timestamp + offset);\n if (nearbyName) {\n elementName = nearbyName;\n break;\n }\n }\n }\n\n return elementName || '<unknown>';\n }\n\n const handleEntries = ({ entries }: { entries: PerformanceEntry[] }): void => {\n const activeSpan = getActiveSpan();\n const activeRootSpan = activeSpan && getRootSpan(activeSpan);\n\n entries.forEach(entry => {\n if (!isPerformanceEventTiming(entry)) {\n return;\n }\n\n const interactionId = entry.interactionId;\n if (interactionId == null) {\n return;\n }\n\n // If the interaction was already recorded before, nothing more to do\n if (INTERACTIONS_SPAN_MAP.has(interactionId)) {\n return;\n }\n\n const elementName = entry.target ? htmlTreeAsString(entry.target) : resolveElementNameFromEntry(entry);\n\n // We keep max. 10 interactions in the list, then remove the oldest one & clean up\n if (LAST_INTERACTIONS.length > 10) {\n const last = LAST_INTERACTIONS.shift() as number;\n INTERACTIONS_SPAN_MAP.delete(last);\n }\n\n // We add the interaction to the list of recorded interactions\n // and store both the span and element name for this interaction\n LAST_INTERACTIONS.push(interactionId);\n INTERACTIONS_SPAN_MAP.set(interactionId, {\n span: activeRootSpan,\n elementName,\n });\n });\n };\n\n addPerformanceInstrumentationHandler('event', handleEntries);\n addPerformanceInstrumentationHandler('first-input', handleEntries);\n}\n"],"names":[],"mappings":";;;;;AAWA,MAAM,oBAA8B,EAAC;AACrC,MAAM,qBAAA,uBAA4B,GAAA,EAAgC;AAGlE,MAAM,0BAAA,uBAAiC,GAAA,EAAoB;AAMpD,MAAM,0BAAA,GAA6B;AAEnC,MAAM,aAAA,GAAsE;AAAA,EACjF,KAAA,EAAO,OAAA;AAAA,EACP,WAAA,EAAa,OAAA;AAAA,EACb,SAAA,EAAW,OAAA;AAAA,EACX,SAAA,EAAW,OAAA;AAAA,EACX,OAAA,EAAS,OAAA;AAAA,EACT,UAAA,EAAY,OAAA;AAAA,EACZ,QAAA,EAAU,OAAA;AAAA,EACV,SAAA,EAAW,OAAA;AAAA,EACX,QAAA,EAAU,OAAA;AAAA,EACV,UAAA,EAAY,OAAA;AAAA,EACZ,UAAA,EAAY,OAAA;AAAA,EACZ,WAAA,EAAa,OAAA;AAAA,EACb,UAAA,EAAY,OAAA;AAAA,EACZ,YAAA,EAAc,OAAA;AAAA,EACd,YAAA,EAAc,OAAA;AAAA,EACd,SAAA,EAAW,MAAA;AAAA,EAC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GrG,MAAA,IAAI,iBAAA,CAAkB,SAAS,EAAA,EAAI;AACjC,QAAA,MAAM,IAAA,GAAO,kBAAkB,KAAA,EAAM;AACrC,QAAA,qBAAA,CAAsB,OAAO,IAAI,CAAA;AAAA,MACnC;AAIA,MAAA,iBAAA,CAAkB,KAAK,aAAa,CAAA;AACpC,MAAA,qBAAA,CAAsB,IAAI,aAAA,EAAe;AAAA,QACvC,IAAA,EAAM,cAAA;AAAA,QACN;AAAA,OACD,CAAA;AAAA,IACH,CAAC,CAAA;AAAA,EACH,CAAA;AAEA,EAAA,oCAAA,CAAqC,SAAS,aAAa,CAAA;AAC3D,EAAA,oCAAA,CAAqC,eAAe,aAAa,CAAA;AACnE;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instrument.js","sources":["../../../src/metrics/instrument.ts"],"sourcesContent":["import { debug, getFunctionName } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport { onCLS } from './web-vitals/getCLS';\nimport { onINP } from './web-vitals/getINP';\nimport { onLCP } from './web-vitals/getLCP';\nimport { observe } from './web-vitals/lib/observe';\nimport { onTTFB } from './web-vitals/onTTFB';\n\ntype InstrumentHandlerTypePerformanceObserver =\n | 'longtask'\n | 'event'\n | 'navigation'\n | 'paint'\n | 'resource'\n | 'element'\n // fist-input is still needed for INP\n | 'first-input';\n\ntype InstrumentHandlerTypeMetric = 'cls' | 'lcp' | 'ttfb' | 'inp';\n\n// We provide this here manually instead of relying on a global, as this is not available in non-browser environements\n// And we do not want to expose such types\ninterface PerformanceEntry {\n readonly duration: number;\n readonly entryType: string;\n readonly name: string;\n readonly startTime: number;\n toJSON(): Record<string, unknown>;\n}\nexport interface PerformanceEventTiming extends PerformanceEntry {\n processingStart: number;\n processingEnd: number;\n duration: number;\n cancelable?: boolean;\n target?: unknown | null;\n interactionId?: number;\n}\n\ninterface PerformanceScriptTiming extends PerformanceEntry {\n sourceURL: string;\n sourceFunctionName: string;\n sourceCharPosition: number;\n invoker: string;\n invokerType: string;\n}\nexport interface PerformanceLongAnimationFrameTiming extends PerformanceEntry {\n scripts: PerformanceScriptTiming[];\n}\n\ninterface Metric {\n /**\n * The name of the metric (in acronym form).\n */\n name: 'CLS' | 'FCP' | 'INP' | 'LCP' | 'TTFB';\n\n /**\n * The current value of the metric.\n */\n value: number;\n\n /**\n * The rating as to whether the metric value is within the \"good\",\n * \"needs improvement\", or \"poor\" thresholds of the metric.\n */\n rating: 'good' | 'needs-improvement' | 'poor';\n\n /**\n * The delta between the current value and the last-reported value.\n * On the first report, `delta` and `value` will always be the same.\n */\n delta: number;\n\n /**\n * A unique ID representing this particular metric instance. This ID can\n * be used by an analytics tool to dedupe multiple values sent for the same\n * metric instance, or to group multiple deltas together and calculate a\n * total. It can also be used to differentiate multiple different metric\n * instances sent from the same page, which can happen if the page is\n * restored from the back/forward cache (in that case new metrics object\n * get created).\n */\n id: string;\n\n /**\n * Any performance entries relevant to the metric value calculation.\n * The array may also be empty if the metric value was not based on any\n * entries (e.g. a CLS value of 0 given no layout shifts).\n */\n entries: PerformanceEntry[];\n\n /**\n * The type of navigation\n *\n * Navigation Timing API (or `undefined` if the browser doesn't\n * support that API). For pages that are restored from the bfcache, this\n * value will be 'back-forward-cache'.\n */\n navigationType: 'navigate' | 'reload' | 'back-forward' | 'back-forward-cache' | 'prerender' | 'restore';\n}\n\ntype InstrumentHandlerType = InstrumentHandlerTypeMetric | InstrumentHandlerTypePerformanceObserver;\n\ntype StopListening = undefined | void | (() => void);\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype InstrumentHandlerCallback = (data: any) => void;\n\ntype CleanupHandlerCallback = () => void;\n\nconst handlers: { [key in InstrumentHandlerType]?: InstrumentHandlerCallback[] } = {};\nconst instrumented: { [key in InstrumentHandlerType]?: boolean } = {};\n\nlet _previousCls: Metric | undefined;\nlet _previousLcp: Metric | undefined;\nlet _previousTtfb: Metric | undefined;\nlet _previousInp: Metric | undefined;\n\n/**\n * Add a callback that will be triggered when a CLS metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for CLS when the cleanup callback is called.\n * This will lead to the CLS being finalized and frozen.\n */\nexport function addClsInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('cls', callback, instrumentCls, _previousCls, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a LCP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n *\n * Pass `stopOnCallback = true` to stop listening for LCP when the cleanup callback is called.\n * This will lead to the LCP being finalized and frozen.\n */\nexport function addLcpInstrumentationHandler(\n callback: (data: { metric: Metric }) => void,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n return addMetricObserver('lcp', callback, instrumentLcp, _previousLcp, stopOnCallback);\n}\n\n/**\n * Add a callback that will be triggered when a TTFD metric is available.\n */\nexport function addTtfbInstrumentationHandler(callback: (data: { metric: Metric }) => void): CleanupHandlerCallback {\n return addMetricObserver('ttfb', callback, instrumentTtfb, _previousTtfb);\n}\n\nexport type InstrumentationHandlerCallback = (data: {\n metric: Omit<Metric, 'entries'> & {\n entries: PerformanceEventTiming[];\n };\n}) => void;\n\n/**\n * Add a callback that will be triggered when a INP metric is available.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addInpInstrumentationHandler(callback: InstrumentationHandlerCallback): CleanupHandlerCallback {\n return addMetricObserver('inp', callback, instrumentInp, _previousInp);\n}\n\nexport function addPerformanceInstrumentationHandler(\n type: 'event',\n callback: (data: { entries: ((PerformanceEntry & { target?: unknown | null }) | PerformanceEventTiming)[] }) => void,\n): CleanupHandlerCallback;\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback;\n\n/**\n * Add a callback that will be triggered when a performance observer is triggered,\n * and receives the entries of the observer.\n * Returns a cleanup callback which can be called to remove the instrumentation handler.\n */\nexport function addPerformanceInstrumentationHandler(\n type: InstrumentHandlerTypePerformanceObserver,\n callback: (data: { entries: PerformanceEntry[] }) => void,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n if (!instrumented[type]) {\n instrumentPerformanceObserver(type);\n instrumented[type] = true;\n }\n\n return getCleanupCallback(type, callback);\n}\n\n/** Trigger all handlers of a given type. */\nfunction triggerHandlers(type: InstrumentHandlerType, data: unknown): void {\n const typeHandlers = handlers[type];\n\n if (!typeHandlers?.length) {\n return;\n }\n\n for (const handler of typeHandlers) {\n try {\n handler(data);\n } catch (e) {\n DEBUG_BUILD &&\n debug.error(\n `Error while triggering instrumentation handler.\\nType: ${type}\\nName: ${getFunctionName(handler)}\\nError:`,\n e,\n );\n }\n }\n}\n\nfunction instrumentCls(): StopListening {\n return onCLS(\n metric => {\n triggerHandlers('cls', {\n metric,\n });\n _previousCls = metric;\n },\n // We want the callback to be called whenever the CLS value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: true },\n );\n}\n\nfunction instrumentLcp(): StopListening {\n return onLCP(\n metric => {\n triggerHandlers('lcp', {\n metric,\n });\n _previousLcp = metric;\n },\n // We want the callback to be called whenever the LCP value updates.\n // By default, the callback is only called when the tab goes to the background.\n { reportAllChanges: true },\n );\n}\n\nfunction instrumentTtfb(): StopListening {\n return onTTFB(metric => {\n triggerHandlers('ttfb', {\n metric,\n });\n _previousTtfb = metric;\n });\n}\n\nfunction instrumentInp(): void {\n return onINP(metric => {\n triggerHandlers('inp', {\n metric,\n });\n _previousInp = metric;\n });\n}\n\nfunction addMetricObserver(\n type: InstrumentHandlerTypeMetric,\n callback: InstrumentHandlerCallback,\n instrumentFn: () => StopListening,\n previousValue: Metric | undefined,\n stopOnCallback = false,\n): CleanupHandlerCallback {\n addHandler(type, callback);\n\n let stopListening: StopListening | undefined;\n\n if (!instrumented[type]) {\n stopListening = instrumentFn();\n instrumented[type] = true;\n }\n\n if (previousValue) {\n callback({ metric: previousValue });\n }\n\n return getCleanupCallback(type, callback, stopOnCallback ? stopListening : undefined);\n}\n\nfunction instrumentPerformanceObserver(type: InstrumentHandlerTypePerformanceObserver): void {\n const options: PerformanceObserverInit = {};\n\n // Special per-type options we want to use\n if (type === 'event') {\n options.durationThreshold = 0;\n }\n\n observe(\n type,\n entries => {\n triggerHandlers(type, { entries });\n },\n options,\n );\n}\n\nfunction addHandler(type: InstrumentHandlerType, handler: InstrumentHandlerCallback): void {\n handlers[type] = handlers[type] || [];\n handlers[type].push(handler);\n}\n\n// Get a callback which can be called to remove the instrumentation handler\nfunction getCleanupCallback(\n type: InstrumentHandlerType,\n callback: InstrumentHandlerCallback,\n stopListening: StopListening,\n): CleanupHandlerCallback {\n return () => {\n if (stopListening) {\n stopListening();\n }\n\n const typeHandlers = handlers[type];\n\n if (!typeHandlers) {\n return;\n }\n\n const index = typeHandlers.indexOf(callback);\n if (index !== -1) {\n typeHandlers.splice(index, 1);\n }\n };\n}\n\n/**\n * Check if a PerformanceEntry is a PerformanceEventTiming by checking for the `duration` property.\n */\nexport function isPerformanceEventTiming(entry: PerformanceEntry): entry is PerformanceEventTiming {\n return 'duration' in entry;\n}\n"],"names":[],"mappings":";;;;;;;;AA6GA,MAAM,WAA6E,EAAC;AACpF,MAAM,eAA6D,EAAC;AAEpE,IAAI,YAAA;AACJ,IAAI,YAAA;AACJ,IAAI,aAAA;AACJ,IAAI,YAAA;AASG,SAAS,4BAAA,CACd,QAAA,EACA,cAAA,GAAiB,KAAA,EACO;AACxB,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,cAAc,cAAc,CAAA;AACvF;AASO,SAAS,4BAAA,CACd,QAAA,EACA,cAAA,GAAiB,KAAA,EACO;AACxB,EAAA,OAAO,iBAAA,CAAkB,KAAA,EAAO,QAAA,EAAU,aAAA,EAAe,cAAc,cAAc,CAAA;AACvF;AAKO,SAAS,8BAA8B,QAAA,EAAsE;A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AAI,SAAS,OAAA,EAAS;AACpB,IAAA,OAAA,CAAQ,iBAAA,GAAoB,CAAA;AAAA,EAC9B;AAEA,EAAA,OAAA;AAAA,IACE,IAAA;AAAA,IACA,CAAA,OAAA,KAAW;AACT,MAAA,eAAA,CAAgB,IAAA,EAAM,EAAE,OAAA,EAAS,CAAA;AAAA,IACnC,CAAA;AAAA,IACA;AAAA,GACF;AACF;AAEA,SAAS,UAAA,CAAW,MAA6B,OAAA,EAA0C;AACzF,EAAA,QAAA,CAAS,IAAI,CAAA,GAAI,QAAA,CAAS,IAAI,KAAK,EAAC;AACpC,EAAA,QAAA,CAAS,IAAI,CAAA,CAAE,IAAA,CAAK,OAAO,CAAA;AAC7B;AAGA,SAAS,kBAAA,CACP,IAAA,EACA,QAAA,EACA,aAAA,EACwB;AACxB,EAAA,OAAO,MAAM;AACX,IAAA,IAAI,aAAA,EAAe;AACjB,MAAA,aAAA,EAAc;AAAA,IAChB;AAEA,IAAA,MAAM,YAAA,GAAe,SAAS,IAAI,CAAA;AAElC,IAAA,IAAI,CAAC,YAAA,EAAc;AACjB,MAAA;AAAA,IACF;AAEA,IAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,OAAA,CAAQ,QAAQ,CAAA;AAC3C,IAAA,IAAI,UAAU,EAAA,EAAI;AAChB,MAAA,YAAA,CAAa,MAAA,CAAO,OAAO,CAAC,CAAA;AAAA,IAC9B;AAAA,EACF,CAAA;AACF;AAKO,SAAS,yBAAyB,KAAA,EAA0D;AACjG,EAAA,OAAO,UAAA,IAAc,KAAA;AACvB;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lcp.js","sources":["../../../src/metrics/lcp.ts"],"sourcesContent":["/**\n * 60 seconds is the maximum for a plausible LCP value.\n */\nexport const MAX_PLAUSIBLE_LCP_DURATION = 60_000;\n\nexport function isValidLcpMetric(lcpValue: number | undefined): lcpValue is number {\n return lcpValue != null && lcpValue > 0 && lcpValue <= MAX_PLAUSIBLE_LCP_DURATION;\n}\n"],"names":[],"mappings":"AAGO,MAAM,0BAAA,GAA6B;AAEnC,SAAS,iBAAiB,QAAA,EAAkD;AACjF,EAAA,OAAO,QAAA,IAAY,IAAA,IAAQ,QAAA,GAAW,CAAA,IAAK,QAAA,IAAY,0BAAA;AACzD;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resourceTiming.js","sources":["../../../src/metrics/resourceTiming.ts"],"sourcesContent":["import type { SpanAttributes } from '@sentry/core';\nimport { browserPerformanceTimeOrigin } from '@sentry/core';\nimport { extractNetworkProtocol, getBrowserPerformanceAPI } from './utils';\n\nfunction getAbsoluteTime(time: number | undefined): number | undefined {\n // falsy values should be preserved so that we can later on drop undefined values and\n // preserve 0 vals for cross-origin resources without proper `Timing-Allow-Origin` header.\n return time ? ((browserPerformanceTimeOrigin() || performance.timeOrigin) + time) / 1000 : time;\n}\n\n/**\n * Converts a PerformanceResourceTiming entry to span data for the resource span. Most importantly,\n * it converts the timing values from timestamps relative to the `performance.timeOrigin` to absolute timestamps\n * in seconds.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming#timestamps\n *\n * @param resourceTiming\n * @returns An array where the first element is the attribute name and the second element is the attribute value.\n */\nexport function resourceTimingToSpanAttributes(resourceTiming: PerformanceResourceTiming): SpanAttributes {\n const timingSpanData: SpanAttributes = {};\n // Checking for only `undefined` and `null` is intentional because it's\n // valid for `nextHopProtocol` to be an empty string.\n if (resourceTiming.nextHopProtocol != undefined) {\n const { name, version } = extractNetworkProtocol(resourceTiming.nextHopProtocol);\n timingSpanData['network.protocol.version'] = version;\n timingSpanData['network.protocol.name'] = name;\n }\n\n if (!(browserPerformanceTimeOrigin() || getBrowserPerformanceAPI()?.timeOrigin)) {\n return timingSpanData;\n }\n\n return dropUndefinedKeysFromObject({\n ...timingSpanData,\n\n 'http.request.redirect_start': getAbsoluteTime(resourceTiming.redirectStart),\n 'http.request.redirect_end': getAbsoluteTime(resourceTiming.redirectEnd),\n\n 'http.request.worker_start': getAbsoluteTime(resourceTiming.workerStart),\n\n 'http.request.fetch_start': getAbsoluteTime(resourceTiming.fetchStart),\n\n 'http.request.domain_lookup_start': getAbsoluteTime(resourceTiming.domainLookupStart),\n 'http.request.domain_lookup_end': getAbsoluteTime(resourceTiming.domainLookupEnd),\n\n 'http.request.connect_start': getAbsoluteTime(resourceTiming.connectStart),\n 'http.request.secure_connection_start': getAbsoluteTime(resourceTiming.secureConnectionStart),\n 'http.request.connection_end': getAbsoluteTime(resourceTiming.connectEnd),\n\n 'http.request.request_start': getAbsoluteTime(resourceTiming.requestStart),\n\n 'http.request.response_start': getAbsoluteTime(resourceTiming.responseStart),\n 'http.request.response_end': getAbsoluteTime(resourceTiming.responseEnd),\n\n // For TTFB we actually want the relative time from timeOrigin to responseStart\n // This way, TTFB always measures the \"first page load\" experience.\n // see: https://web.dev/articles/ttfb#measure-resource-requests\n 'http.request.time_to_first_byte':\n resourceTiming.responseStart != null ? resourceTiming.responseStart / 1000 : undefined,\n });\n}\n\n/**\n * Remove properties with `undefined` as value from an object.\n * In contrast to `dropUndefinedKeys` in core this funciton only works on first-level\n * key-value objects and does not recursively go into object properties or arrays.\n */\nfunction dropUndefinedKeysFromObject<T extends object>(attrs: T): Partial<T> {\n return Object.fromEntries(Object.entries(attrs).filter(([, value]) => value != null)) as Partial<T>;\n}\n"],"names":[],"mappings":";;;AAIA,SAAS,gBAAgB,IAAA,EAA8C;AAGrE,EAAA,OAAO,SAAS,4BAAA,EAA6B,IAAK,WAAA,CAAY,UAAA,IAAc,QAAQ,GAAA,GAAO,IAAA;AAC7F;AAYO,SAAS,+BAA+B,cAAA,EAA2D;AACxG,EAAA,MAAM,iBAAiC,EAAC;AAGxC,EAAA,IAAI,cAAA,CAAe,mBAAmB,MAAA,EAAW;AAC/C,IAAA,MAAM,EAAE,IAAA,EAAM,OAAA,EAAQ,GAAI,sBAAA,CAAuB,eAAe,eAAe,CAAA;AAC/E,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A,OAAO,MAAA,CAAO,WAAA,CAAY,MAAA,CAAO,OAAA,CAAQ,KAAK,CAAA,CAAE,MAAA,CAAO,CAAC,GAAG,KAAK,CAAA,KAAM,KAAA,IAAS,IAAI,CAAC,CAAA;AACtF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"userTiming.js","sources":["../../../src/metrics/userTiming.ts"],"sourcesContent":["import { SENTRY_ORIGIN } from '@sentry/conventions/attributes';\nimport type { IntegrationFn, Span, SpanAttributes, SpanAttributeValue } from '@sentry/core';\nimport {\n browserPerformanceTimeOrigin,\n defineIntegration,\n isPrimitive,\n spanToJSON,\n stringMatchesSomePattern,\n} from '@sentry/core';\nimport { getBrowserPerformanceAPI, msToSec, startAndEndSpan } from './utils';\nimport { getNavigationEntry } from './web-vitals/lib/getNavigationEntry';\n\ninterface UserTimingOptions {\n /**\n * User Timing entries with names matching any of these strings or regular expressions will not be emitted.\n *\n * Default: []\n */\n ignore?: Array<string | RegExp>;\n}\n\nconst INTEGRATION_NAME = 'UserTiming';\n\nconst _userTimingIntegration = ((options: UserTimingOptions = {}) => {\n return {\n name: INTEGRATION_NAME,\n setup(client) {\n const performance = getBrowserPerformanceAPI();\n const timeOrigin = browserPerformanceTimeOrigin();\n if (!performance?.getEntries || !timeOrigin) {\n return;\n }\n const timeOriginInSeconds = msToSec(timeOrigin);\n let performanceCursor = 0;\n\n client.on('beforeIdleSpanEnd', idleSpan => {\n const { op: parentOp, start_timestamp: parentStartTimestamp } = spanToJSON(idleSpan);\n if (parentOp !== 'pageload' && parentOp !== 'navigation') {\n return;\n }\n\n const requestTime = msToSec(getNavigationEntry(false)?.requestStart ?? 0);\n const performanceEntries = performance.getEntries();\n\n for (const entry of performanceEntries.slice(performanceCursor)) {\n if (entry.entryType !== 'mark' && entry.entryType !== 'measure') {\n continue;\n }\n\n const startTime = msToSec(entry.startTime);\n const absoluteStartTime = timeOriginInSeconds + startTime;\n\n if (parentOp === 'navigation' && parentStartTimestamp && absoluteStartTime < parentStartTimestamp) {\n continue;\n }\n\n _addUserTimingSpan(\n idleSpan,\n entry,\n startTime,\n msToSec(Math.max(0, entry.duration)),\n timeOriginInSeconds,\n requestTime,\n options.ignore ?? [],\n );\n }\n\n performanceCursor = performanceEntries.length;\n });\n },\n };\n}) satisfies IntegrationFn;\n\n/**\n * Captures spans created with the browser's User Timing APIs, `performance.mark` and `performance.measure`.\n *\n * The integration must be explicitly added to `Sentry.init`. Entries are attached to the active pageload or\n * navigation span when it ends.\n *\n * @example\n * ```ts\n * Sentry.init({\n * integrations: [\n * Sentry.browserTracingIntegration(),\n * Sentry.userTimingIntegration({\n * ignore: ['third-party-mark', /framework-measure/],\n * }),\n * ],\n * });\n * ```\n */\nexport const userTimingIntegration = defineIntegration(_userTimingIntegration);\n\n/**\n * Creates a span for a browser User Timing entry.\n * Exported only for tests.\n */\nexport function _addUserTimingSpan(\n parentSpan: Span,\n entry: PerformanceEntry,\n startTime: number,\n duration: number,\n timeOrigin: number,\n requestTime: number,\n ignore: Array<string | RegExp>,\n): void {\n if (isReact19MeasureEntry(entry) || stringMatchesSomePattern(entry.name, ignore)) {\n return;\n }\n\n // Measures can reference arbitrary timestamps, including timestamps before the page request started.\n const spanStartTimestamp = timeOrigin + Math.max(startTime, requestTime);\n const originalStartTimestamp = timeOrigin + startTime;\n const spanEndTimestamp = originalStartTimestamp + duration;\n\n const attributes: SpanAttributes = {\n [SENTRY_ORIGIN]: `auto.browser.user_timing.${entry.entryType}`,\n };\n\n if (spanStartTimestamp !== originalStartTimestamp) {\n attributes['sentry.browser.measure_happened_before_request'] = true;\n attributes['sentry.browser.measure_start_time'] = spanStartTimestamp;\n }\n\n addDetailToSpanAttributes(attributes, entry as PerformanceMeasure);\n\n // Third-party measurements can contain timestamps which would produce invalid spans.\n if (spanStartTimestamp <= spanEndTimestamp) {\n startAndEndSpan(parentSpan, spanStartTimestamp, spanEndTimestamp, {\n name: entry.name,\n op: entry.entryType,\n attributes,\n });\n }\n}\n\n/**\n * React 19.2+ creates performance.measure entries for component renders.\n * We can identify them by the `detail.devtools.track` property being set to 'Components ⚛'.\n * See https://react.dev/reference/dev-tools/react-performance-tracks.\n */\nfunction isReact19MeasureEntry(entry: PerformanceEntry): boolean | void {\n if (entry.entryType !== 'measure') {\n return;\n }\n\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n return (entry as PerformanceMeasure).detail.devtools.track === 'Components ⚛';\n } catch {\n return;\n }\n}\n\nfunction addDetailToSpanAttributes(attributes: SpanAttributes, entry: PerformanceMeasure): void {\n try {\n // Accessing detail can throw in some browsers due to security restrictions.\n const detail = entry.detail;\n if (!detail) {\n return;\n }\n\n if (typeof detail === 'object') {\n for (const [key, value] of Object.entries(detail)) {\n if (value && isPrimitive(value)) {\n attributes[`sentry.browser.measure.detail.${key}`] = value as SpanAttributeValue;\n } else if (value !== undefined) {\n try {\n attributes[`sentry.browser.measure.detail.${key}`] = JSON.stringify(value);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n }\n }\n return;\n }\n\n if (isPrimitive(detail)) {\n attributes['sentry.browser.measure.detail'] = detail as SpanAttributeValue;\n return;\n }\n\n try {\n attributes['sentry.browser.measure.detail'] = JSON.stringify(detail);\n } catch {\n // User-provided detail values are not guaranteed to be serializable.\n }\n } catch {\n // Accessing detail can throw in some browsers due to security restrictions.\n }\n}\n"],"names":[],"mappings":";;;;;AAqBA,MAAM,gBAAA,GAAmB,YAAA;AAEzB,MAAM,sBAAA,IAA0B,CAAC,OAAA,GAA6B,EAAC,KAAM;AACnE,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,gBAAA;AAAA,IACN,MAAM,MAAA,EAAQ;AACZ,MAAA,MAAM,cAAc,wBAAA,EAAyB;AAC7C,MAAA,MAAM,aAAa,4BAAA,EAA6B;AAChD,MAAA,IAAI,CAAC,WAAA,EAAa,UAAA,IAAc,CAAC,UAAA,EAAY;AAC3C,QAAA;AAAA,MACF;AACA,MAAA,MAAM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AA,CAA0B,YAA4B,KAAA,EAAiC;AAC9F,EAAA,IAAI;AAEF,IAAA,MAAM,SAAS,KAAA,CAAM,MAAA;AACrB,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA;AAAA,IACF;AAEA,IAAA,IAAI,OAAO,WAAW,QAAA,EAAU;AAC9B,MAAA,KAAA,MAAW,CAAC,GAAA,EAAK,KAAK,KAAK,MAAA,CAAO,OAAA,CAAQ,MAAM,CAAA,EAAG;AACjD,QAAA,IAAI,KAAA,IAAS,WAAA,CAAY,KAAK,CAAA,EAAG;AAC/B,UAAA,UAAA,CAAW,CAAA,8BAAA,EAAiC,GAAG,CAAA,CAAE,CAAA,GAAI,KAAA;AAAA,QACvD,CAAA,MAAA,IAAW,UAAU,KAAA,CAAA,EAAW;AAC9B,UAAA,IAAI;AACF,YAAA,UAAA,CAAW,iCAAiC,GAAG,CAAA,CAAE,CAAA,GAAI,IAAA,CAAK,UAAU,KAAK,CAAA;AAAA,UAC3E,CAAA,CAAA,MAAQ;AAAA,UAER;AAAA,QACF;AAAA,MACF;AACA,MAAA;AAAA,IACF;AAEA,IAAA,IAAI,WAAA,CAAY,MAAM,CAAA,EAAG;AACvB,MAAA,UAAA,CAAW,+BAA+B,CAAA,GAAI,MAAA;AAC9C,MAAA;AAAA,IACF;AAEA,IAAA,IAAI;AACF,MAAA,UAAA,CAAW,+BAA+B,CAAA,GAAI,IAAA,CAAK,SAAA,CAAU,MAAM,CAAA;AAAA,IACrE,CAAA,CAAA,MAAQ;AAAA,IAER;AAAA,EACF,CAAA,CAAA,MAAQ;AAAA,EAER;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/metrics/utils.ts"],"sourcesContent":["import type { Client, SentrySpan, Span, SpanTimeInput, StartSpanOptions } from '@sentry/core';\nimport { spanToJSON, startInactiveSpan, withActiveSpan } from '@sentry/core';\nimport { WINDOW } from '../types';\nimport { onHidden } from './web-vitals/lib/onHidden';\n\nexport type WebVitalReportEvent = 'pagehide' | 'navigation';\n\n/**\n * Checks if a given value is a valid measurement value.\n */\nexport function isMeasurementValue(value: unknown): value is number {\n return typeof value === 'number' && isFinite(value);\n}\n\n/**\n * Helper function to start child on transactions. This function will make sure that the transaction will\n * use the start timestamp of the created child span if it is earlier than the transactions actual\n * start timestamp.\n */\nexport function startAndEndSpan(\n parentSpan: Span,\n startTimeInSeconds: number,\n endTime: SpanTimeInput,\n { ...ctx }: StartSpanOptions,\n): Span | undefined {\n const parentStartTime = spanToJSON(parentSpan).start_timestamp;\n if (parentStartTime && parentStartTime > startTimeInSeconds) {\n // We can only do this for SentrySpans...\n if (typeof (parentSpan as Partial<SentrySpan>).updateStartTime === 'function') {\n (parentSpan as SentrySpan).updateStartTime(startTimeInSeconds);\n }\n }\n\n // The return value only exists for tests\n return withActiveSpan(parentSpan, () => {\n const span = startInactiveSpan({\n startTime: startTimeInSeconds,\n ...ctx,\n });\n\n if (span) {\n span.end(endTime);\n }\n\n return span;\n });\n}\n\n/** Get the browser performance API. */\nexport function getBrowserPerformanceAPI(): Performance | undefined {\n // @ts-expect-error we want to make sure all of these are available, even if TS is sure they are\n return WINDOW.addEventListener && WINDOW.performance;\n}\n\n/**\n * Converts from milliseconds to seconds\n * @param time time in ms\n */\nexport function msToSec(time: number): number {\n return time / 1000;\n}\n\n/**\n * Converts ALPN protocol ids to name and version.\n *\n * (https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml#alpn-protocol-ids)\n * @param nextHopProtocol PerformanceResourceTiming.nextHopProtocol\n */\nexport function extractNetworkProtocol(nextHopProtocol: string): { name: string; version: string } {\n let name = 'unknown';\n let version = 'unknown';\n let _name = '';\n for (const char of nextHopProtocol) {\n // http/1.1 etc.\n if (char === '/') {\n [name, version] = nextHopProtocol.split('/') as [string, string];\n break;\n }\n // h2, h3 etc.\n if (!isNaN(Number(char))) {\n name = _name === 'h' ? 'http' : _name;\n version = nextHopProtocol.split(_name)[1] as string;\n break;\n }\n _name += char;\n }\n if (_name === nextHopProtocol) {\n // webrtc, ftp, etc.\n name = _name;\n }\n return { name, version };\n}\n\n/**\n * Generic support check for web vitals\n */\nexport function supportsWebVital(entryType: 'layout-shift' | 'largest-contentful-paint'): boolean {\n try {\n return PerformanceObserver.supportedEntryTypes.includes(entryType);\n } catch {\n return false;\n }\n}\n\n/**\n * Listens for events on which we want to collect a previously accumulated web vital value.\n * Currently, this includes:\n *\n * - pagehide (i.e. user minimizes browser window, hides tab, etc)\n * - soft navigation (we only care about the vital of the initially loaded route)\n *\n * As a \"side-effect\", this function will also collect the span id of the pageload span.\n *\n * @param collectorCallback the callback to be called when the first of these events is triggered. Parameters:\n * - event: the event that triggered the reporting of the web vital value.\n * - pageloadSpanId: the span id of the pageload span. This is used to link the web vital span to the pageload span.\n * - pageloadSpan: the pageload span instance. This is used for full access to the pageload span for span streaming.\n */\nexport function listenForWebVitalReportEvents(\n client: Client,\n collectorCallback: (event: WebVitalReportEvent, pageloadSpanId: string, pageloadSpan?: Span) => void,\n) {\n let pageloadSpan: Span | undefined;\n\n let collected = false;\n function _runCollectorCallbackOnce(event: WebVitalReportEvent) {\n if (!collected && pageloadSpan) {\n collectorCallback(event, pageloadSpan.spanContext().spanId, pageloadSpan);\n }\n collected = true;\n }\n\n // eslint-disable-next-line typescript/no-deprecated\n onHidden(() => {\n _runCollectorCallbackOnce('pagehide');\n });\n\n const unsubscribeStartNavigation = client.on('beforeStartNavigationSpan', (_, options) => {\n // we only want to collect LCP if we actually navigate. Redirects should be ignored.\n if (!options?.isRedirect) {\n _runCollectorCallbackOnce('navigation');\n unsubscribeStartNavigation();\n unsubscribeAfterStartPageLoadSpan();\n }\n });\n\n const unsubscribeAfterStartPageLoadSpan = client.on('afterStartPageLoadSpan', span => {\n pageloadSpan = span;\n unsubscribeAfterStartPageLoadSpan();\n });\n}\n"],"names":[],"mappings":";;;;AAUO,SAAS,mBAAmB,KAAA,EAAiC;AAClE,EAAA,OAAO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AAA,CAAO,EAAA,CAAG,wBAAA,EAA0B,CAAA,IAAA,KAAQ;AACpF,IAAA,YAAA,GAAe,IAAA;AACf,IAAA,iCAAA,EAAkC;AAAA,EACpC,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { WINDOW } from '../../types.js';
|
|
2
|
-
import { bindReporter } from './lib/bindReporter.js';
|
|
3
|
-
import { getVisibilityWatcher } from './lib/getVisibilityWatcher.js';
|
|
4
|
-
import { initMetric } from './lib/initMetric.js';
|
|
5
|
-
import { initUnique } from './lib/initUnique.js';
|
|
6
|
-
import { LayoutShiftManager } from './lib/LayoutShiftManager.js';
|
|
7
|
-
import { observe } from './lib/observe.js';
|
|
8
|
-
import { runOnce } from './lib/runOnce.js';
|
|
9
|
-
import { onFCP } from './onFCP.js';
|
|
10
|
-
|
|
11
|
-
const CLSThresholds = [0.1, 0.25];
|
|
12
|
-
const onCLS = (onReport, opts = {}) => {
|
|
13
|
-
onFCP(
|
|
14
|
-
runOnce(() => {
|
|
15
|
-
const metric = initMetric("CLS", 0);
|
|
16
|
-
let report;
|
|
17
|
-
const visibilityWatcher = getVisibilityWatcher();
|
|
18
|
-
const layoutShiftManager = initUnique(opts, LayoutShiftManager);
|
|
19
|
-
const handleEntries = (entries) => {
|
|
20
|
-
for (const entry of entries) {
|
|
21
|
-
layoutShiftManager._processEntry(entry);
|
|
22
|
-
}
|
|
23
|
-
if (layoutShiftManager._sessionValue > metric.value) {
|
|
24
|
-
metric.value = layoutShiftManager._sessionValue;
|
|
25
|
-
metric.entries = layoutShiftManager._sessionEntries;
|
|
26
|
-
report();
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
const po = observe("layout-shift", handleEntries);
|
|
30
|
-
if (po) {
|
|
31
|
-
report = bindReporter(onReport, metric, CLSThresholds, opts.reportAllChanges);
|
|
32
|
-
visibilityWatcher.onHidden(() => {
|
|
33
|
-
handleEntries(po.takeRecords());
|
|
34
|
-
report(true);
|
|
35
|
-
});
|
|
36
|
-
WINDOW?.setTimeout?.(report);
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export { CLSThresholds, onCLS };
|
|
43
|
-
//# sourceMappingURL=getCLS.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCLS.js","sources":["../../../../src/metrics/web-vitals/getCLS.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { WINDOW } from '../../types';\nimport { bindReporter } from './lib/bindReporter';\nimport { getVisibilityWatcher } from './lib/getVisibilityWatcher';\nimport { initMetric } from './lib/initMetric';\nimport { initUnique } from './lib/initUnique';\nimport { LayoutShiftManager } from './lib/LayoutShiftManager';\nimport { observe } from './lib/observe';\nimport { runOnce } from './lib/runOnce';\nimport { onFCP } from './onFCP';\nimport type { CLSMetric, MetricRatingThresholds, ReportOpts } from './types';\n\n/** Thresholds for CLS. See https://web.dev/articles/cls#what_is_a_good_cls_score */\nexport const CLSThresholds: MetricRatingThresholds = [0.1, 0.25];\n\n/**\n * Calculates the [CLS](https://web.dev/articles/cls) value for the current page and\n * calls the `callback` function once the value is ready to be reported, along\n * with all `layout-shift` performance entries that were used in the metric\n * value calculation. The reported value is a `double` (corresponding to a\n * [layout shift score](https://web.dev/articles/cls#layout_shift_score)).\n *\n * If the `reportAllChanges` configuration option is set to `true`, the\n * `callback` function will be called as soon as the value is initially\n * determined as well as any time the value changes throughout the page\n * lifespan.\n *\n * _**Important:** CLS should be continually monitored for changes throughout\n * the entire lifespan of a page—including if the user returns to the page after\n * it's been hidden/backgrounded. However, since browsers often [will not fire\n * additional callbacks once the user has backgrounded a\n * page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden),\n * `callback` is always called when the page's visibility state changes to\n * hidden. As a result, the `callback` function might be called multiple times\n * during the same page load._\n */\nexport const onCLS = (onReport: (metric: CLSMetric) => void, opts: ReportOpts = {}) => {\n // Start monitoring FCP so we can only report CLS if FCP is also reported.\n // Note: this is done to match the current behavior of CrUX.\n onFCP(\n runOnce(() => {\n const metric = initMetric('CLS', 0);\n let report: ReturnType<typeof bindReporter>;\n const visibilityWatcher = getVisibilityWatcher();\n\n const layoutShiftManager = initUnique(opts, LayoutShiftManager);\n\n const handleEntries = (entries: LayoutShift[]) => {\n for (const entry of entries) {\n layoutShiftManager._processEntry(entry);\n }\n\n // If the current session value is larger than the current CLS value,\n // update CLS and the entries contributing to it.\n if (layoutShiftManager._sessionValue > metric.value) {\n metric.value = layoutShiftManager._sessionValue;\n metric.entries = layoutShiftManager._sessionEntries;\n report();\n }\n };\n\n const po = observe('layout-shift', handleEntries);\n if (po) {\n report = bindReporter(onReport, metric, CLSThresholds, opts.reportAllChanges);\n\n visibilityWatcher.onHidden(() => {\n handleEntries(po.takeRecords() as CLSMetric['entries']);\n report(true);\n });\n\n // Queue a task to report (if nothing else triggers a report first).\n // This allows CLS to be reported as soon as FCP fires when\n // `reportAllChanges` is true.\n WINDOW?.setTimeout?.(report);\n }\n }),\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;AA4BO,MAAM,aAAA,GAAwC,CAAC,GAAA,EAAK,IAAI;AAuBxD,MAAM,KAAA,GAAQ,CAAC,QAAA,EAAuC,IAAA,GAAmB,EAAC,KAAM;AAGrF,EAAA,KAAA;AAAA,IACE,QAAQ,MAAM;AACZ,MAAA,MAAM,MAAA,GAAS,UAAA,CAAW,KAAA,EAAO,CAAC,CAAA;AAClC,MAAA,IAAI,MAAA;AACJ,MAAA,MAAM,oBAAoB,oBAAA,EAAqB;AAE/C,MAAA,MAAM,kBAAA,GAAqB,UAAA,CAAW,IAAA,EAAM,kBAAkB,CAAA;AAE9D,MAAA,MAAM,aAAA,GAAgB,CAAC,OAAA,KAA2B;AAChD,QAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,UAAA,kBAAA,CAAmB,cAAc,KAAK,CAAA;AAAA,QACxC;AAIA,QAAA,IAAI,kBAAA,CAAmB,aAAA,GAAgB,MAAA,CAAO,KAAA,EAAO;AACnD,UAAA,MAAA,CAAO,QAAQ,kBAAA,CAAmB,aAAA;AAClC,UAAA,MAAA,CAAO,UAAU,kBAAA,CAAmB,eAAA;AACpC,UAAA,MAAA,EAAO;AAAA,QACT;AAAA,MACF,CAAA;AAEA,MAAA,MAAM,EAAA,GAAK,OAAA,CAAQ,cAAA,EAAgB,aAAa,CAAA;AAChD,MAAA,IAAI,EAAA,EAAI;AACN,QAAA,MAAA,GAAS,YAAA,CAAa,QAAA,EAAU,MAAA,EAAQ,aAAA,EAAe,KAAK,gBAAgB,CAAA;AAE5E,QAAA,iBAAA,CAAkB,SAAS,MAAM;AAC/B,UAAA,aAAA,CAAc,EAAA,CAAG,aAAqC,CAAA;AACtD,UAAA,MAAA,CAAO,IAAI,CAAA;AAAA,QACb,CAAC,CAAA;AAKD,QAAA,MAAA,EAAQ,aAAa,MAAM,CAAA;AAAA,MAC7B;AAAA,IACF,CAAC;AAAA,GACH;AACF;;;;"}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { bindReporter } from './lib/bindReporter.js';
|
|
2
|
-
import { getVisibilityWatcher } from './lib/getVisibilityWatcher.js';
|
|
3
|
-
import { initMetric } from './lib/initMetric.js';
|
|
4
|
-
import { initUnique } from './lib/initUnique.js';
|
|
5
|
-
import { InteractionManager } from './lib/InteractionManager.js';
|
|
6
|
-
import { observe } from './lib/observe.js';
|
|
7
|
-
import { initInteractionCountPolyfill } from './lib/polyfills/interactionCountPolyfill.js';
|
|
8
|
-
import { whenActivated } from './lib/whenActivated.js';
|
|
9
|
-
import { whenIdleOrHidden } from './lib/whenIdleOrHidden.js';
|
|
10
|
-
|
|
11
|
-
const INPThresholds = [200, 500];
|
|
12
|
-
const DEFAULT_DURATION_THRESHOLD = 40;
|
|
13
|
-
const onINP = (onReport, opts = {}) => {
|
|
14
|
-
if (!(globalThis.PerformanceEventTiming && "interactionId" in PerformanceEventTiming.prototype)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const visibilityWatcher = getVisibilityWatcher();
|
|
18
|
-
whenActivated(() => {
|
|
19
|
-
initInteractionCountPolyfill();
|
|
20
|
-
const metric = initMetric("INP");
|
|
21
|
-
let report;
|
|
22
|
-
const interactionManager = initUnique(opts, InteractionManager);
|
|
23
|
-
const handleEntries = (entries) => {
|
|
24
|
-
whenIdleOrHidden(() => {
|
|
25
|
-
for (const entry of entries) {
|
|
26
|
-
interactionManager._processEntry(entry);
|
|
27
|
-
}
|
|
28
|
-
const inp = interactionManager._estimateP98LongestInteraction();
|
|
29
|
-
if (inp && inp._latency !== metric.value) {
|
|
30
|
-
metric.value = inp._latency;
|
|
31
|
-
metric.entries = inp.entries;
|
|
32
|
-
report();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
};
|
|
36
|
-
const po = observe("event", handleEntries, {
|
|
37
|
-
// Event Timing entries have their durations rounded to the nearest 8ms,
|
|
38
|
-
// so a duration of 40ms would be any event that spans 2.5 or more frames
|
|
39
|
-
// at 60Hz. This threshold is chosen to strike a balance between usefulness
|
|
40
|
-
// and performance. Running this callback for any interaction that spans
|
|
41
|
-
// just one or two frames is likely not worth the insight that could be
|
|
42
|
-
// gained.
|
|
43
|
-
durationThreshold: opts.durationThreshold ?? DEFAULT_DURATION_THRESHOLD
|
|
44
|
-
});
|
|
45
|
-
report = bindReporter(onReport, metric, INPThresholds, opts.reportAllChanges);
|
|
46
|
-
if (po) {
|
|
47
|
-
po.observe({ type: "first-input", buffered: true });
|
|
48
|
-
visibilityWatcher.onHidden(() => {
|
|
49
|
-
handleEntries(po.takeRecords());
|
|
50
|
-
report(true);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export { INPThresholds, onINP };
|
|
57
|
-
//# sourceMappingURL=getINP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getINP.js","sources":["../../../../src/metrics/web-vitals/getINP.ts"],"sourcesContent":["/*\n * Copyright 2022 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { bindReporter } from './lib/bindReporter';\nimport { getVisibilityWatcher } from './lib/getVisibilityWatcher';\nimport { initMetric } from './lib/initMetric';\nimport { initUnique } from './lib/initUnique';\nimport { InteractionManager } from './lib/InteractionManager';\nimport { observe } from './lib/observe';\nimport { initInteractionCountPolyfill } from './lib/polyfills/interactionCountPolyfill';\nimport { whenActivated } from './lib/whenActivated';\nimport { whenIdleOrHidden } from './lib/whenIdleOrHidden';\nimport type { INPMetric, INPReportOpts, MetricRatingThresholds } from './types';\n\n/** Thresholds for INP. See https://web.dev/articles/inp#what_is_a_good_inp_score */\nexport const INPThresholds: MetricRatingThresholds = [200, 500];\n\n// The default `durationThreshold` used across this library for observing\n// `event` entries via PerformanceObserver.\nconst DEFAULT_DURATION_THRESHOLD = 40;\n\n/**\n * Calculates the [INP](https://web.dev/articles/inp) value for the current\n * page and calls the `callback` function once the value is ready, along with\n * the `event` performance entries reported for that interaction. The reported\n * value is a `DOMHighResTimeStamp`.\n *\n * A custom `durationThreshold` configuration option can optionally be passed\n * to control what `event-timing` entries are considered for INP reporting. The\n * default threshold is `40`, which means INP scores of less than 40 will not\n * be reported. To avoid reporting no interactions in these cases, the library\n * will fall back to the input delay of the first interaction. Note that this\n * will not affect your 75th percentile INP value unless that value is also\n * less than 40 (well below the recommended\n * [good](https://web.dev/articles/inp#what_is_a_good_inp_score) threshold).\n *\n * If the `reportAllChanges` configuration option is set to `true`, the\n * `callback` function will be called as soon as the value is initially\n * determined as well as any time the value changes throughout the page\n * lifespan.\n *\n * _**Important:** INP should be continually monitored for changes throughout\n * the entire lifespan of a page—including if the user returns to the page after\n * it's been hidden/backgrounded. However, since browsers often [will not fire\n * additional callbacks once the user has backgrounded a\n * page](https://developer.chrome.com/blog/page-lifecycle-api/#advice-hidden),\n * `callback` is always called when the page's visibility state changes to\n * hidden. As a result, the `callback` function might be called multiple times\n * during the same page load._\n */\nexport const onINP = (onReport: (metric: INPMetric) => void, opts: INPReportOpts = {}) => {\n // Return if the browser doesn't support all APIs needed to measure INP.\n if (!(globalThis.PerformanceEventTiming && 'interactionId' in PerformanceEventTiming.prototype)) {\n return;\n }\n\n const visibilityWatcher = getVisibilityWatcher();\n\n whenActivated(() => {\n // TODO(philipwalton): remove once the polyfill is no longer needed.\n initInteractionCountPolyfill();\n\n const metric = initMetric('INP');\n // eslint-disable-next-line prefer-const\n let report: ReturnType<typeof bindReporter>;\n\n const interactionManager = initUnique(opts, InteractionManager);\n\n const handleEntries = (entries: INPMetric['entries']) => {\n // Queue the `handleEntries()` callback in the next idle task.\n // This is needed to increase the chances that all event entries that\n // occurred between the user interaction and the next paint\n // have been dispatched. Note: there is currently an experiment\n // running in Chrome (EventTimingKeypressAndCompositionInteractionId)\n // 123+ that if rolled out fully may make this no longer necessary.\n whenIdleOrHidden(() => {\n for (const entry of entries) {\n interactionManager._processEntry(entry);\n }\n\n const inp = interactionManager._estimateP98LongestInteraction();\n\n if (inp && inp._latency !== metric.value) {\n metric.value = inp._latency;\n metric.entries = inp.entries;\n report();\n }\n });\n };\n\n const po = observe('event', handleEntries, {\n // Event Timing entries have their durations rounded to the nearest 8ms,\n // so a duration of 40ms would be any event that spans 2.5 or more frames\n // at 60Hz. This threshold is chosen to strike a balance between usefulness\n // and performance. Running this callback for any interaction that spans\n // just one or two frames is likely not worth the insight that could be\n // gained.\n durationThreshold: opts.durationThreshold ?? DEFAULT_DURATION_THRESHOLD,\n });\n\n report = bindReporter(onReport, metric, INPThresholds, opts.reportAllChanges);\n\n if (po) {\n // Also observe entries of type `first-input`. This is useful in cases\n // where the first interaction is less than the `durationThreshold`.\n po.observe({ type: 'first-input', buffered: true });\n\n visibilityWatcher.onHidden(() => {\n handleEntries(po.takeRecords() as INPMetric['entries']);\n report(true);\n });\n }\n });\n};\n"],"names":[],"mappings":";;;;;;;;;;AA4BO,MAAM,aAAA,GAAwC,CAAC,GAAA,EAAK,GAAG;AAI9D,MAAM,0BAAA,GAA6B,EAAA;AA+B5B,MAAM,KAAA,GAAQ,CAAC,QAAA,EAAuC,IAAA,GAAsB,EAAC,KAAM;AAExF,EAAA,IAAI,EAAE,UAAA,CAAW,sBAAA,IAA0B,eAAA,IAAmB,uBAAuB,SAAA,CAAA,EAAY;AAC/F,IAAA;AAAA,EACF;AAEA,EAAA,MAAM,oBAAoB,oBAAA,EAAqB;AAE/C,EAAA,aAAA,CAAc,MAAM;AAElB,IAAA,4BAAA,EAA6B;AAE7B,IAAA,MAAM,MAAA,GAAS,WAAW,KAAK,CAAA;AAE/B,IAAA,IAAI,MAAA;AAEJ,IAAA,MAAM,kBAAA,GAAqB,UAAA,CAAW,IAAA,EAAM,kBAAkB,CAAA;AAE9D,IAAA,MAAM,aAAA,GAAgB,CAAC,OAAA,KAAkC;AAOvD,MAAA,gBAAA,CAAiB,MAAM;AACrB,QAAA,KAAA,MAAW,SAAS,OAAA,EAAS;AAC3B,UAAA,kBAAA,CAAmB,cAAc,KAAK,CAAA;AAAA,QACxC;AAEA,QAAA,MAAM,GAAA,GAAM,mBAAmB,8BAAA,EAA+B;AAE9D,QAAA,IAAI,GAAA,IAAO,GAAA,CAAI,QAAA,KAAa,MAAA,CAAO,KAAA,EAAO;AACxC,UAAA,MAAA,CAAO,QAAQ,GAAA,CAAI,QAAA;AACnB,UAAA,MAAA,CAAO,UAAU,GAAA,CAAI,OAAA;AACrB,UAAA,MAAA,EAAO;AAAA,QACT;AAAA,MACF,CAAC,CAAA;AAAA,IACH,CAAA;AAEA,IAAA,MAAM,EAAA,GAAK,OAAA,CAAQ,OAAA,EAAS,aAAA,EAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOzC,iBAAA,EAAmB,KAAK,iBAAA,IAAqB;AAAA,KAC9C,CAAA;AAED,IAAA,MAAA,GAAS,YAAA,CAAa,QAAA,EAAU,MAAA,EAAQ,aAAA,EAAe,KAAK,gBAAgB,CAAA;AAE5E,IAAA,IAAI,EAAA,EAAI;AAGN,MAAA,EAAA,CAAG,QAAQ,EAAE,IAAA,EAAM,aAAA,EAAe,QAAA,EAAU,MAAM,CAAA;AAElD,MAAA,iBAAA,CAAkB,SAAS,MAAM;AAC/B,QAAA,aAAA,CAAc,EAAA,CAAG,aAAqC,CAAA;AACtD,QAAA,MAAA,CAAO,IAAI,CAAA;AAAA,MACb,CAAC,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { bindReporter } from './lib/bindReporter.js';
|
|
2
|
-
import { getActivationStart } from './lib/getActivationStart.js';
|
|
3
|
-
import { getVisibilityWatcher } from './lib/getVisibilityWatcher.js';
|
|
4
|
-
import { addPageListener, removePageListener } from './lib/globalListeners.js';
|
|
5
|
-
import { initMetric } from './lib/initMetric.js';
|
|
6
|
-
import { initUnique } from './lib/initUnique.js';
|
|
7
|
-
import { LCPEntryManager } from './lib/LCPEntryManager.js';
|
|
8
|
-
import { observe } from './lib/observe.js';
|
|
9
|
-
import { runOnce } from './lib/runOnce.js';
|
|
10
|
-
import { whenActivated } from './lib/whenActivated.js';
|
|
11
|
-
import { whenIdleOrHidden } from './lib/whenIdleOrHidden.js';
|
|
12
|
-
|
|
13
|
-
const LCPThresholds = [2500, 4e3];
|
|
14
|
-
const onLCP = (onReport, opts = {}) => {
|
|
15
|
-
whenActivated(() => {
|
|
16
|
-
const visibilityWatcher = getVisibilityWatcher();
|
|
17
|
-
const metric = initMetric("LCP");
|
|
18
|
-
let report;
|
|
19
|
-
const lcpEntryManager = initUnique(opts, LCPEntryManager);
|
|
20
|
-
const handleEntries = (entries) => {
|
|
21
|
-
if (!opts.reportAllChanges) {
|
|
22
|
-
entries = entries.slice(-1);
|
|
23
|
-
}
|
|
24
|
-
for (const entry of entries) {
|
|
25
|
-
lcpEntryManager._processEntry(entry);
|
|
26
|
-
if (entry.startTime < visibilityWatcher.firstHiddenTime) {
|
|
27
|
-
metric.value = Math.max(entry.startTime - getActivationStart(), 0);
|
|
28
|
-
metric.entries = [entry];
|
|
29
|
-
report();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const po = observe("largest-contentful-paint", handleEntries);
|
|
34
|
-
if (po) {
|
|
35
|
-
report = bindReporter(onReport, metric, LCPThresholds, opts.reportAllChanges);
|
|
36
|
-
const stopListening = runOnce(() => {
|
|
37
|
-
handleEntries(po.takeRecords());
|
|
38
|
-
po.disconnect();
|
|
39
|
-
report(true);
|
|
40
|
-
});
|
|
41
|
-
const stopListeningWrapper = (event) => {
|
|
42
|
-
if (event.isTrusted) {
|
|
43
|
-
whenIdleOrHidden(stopListening);
|
|
44
|
-
removePageListener(event.type, stopListeningWrapper, {
|
|
45
|
-
capture: true
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
for (const type of ["keydown", "click", "visibilitychange"]) {
|
|
50
|
-
addPageListener(type, stopListeningWrapper, {
|
|
51
|
-
capture: true
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { LCPThresholds, onLCP };
|
|
59
|
-
//# sourceMappingURL=getLCP.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getLCP.js","sources":["../../../../src/metrics/web-vitals/getLCP.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { bindReporter } from './lib/bindReporter';\nimport { getActivationStart } from './lib/getActivationStart';\nimport { getVisibilityWatcher } from './lib/getVisibilityWatcher';\nimport { addPageListener, removePageListener } from './lib/globalListeners';\nimport { initMetric } from './lib/initMetric';\nimport { initUnique } from './lib/initUnique';\nimport { LCPEntryManager } from './lib/LCPEntryManager';\nimport { observe } from './lib/observe';\nimport { runOnce } from './lib/runOnce';\nimport { whenActivated } from './lib/whenActivated';\nimport { whenIdleOrHidden } from './lib/whenIdleOrHidden';\nimport type { LCPMetric, MetricRatingThresholds, ReportOpts } from './types';\n\n/** Thresholds for LCP. See https://web.dev/articles/lcp#what_is_a_good_lcp_score */\nexport const LCPThresholds: MetricRatingThresholds = [2500, 4000];\n\n/**\n * Calculates the [LCP](https://web.dev/articles/lcp) value for the current page and\n * calls the `callback` function once the value is ready (along with the\n * relevant `largest-contentful-paint` performance entry used to determine the\n * value). The reported value is a `DOMHighResTimeStamp`.\n *\n * If the `reportAllChanges` configuration option is set to `true`, the\n * `callback` function will be called any time a new `largest-contentful-paint`\n * performance entry is dispatched, or once the final value of the metric has\n * been determined.\n */\nexport const onLCP = (onReport: (metric: LCPMetric) => void, opts: ReportOpts = {}) => {\n whenActivated(() => {\n const visibilityWatcher = getVisibilityWatcher();\n const metric = initMetric('LCP');\n let report: ReturnType<typeof bindReporter>;\n\n const lcpEntryManager = initUnique(opts, LCPEntryManager);\n\n const handleEntries = (entries: LCPMetric['entries']) => {\n // If reportAllChanges is set then call this function for each entry,\n // otherwise only consider the last one.\n if (!opts.reportAllChanges) {\n // eslint-disable-next-line no-param-reassign\n entries = entries.slice(-1);\n }\n\n for (const entry of entries) {\n lcpEntryManager._processEntry(entry);\n\n // Only report if the page wasn't hidden prior to LCP.\n if (entry.startTime < visibilityWatcher.firstHiddenTime) {\n // The startTime attribute returns the value of the renderTime if it is\n // not 0, and the value of the loadTime otherwise. The activationStart\n // reference is used because LCP should be relative to page activation\n // rather than navigation start if the page was prerendered. But in cases\n // where `activationStart` occurs after the LCP, this time should be\n // clamped at 0.\n metric.value = Math.max(entry.startTime - getActivationStart(), 0);\n metric.entries = [entry];\n report();\n }\n }\n };\n\n const po = observe('largest-contentful-paint', handleEntries);\n\n if (po) {\n report = bindReporter(onReport, metric, LCPThresholds, opts.reportAllChanges);\n\n // Ensure this logic only runs once, since it can be triggered from\n // any of three different event listeners below.\n const stopListening = runOnce(() => {\n handleEntries(po.takeRecords() as LCPMetric['entries']);\n po.disconnect();\n report(true);\n });\n\n // Need a separate wrapper to ensure the `runOnce` function above is\n // common for all three functions\n const stopListeningWrapper = (event: Event) => {\n if (event.isTrusted) {\n // Wrap the listener in an idle callback so it's run in a separate\n // task to reduce potential INP impact.\n // https://github.com/GoogleChrome/web-vitals/issues/383\n whenIdleOrHidden(stopListening);\n removePageListener(event.type, stopListeningWrapper, {\n capture: true,\n });\n }\n };\n\n // Stop listening after input or visibilitychange.\n // Note: while scrolling is an input that stops LCP observation, it's\n // unreliable since it can be programmatically generated.\n // See: https://github.com/GoogleChrome/web-vitals/issues/75\n for (const type of ['keydown', 'click', 'visibilitychange']) {\n addPageListener(type, stopListeningWrapper, {\n capture: true,\n });\n }\n }\n });\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA8B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AAA,MACb,CAAC,CAAA;AAID,MAAA,MAAM,oBAAA,GAAuB,CAAC,KAAA,KAAiB;AAC7C,QAAA,IAAI,MAAM,SAAA,EAAW;AAInB,UAAA,gBAAA,CAAiB,aAAa,CAAA;AAC9B,UAAA,kBAAA,CAAmB,KAAA,CAAM,MAAM,oBAAA,EAAsB;AAAA,YACnD,OAAA,EAAS;AAAA,WACV,CAAA;AAAA,QACH;AAAA,MACF,CAAA;AAMA,MAAA,KAAA,MAAW,IAAA,IAAQ,CAAC,SAAA,EAAW,OAAA,EAAS,kBAAkB,CAAA,EAAG;AAC3D,QAAA,eAAA,CAAgB,MAAM,oBAAA,EAAsB;AAAA,UAC1C,OAAA,EAAS;AAAA,SACV,CAAA;AAAA,MACH;AAAA,IACF;AAAA,EACF,CAAC,CAAA;AACH;;;;"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { getInteractionCount } from './polyfills/interactionCountPolyfill.js';
|
|
2
|
-
|
|
3
|
-
const MAX_INTERACTIONS_TO_CONSIDER = 10;
|
|
4
|
-
let prevInteractionCount = 0;
|
|
5
|
-
const getInteractionCountForNavigation = () => {
|
|
6
|
-
return getInteractionCount() - prevInteractionCount;
|
|
7
|
-
};
|
|
8
|
-
class InteractionManager {
|
|
9
|
-
constructor() {
|
|
10
|
-
/**
|
|
11
|
-
* A list of longest interactions on the page (by latency) sorted so the
|
|
12
|
-
* longest one is first. The list is at most MAX_INTERACTIONS_TO_CONSIDER
|
|
13
|
-
* long.
|
|
14
|
-
*/
|
|
15
|
-
// oxlint-disable-next-line sdk/no-class-field-initializers
|
|
16
|
-
this._longestInteractionList = [];
|
|
17
|
-
/**
|
|
18
|
-
* A mapping of longest interactions by their interaction ID.
|
|
19
|
-
* This is used for faster lookup.
|
|
20
|
-
*/
|
|
21
|
-
// oxlint-disable-next-line sdk/no-class-field-initializers
|
|
22
|
-
this._longestInteractionMap = /* @__PURE__ */ new Map();
|
|
23
|
-
}
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility, jsdoc/require-jsdoc
|
|
25
|
-
_resetInteractions() {
|
|
26
|
-
prevInteractionCount = getInteractionCount();
|
|
27
|
-
this._longestInteractionList.length = 0;
|
|
28
|
-
this._longestInteractionMap.clear();
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns the estimated p98 longest interaction based on the stored
|
|
32
|
-
* interaction candidates and the interaction count for the current page.
|
|
33
|
-
*/
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
|
|
35
|
-
_estimateP98LongestInteraction() {
|
|
36
|
-
const candidateInteractionIndex = Math.min(
|
|
37
|
-
this._longestInteractionList.length - 1,
|
|
38
|
-
Math.floor(getInteractionCountForNavigation() / 50)
|
|
39
|
-
);
|
|
40
|
-
return this._longestInteractionList[candidateInteractionIndex];
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Takes a performance entry and adds it to the list of worst interactions
|
|
44
|
-
* if its duration is long enough to make it among the worst. If the
|
|
45
|
-
* entry is part of an existing interaction, it is merged and the latency
|
|
46
|
-
* and entries list is updated as needed.
|
|
47
|
-
*/
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
|
|
49
|
-
_processEntry(entry) {
|
|
50
|
-
this._onBeforeProcessingEntry?.(entry);
|
|
51
|
-
if (!(entry.interactionId || entry.entryType === "first-input")) return;
|
|
52
|
-
const minLongestInteraction = this._longestInteractionList.at(-1);
|
|
53
|
-
let interaction = this._longestInteractionMap.get(entry.interactionId);
|
|
54
|
-
if (interaction || this._longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER || // If the above conditions are false, `minLongestInteraction` will be set.
|
|
55
|
-
entry.duration > minLongestInteraction._latency) {
|
|
56
|
-
if (interaction) {
|
|
57
|
-
if (entry.duration > interaction._latency) {
|
|
58
|
-
interaction.entries = [entry];
|
|
59
|
-
interaction._latency = entry.duration;
|
|
60
|
-
} else if (entry.duration === interaction._latency && entry.startTime === interaction.entries[0].startTime) {
|
|
61
|
-
interaction.entries.push(entry);
|
|
62
|
-
}
|
|
63
|
-
} else {
|
|
64
|
-
interaction = {
|
|
65
|
-
id: entry.interactionId,
|
|
66
|
-
entries: [entry],
|
|
67
|
-
_latency: entry.duration
|
|
68
|
-
};
|
|
69
|
-
this._longestInteractionMap.set(interaction.id, interaction);
|
|
70
|
-
this._longestInteractionList.push(interaction);
|
|
71
|
-
}
|
|
72
|
-
this._longestInteractionList.sort((a, b) => b._latency - a._latency);
|
|
73
|
-
if (this._longestInteractionList.length > MAX_INTERACTIONS_TO_CONSIDER) {
|
|
74
|
-
const removedInteractions = this._longestInteractionList.splice(MAX_INTERACTIONS_TO_CONSIDER);
|
|
75
|
-
for (const interaction2 of removedInteractions) {
|
|
76
|
-
this._longestInteractionMap.delete(interaction2.id);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
this._onAfterProcessingINPCandidate?.(interaction);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export { InteractionManager };
|
|
85
|
-
//# sourceMappingURL=InteractionManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"InteractionManager.js","sources":["../../../../../src/metrics/web-vitals/lib/InteractionManager.ts"],"sourcesContent":["/*\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getInteractionCount } from './polyfills/interactionCountPolyfill.js';\n\nexport interface Interaction {\n _latency: number;\n // While the `id` and `entries` properties are also internal and could be\n // mangled by prefixing with an underscore, since they correspond to public\n // symbols there is no need to mangle them as the library will compress\n // better if we reuse the existing names.\n id: number;\n entries: PerformanceEventTiming[];\n}\n\n// To prevent unnecessary memory usage on pages with lots of interactions,\n// store at most 10 of the longest interactions to consider as INP candidates.\nconst MAX_INTERACTIONS_TO_CONSIDER = 10;\n\n// Used to store the interaction count after a bfcache restore, since p98\n// interaction latencies should only consider the current navigation.\nlet prevInteractionCount = 0;\n\n/**\n * Returns the interaction count since the last bfcache restore (or for the\n * full page lifecycle if there were no bfcache restores).\n */\nconst getInteractionCountForNavigation = () => {\n return getInteractionCount() - prevInteractionCount;\n};\n\n/**\n *\n */\nexport class InteractionManager {\n /**\n * A list of longest interactions on the page (by latency) sorted so the\n * longest one is first. The list is at most MAX_INTERACTIONS_TO_CONSIDER\n * long.\n */\n // oxlint-disable-next-line sdk/no-class-field-initializers\n _longestInteractionList: Interaction[] = [];\n\n /**\n * A mapping of longest interactions by their interaction ID.\n * This is used for faster lookup.\n */\n // oxlint-disable-next-line sdk/no-class-field-initializers\n _longestInteractionMap: Map<number, Interaction> = new Map();\n\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _onBeforeProcessingEntry?: (entry: PerformanceEventTiming) => void;\n\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _onAfterProcessingINPCandidate?: (interaction: Interaction) => void;\n\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility, jsdoc/require-jsdoc\n _resetInteractions() {\n prevInteractionCount = getInteractionCount();\n this._longestInteractionList.length = 0;\n this._longestInteractionMap.clear();\n }\n\n /**\n * Returns the estimated p98 longest interaction based on the stored\n * interaction candidates and the interaction count for the current page.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _estimateP98LongestInteraction() {\n const candidateInteractionIndex = Math.min(\n this._longestInteractionList.length - 1,\n Math.floor(getInteractionCountForNavigation() / 50),\n );\n\n return this._longestInteractionList[candidateInteractionIndex];\n }\n\n /**\n * Takes a performance entry and adds it to the list of worst interactions\n * if its duration is long enough to make it among the worst. If the\n * entry is part of an existing interaction, it is merged and the latency\n * and entries list is updated as needed.\n */\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _processEntry(entry: PerformanceEventTiming) {\n this._onBeforeProcessingEntry?.(entry);\n\n // Skip further processing for entries that cannot be INP candidates.\n if (!(entry.interactionId || entry.entryType === 'first-input')) return;\n\n // The least-long of the 10 longest interactions.\n const minLongestInteraction = this._longestInteractionList.at(-1);\n\n let interaction = this._longestInteractionMap.get(entry.interactionId);\n\n // Only process the entry if it's possibly one of the ten longest,\n // or if it's part of an existing interaction.\n if (\n interaction ||\n this._longestInteractionList.length < MAX_INTERACTIONS_TO_CONSIDER ||\n // If the above conditions are false, `minLongestInteraction` will be set.\n entry.duration > minLongestInteraction!._latency\n ) {\n // If the interaction already exists, update it. Otherwise create one.\n if (interaction) {\n // If the new entry has a longer duration, replace the old entries,\n // otherwise add to the array.\n if (entry.duration > interaction._latency) {\n interaction.entries = [entry];\n interaction._latency = entry.duration;\n } else if (entry.duration === interaction._latency && entry.startTime === interaction.entries[0]!.startTime) {\n interaction.entries.push(entry);\n }\n } else {\n interaction = {\n id: entry.interactionId,\n entries: [entry],\n _latency: entry.duration,\n };\n this._longestInteractionMap.set(interaction.id, interaction);\n this._longestInteractionList.push(interaction);\n }\n\n // Sort the entries by latency (descending) and keep only the top ten.\n this._longestInteractionList.sort((a, b) => b._latency - a._latency);\n if (this._longestInteractionList.length > MAX_INTERACTIONS_TO_CONSIDER) {\n const removedInteractions = this._longestInteractionList.splice(MAX_INTERACTIONS_TO_CONSIDER);\n\n for (const interaction of removedInteractions) {\n this._longestInteractionMap.delete(interaction.id);\n }\n }\n\n // Call any post-processing on the interaction\n this._onAfterProcessingINPCandidate?.(interaction);\n }\n }\n}\n"],"names":["interaction"],"mappings":";;AA8BA,MAAM,4BAAA,GAA+B,EAAA;AAIrC,IAAI,oBAAA,GAAuB,CAAA;AAM3B,MAAM,mCAAmC,MAAM;AAC7C,EAAA,OAAO,qBAAoB,GAAI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AA,EACF;AACF;;;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
class LCPEntryManager {
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility, jsdoc/require-jsdoc
|
|
3
|
-
_processEntry(entry) {
|
|
4
|
-
this._onBeforeProcessingEntry?.(entry);
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { LCPEntryManager };
|
|
9
|
-
//# sourceMappingURL=LCPEntryManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LCPEntryManager.js","sources":["../../../../../src/metrics/web-vitals/lib/LCPEntryManager.ts"],"sourcesContent":["/*\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// eslint-disable-next-line jsdoc/require-jsdoc\nexport class LCPEntryManager {\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _onBeforeProcessingEntry?: (entry: LargestContentfulPaint) => void;\n\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility, jsdoc/require-jsdoc\n _processEntry(entry: LargestContentfulPaint) {\n this._onBeforeProcessingEntry?.(entry);\n }\n}\n"],"names":[],"mappings":"AAiBO,MAAM,eAAA,CAAgB;AAAA;AAAA,EAK3B,cAAc,KAAA,EAA+B;AAC3C,IAAA,IAAA,CAAK,2BAA2B,KAAK,CAAA;AAAA,EACvC;AACF;;;;"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
class LayoutShiftManager {
|
|
2
|
-
constructor() {
|
|
3
|
-
// oxlint-disable-next-line sdk/no-class-field-initializers
|
|
4
|
-
this._sessionValue = 0;
|
|
5
|
-
// oxlint-disable-next-line sdk/no-class-field-initializers
|
|
6
|
-
this._sessionEntries = [];
|
|
7
|
-
}
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
|
|
9
|
-
_processEntry(entry) {
|
|
10
|
-
if (entry.hadRecentInput) return;
|
|
11
|
-
const firstSessionEntry = this._sessionEntries[0];
|
|
12
|
-
const lastSessionEntry = this._sessionEntries[this._sessionEntries.length - 1];
|
|
13
|
-
if (this._sessionValue && firstSessionEntry && lastSessionEntry && entry.startTime - lastSessionEntry.startTime < 1e3 && entry.startTime - firstSessionEntry.startTime < 5e3) {
|
|
14
|
-
this._sessionValue += entry.value;
|
|
15
|
-
this._sessionEntries.push(entry);
|
|
16
|
-
} else {
|
|
17
|
-
this._sessionValue = entry.value;
|
|
18
|
-
this._sessionEntries = [entry];
|
|
19
|
-
}
|
|
20
|
-
this._onAfterProcessingUnexpectedShift?.(entry);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { LayoutShiftManager };
|
|
25
|
-
//# sourceMappingURL=LayoutShiftManager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LayoutShiftManager.js","sources":["../../../../../src/metrics/web-vitals/lib/LayoutShiftManager.ts"],"sourcesContent":["/* eslint-disable jsdoc/require-jsdoc */\n/*\n * Copyright 2024 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport class LayoutShiftManager {\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _onAfterProcessingUnexpectedShift?: (entry: LayoutShift) => void;\n\n // oxlint-disable-next-line sdk/no-class-field-initializers\n _sessionValue = 0;\n // oxlint-disable-next-line sdk/no-class-field-initializers\n _sessionEntries: LayoutShift[] = [];\n\n // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility\n _processEntry(entry: LayoutShift) {\n // Only count layout shifts without recent user input.\n if (entry.hadRecentInput) return;\n\n const firstSessionEntry = this._sessionEntries[0];\n // This previously used `this._sessionEntries.at(-1)` but that is ES2022. We support ES2021 and earlier.\n const lastSessionEntry = this._sessionEntries[this._sessionEntries.length - 1];\n\n // If the entry occurred less than 1 second after the previous entry\n // and less than 5 seconds after the first entry in the session,\n // include the entry in the current session. Otherwise, start a new\n // session.\n if (\n this._sessionValue &&\n firstSessionEntry &&\n lastSessionEntry &&\n entry.startTime - lastSessionEntry.startTime < 1000 &&\n entry.startTime - firstSessionEntry.startTime < 5000\n ) {\n this._sessionValue += entry.value;\n this._sessionEntries.push(entry);\n } else {\n this._sessionValue = entry.value;\n this._sessionEntries = [entry];\n }\n\n this._onAfterProcessingUnexpectedShift?.(entry);\n }\n}\n"],"names":[],"mappings":"AAiBO,MAAM,kBAAA,CAAmB;AAAA,EAAzB,WAAA,GAAA;AAKL;AAAA,IAAA,IAAA,CAAA,aAAA,GAAgB,CAAA;AAEhB;AAAA,IAAA,IAAA,CAAA,eAAA,GAAiC,EAAC;AAAA,EAAA;AAAA;AAAA,EAGlC,cAAc,KAAA,EAAoB;AAEhC,IAAA,IAAI,MAAM,cAAA,EAAgB;AAE1B,IAAA,MAAM,iBAAA,GAAoB,IAAA,CAAK,eAAA,CAAgB,CAAC,CAAA;AAEhD,IAAA,MAAM,mBAAmB,IAAA,CAAK,eAAA,CAAgB,IAAA,CAAK,eAAA,CAAgB,SAAS,CAAC,CAAA;AAM7E,IAAA,IACE,IAAA,CAAK,aAAA,IACL,iBAAA,IACA,gBAAA,IACA,KAAA,CAAM,SAAA,GAAY,gBAAA,CAAiB,SAAA,GAAY,GAAA,IAC/C,KAAA,CAAM,SAAA,GAAY,iBAAA,CAAkB,YAAY,GAAA,EAChD;AACA,MAAA,IAAA,CAAK,iBAAiB,KAAA,CAAM,KAAA;AAC5B,MAAA,IAAA,CAAK,eAAA,CAAgB,KAAK,KAAK,CAAA;AAAA,IACjC,CAAA,MAAO;AACL,MAAA,IAAA,CAAK,gBAAgB,KAAA,CAAM,KAAA;AAC3B,MAAA,IAAA,CAAK,eAAA,GAAkB,CAAC,KAAK,CAAA;AAAA,IAC/B;AAEA,IAAA,IAAA,CAAK,oCAAoC,KAAK,CAAA;AAAA,EAChD;AACF;;;;"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const getRating = (value, thresholds) => {
|
|
2
|
-
if (value > thresholds[1]) {
|
|
3
|
-
return "poor";
|
|
4
|
-
}
|
|
5
|
-
if (value > thresholds[0]) {
|
|
6
|
-
return "needs-improvement";
|
|
7
|
-
}
|
|
8
|
-
return "good";
|
|
9
|
-
};
|
|
10
|
-
const bindReporter = (callback, metric, thresholds, reportAllChanges) => {
|
|
11
|
-
let prevValue;
|
|
12
|
-
let delta;
|
|
13
|
-
return (forceReport) => {
|
|
14
|
-
if (metric.value >= 0) {
|
|
15
|
-
if (forceReport || reportAllChanges) {
|
|
16
|
-
delta = metric.value - (prevValue ?? 0);
|
|
17
|
-
if (delta || prevValue === void 0) {
|
|
18
|
-
prevValue = metric.value;
|
|
19
|
-
metric.delta = delta;
|
|
20
|
-
metric.rating = getRating(metric.value, thresholds);
|
|
21
|
-
callback(metric);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { bindReporter };
|
|
29
|
-
//# sourceMappingURL=bindReporter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bindReporter.js","sources":["../../../../../src/metrics/web-vitals/lib/bindReporter.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { MetricRatingThresholds, MetricType } from '../types';\n\nconst getRating = (value: number, thresholds: MetricRatingThresholds): MetricType['rating'] => {\n if (value > thresholds[1]) {\n return 'poor';\n }\n if (value > thresholds[0]) {\n return 'needs-improvement';\n }\n return 'good';\n};\n\nexport const bindReporter = <MetricName extends MetricType['name']>(\n callback: (metric: Extract<MetricType, { name: MetricName }>) => void,\n metric: Extract<MetricType, { name: MetricName }>,\n thresholds: MetricRatingThresholds,\n reportAllChanges?: boolean,\n) => {\n let prevValue: number;\n let delta: number;\n return (forceReport?: boolean) => {\n if (metric.value >= 0) {\n if (forceReport || reportAllChanges) {\n delta = metric.value - (prevValue ?? 0);\n\n // Report the metric if there's a non-zero delta or if no previous\n // value exists (which can happen in the case of the document becoming\n // hidden when the metric value is 0).\n // See: https://github.com/GoogleChrome/web-vitals/issues/14\n if (delta || prevValue === undefined) {\n prevValue = metric.value;\n metric.delta = delta;\n metric.rating = getRating(metric.value, thresholds);\n callback(metric);\n }\n }\n }\n };\n};\n"],"names":[],"mappings":"AAkBA,MAAM,SAAA,GAAY,CAAC,KAAA,EAAe,UAAA,KAA6D;AAC7F,EAAA,IAAI,KAAA,GAAQ,UAAA,CAAW,CAAC,CAAA,EAAG;AACzB,IAAA,OAAO,MAAA;AAAA,EACT;AACA,EAAA,IAAI,KAAA,GAAQ,UAAA,CAAW,CAAC,CAAA,EAAG;AACzB,IAAA,OAAO,mBAAA;AAAA,EACT;AACA,EAAA,OAAO,MAAA;AACT,CAAA;AAEO,MAAM,YAAA,GAAe,CAC1B,QAAA,EACA,MAAA,EACA,YACA,gBAAA,KACG;AACH,EAAA,IAAI,SAAA;AACJ,EAAA,IAAI,KAAA;AACJ,EAAA,OAAO,CAAC,WAAA,KAA0B;AAChC,IAAA,IAAI,MAAA,CAAO,SAAS,CAAA,EAAG;AACrB,MAAA,IAAI,eAAe,gBAAA,EAAkB;AACnC,QAAA,KAAA,GAAQ,MAAA,CAAO,SAAS,SAAA,IAAa,CAAA,CAAA;AAMrC,QAAA,IAAI,KAAA,IAAS,cAAc,MAAA,EAAW;AACpC,UAAA,SAAA,GAAY,MAAA,CAAO,KAAA;AACnB,UAAA,MAAA,CAAO,KAAA,GAAQ,KAAA;AACf,UAAA,MAAA,CAAO,MAAA,GAAS,SAAA,CAAU,MAAA,CAAO,KAAA,EAAO,UAAU,CAAA;AAClD,UAAA,QAAA,CAAS,MAAM,CAAA;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAA;AACF;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateUniqueID.js","sources":["../../../../../src/metrics/web-vitals/lib/generateUniqueID.ts"],"sourcesContent":["/*\n * Copyright 2020 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Performantly generate a unique, 30-char string by combining a version\n * number, the current timestamp with a 13-digit number integer.\n * @return {string}\n */\nexport const generateUniqueID = () => {\n return `v5-${Date.now()}-${Math.floor(Math.random() * (9e12 - 1)) + 1e12}`;\n};\n"],"names":[],"mappings":"AAqBO,MAAM,mBAAmB,MAAM;AACpC,EAAA,OAAO,CAAA,GAAA,EAAM,IAAA,CAAK,GAAA,EAAK,CAAA,CAAA,EAAI,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,MAAA,EAAO,IAAK,IAAA,GAAO,CAAA,CAAE,IAAI,IAAI,CAAA,CAAA;AAC1E;;;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { getNavigationEntry } from './getNavigationEntry.js';
|
|
2
|
-
|
|
3
|
-
const getActivationStart = () => {
|
|
4
|
-
const navEntry = getNavigationEntry();
|
|
5
|
-
return navEntry?.activationStart ?? 0;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export { getActivationStart };
|
|
9
|
-
//# sourceMappingURL=getActivationStart.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getActivationStart.js","sources":["../../../../../src/metrics/web-vitals/lib/getActivationStart.ts"],"sourcesContent":["/*\n * Copyright 2022 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getNavigationEntry } from './getNavigationEntry';\n\nexport const getActivationStart = (): number => {\n const navEntry = getNavigationEntry();\n return navEntry?.activationStart ?? 0;\n};\n"],"names":[],"mappings":";;AAkBO,MAAM,qBAAqB,MAAc;AAC9C,EAAA,MAAM,WAAW,kBAAA,EAAmB;AACpC,EAAA,OAAO,UAAU,eAAA,IAAmB,CAAA;AACtC;;;;"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { WINDOW } from '../../../types.js';
|
|
2
|
-
|
|
3
|
-
const getNavigationEntry = (checkResponseStart = true) => {
|
|
4
|
-
const navigationEntry = WINDOW.performance?.getEntriesByType?.("navigation")[0];
|
|
5
|
-
if (
|
|
6
|
-
// sentry-specific change:
|
|
7
|
-
// We don't want to check for responseStart for our own use of `getNavigationEntry`
|
|
8
|
-
!checkResponseStart || navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now()
|
|
9
|
-
) {
|
|
10
|
-
return navigationEntry;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export { getNavigationEntry };
|
|
15
|
-
//# sourceMappingURL=getNavigationEntry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getNavigationEntry.js","sources":["../../../../../src/metrics/web-vitals/lib/getNavigationEntry.ts"],"sourcesContent":["/*\n * Copyright 2022 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { WINDOW } from '../../../types';\n\n// sentry-specific change:\n// add optional param to not check for responseStart (see comment below)\nexport const getNavigationEntry = (checkResponseStart = true): PerformanceNavigationTiming | void => {\n const navigationEntry = WINDOW.performance?.getEntriesByType?.('navigation')[0];\n // Check to ensure the `responseStart` property is present and valid.\n // In some cases a zero value is reported by the browser (for\n // privacy/security reasons), and in other cases (bugs) the value is\n // negative or is larger than the current page time. Ignore these cases:\n // - https://github.com/GoogleChrome/web-vitals/issues/137\n // - https://github.com/GoogleChrome/web-vitals/issues/162\n // - https://github.com/GoogleChrome/web-vitals/issues/275\n if (\n // sentry-specific change:\n // We don't want to check for responseStart for our own use of `getNavigationEntry`\n !checkResponseStart ||\n (navigationEntry && navigationEntry.responseStart > 0 && navigationEntry.responseStart < performance.now())\n ) {\n return navigationEntry;\n }\n};\n"],"names":[],"mappings":";;AAoBO,MAAM,kBAAA,GAAqB,CAAC,kBAAA,GAAqB,IAAA,KAA6C;AACnG,EAAA,MAAM,kBAAkB,MAAA,CAAO,WAAA,EAAa,gBAAA,GAAmB,YAAY,EAAE,CAAC,CAAA;AAQ9E,EAAA;AAAA;AAAA;AAAA,IAGE,CAAC,sBACA,eAAA,IAAmB,eAAA,CAAgB,gBAAgB,CAAA,IAAK,eAAA,CAAgB,aAAA,GAAgB,WAAA,CAAY,GAAA;AAAI,IACzG;AACA,IAAA,OAAO,eAAA;AAAA,EACT;AACF;;;;"}
|