File tree Expand file tree Collapse file tree 3 files changed +15
-20
lines changed
packages/browser-utils/src/metrics Expand file tree Collapse file tree 3 files changed +15
-20
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717import { DEBUG_BUILD } from '../debug-build' ;
1818import { addClsInstrumentationHandler } from './instrument' ;
1919import type { WebVitalReportEvent } from './utils' ;
20- import { msToSec , startStandaloneWebVitalSpan } from './utils' ;
20+ import { msToSec , startStandaloneWebVitalSpan , supportsWebVital } from './utils' ;
2121import { onHidden } from './web-vitals/lib/onHidden' ;
2222import { runOnce } from './web-vitals/lib/runOnce' ;
2323
@@ -35,7 +35,7 @@ export function trackClsAsStandaloneSpan(): void {
3535 let standaloneClsEntry : LayoutShift | undefined ;
3636 let pageloadSpanId : string | undefined ;
3737
38- if ( ! supportsLayoutShift ( ) ) {
38+ if ( ! supportsWebVital ( 'layout-shift' ) ) {
3939 return ;
4040 }
4141
@@ -139,11 +139,3 @@ function sendStandaloneClsSpan(
139139 span . end ( startTime ) ;
140140 }
141141}
142-
143- function supportsLayoutShift ( ) : boolean {
144- try {
145- return PerformanceObserver . supportedEntryTypes . includes ( 'layout-shift' ) ;
146- } catch {
147- return false ;
148- }
149- }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717import { DEBUG_BUILD } from '../debug-build' ;
1818import { addLcpInstrumentationHandler } from './instrument' ;
1919import type { WebVitalReportEvent } from './utils' ;
20- import { msToSec , startStandaloneWebVitalSpan } from './utils' ;
20+ import { msToSec , startStandaloneWebVitalSpan , supportsWebVital } from './utils' ;
2121import { onHidden } from './web-vitals/lib/onHidden' ;
2222import { runOnce } from './web-vitals/lib/runOnce' ;
2323
@@ -35,7 +35,7 @@ export function trackLcpAsStandaloneSpan(): void {
3535 let standaloneLcpEntry : LargestContentfulPaint | undefined ;
3636 let pageloadSpanId : string | undefined ;
3737
38- if ( ! supportsLargestContentfulPaint ( ) ) {
38+ if ( ! supportsWebVital ( 'largest-contentful-paint' ) ) {
3939 return ;
4040 }
4141
@@ -151,11 +151,3 @@ export function _sendStandaloneLcpSpan(
151151 span . end ( startTime ) ;
152152 }
153153}
154-
155- function supportsLargestContentfulPaint ( ) : boolean {
156- try {
157- return PerformanceObserver . supportedEntryTypes . includes ( 'largest-contentful-paint' ) ;
158- } catch {
159- return false ;
160- }
161- }
Original file line number Diff line number Diff line change @@ -170,3 +170,14 @@ export function extractNetworkProtocol(nextHopProtocol: string): { name: string;
170170 }
171171 return { name, version } ;
172172}
173+
174+ /**
175+ * Generic support check for web vitals
176+ */
177+ export function supportsWebVital ( entryType : 'layout-shift' | 'largest-contentful-paint' ) : boolean {
178+ try {
179+ return PerformanceObserver . supportedEntryTypes . includes ( entryType ) ;
180+ } catch {
181+ return false ;
182+ }
183+ }
You can’t perform that action at this time.
0 commit comments