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 {
17
17
import { DEBUG_BUILD } from '../debug-build' ;
18
18
import { addClsInstrumentationHandler } from './instrument' ;
19
19
import type { WebVitalReportEvent } from './utils' ;
20
- import { msToSec , startStandaloneWebVitalSpan } from './utils' ;
20
+ import { msToSec , startStandaloneWebVitalSpan , supportsWebVital } from './utils' ;
21
21
import { onHidden } from './web-vitals/lib/onHidden' ;
22
22
import { runOnce } from './web-vitals/lib/runOnce' ;
23
23
@@ -35,7 +35,7 @@ export function trackClsAsStandaloneSpan(): void {
35
35
let standaloneClsEntry : LayoutShift | undefined ;
36
36
let pageloadSpanId : string | undefined ;
37
37
38
- if ( ! supportsLayoutShift ( ) ) {
38
+ if ( ! supportsWebVital ( 'layout-shift' ) ) {
39
39
return ;
40
40
}
41
41
@@ -139,11 +139,3 @@ function sendStandaloneClsSpan(
139
139
span . end ( startTime ) ;
140
140
}
141
141
}
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 {
17
17
import { DEBUG_BUILD } from '../debug-build' ;
18
18
import { addLcpInstrumentationHandler } from './instrument' ;
19
19
import type { WebVitalReportEvent } from './utils' ;
20
- import { msToSec , startStandaloneWebVitalSpan } from './utils' ;
20
+ import { msToSec , startStandaloneWebVitalSpan , supportsWebVital } from './utils' ;
21
21
import { onHidden } from './web-vitals/lib/onHidden' ;
22
22
import { runOnce } from './web-vitals/lib/runOnce' ;
23
23
@@ -35,7 +35,7 @@ export function trackLcpAsStandaloneSpan(): void {
35
35
let standaloneLcpEntry : LargestContentfulPaint | undefined ;
36
36
let pageloadSpanId : string | undefined ;
37
37
38
- if ( ! supportsLargestContentfulPaint ( ) ) {
38
+ if ( ! supportsWebVital ( 'largest-contentful-paint' ) ) {
39
39
return ;
40
40
}
41
41
@@ -151,11 +151,3 @@ export function _sendStandaloneLcpSpan(
151
151
span . end ( startTime ) ;
152
152
}
153
153
}
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;
170
170
}
171
171
return { name, version } ;
172
172
}
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