Skip to content

Commit b8570e7

Browse files
committed
better sentry-specific comments, add guard for window.document
1 parent 55d5ac7 commit b8570e7

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

packages/browser-utils/src/metrics/web-vitals/getLCP.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { WINDOW } from '../../types';
1718
import { bindReporter } from './lib/bindReporter';
1819
import { getActivationStart } from './lib/getActivationStart';
1920
import { getVisibilityWatcher } from './lib/getVisibilityWatcher';
@@ -92,10 +93,12 @@ export const onLCP = (onReport: (metric: LCPMetric) => void, opts: ReportOpts =
9293
// Wrap in a setTimeout so the callback is run in a separate task
9394
// to avoid extending the keyboard/click handler to reduce INP impact
9495
// https://github.com/GoogleChrome/web-vitals/issues/383
95-
addEventListener(type, () => whenIdle(stopListening as () => void), {
96-
once: true,
97-
capture: true,
98-
});
96+
if (WINDOW.document) {
97+
addEventListener(type, () => whenIdle(stopListening as () => void), {
98+
once: true,
99+
capture: true,
100+
});
101+
}
99102
});
100103

101104
onHidden(stopListening);

packages/browser-utils/src/metrics/web-vitals/lib/observe.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@
1616

1717
interface PerformanceEntryMap {
1818
event: PerformanceEventTiming[];
19-
paint: PerformancePaintTiming[];
2019
'first-input': PerformanceEventTiming[];
2120
'layout-shift': LayoutShift[];
2221
'largest-contentful-paint': LargestContentfulPaint[];
2322
'long-animation-frame': PerformanceLongAnimationFrameTiming[];
23+
paint: PerformancePaintTiming[];
2424
navigation: PerformanceNavigationTiming[];
2525
resource: PerformanceResourceTiming[];
26+
// Sentry-specific change:
27+
// We add longtask as a supported entry type as we use this in
28+
// our `instrumentPerformanceObserver` function also observes 'longtask'
29+
// entries.
2630
longtask: PerformanceEntry[];
2731
}
2832

packages/browser-utils/src/metrics/web-vitals/lib/onHidden.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface OnHiddenCallback {
2020
(event: Event): void;
2121
}
2222

23+
// Sentry-specific change:
2324
// This function's logic was NOT updated to web-vitals 4.2.4 but we continue
2425
// to use the web-vitals 3.5.2 due to us having stricter browser support.
2526
// PR with context that made the changes: https://github.com/GoogleChrome/web-vitals/pull/442/files#r1530492402

0 commit comments

Comments
 (0)