Skip to content

Commit 2bac393

Browse files
committed
fix: check for browser first
1 parent 22cbbef commit 2bac393

File tree

1 file changed

+6
-3
lines changed
  • packages/browser-utils/src/metrics

1 file changed

+6
-3
lines changed

packages/browser-utils/src/metrics/inp.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getCurrentScope,
66
getRootSpan,
77
htmlTreeAsString,
8+
isBrowser,
89
SEMANTIC_ATTRIBUTE_EXCLUSIVE_TIME,
910
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_UNIT,
1011
SEMANTIC_ATTRIBUTE_SENTRY_MEASUREMENT_VALUE,
@@ -160,9 +161,11 @@ export const _onInp: InstrumentationHandlerCallback = ({ metric }) => {
160161
export function registerInpInteractionListener(): void {
161162
// Listen for all interaction events that could contribute to INP
162163
const interactionEvents = Object.keys(INP_ENTRY_MAP);
163-
interactionEvents.forEach(eventType => {
164-
WINDOW.addEventListener(eventType, captureElementFromEvent, { capture: true, passive: true });
165-
});
164+
if (isBrowser()) {
165+
interactionEvents.forEach(eventType => {
166+
WINDOW.addEventListener(eventType, captureElementFromEvent, { capture: true, passive: true });
167+
});
168+
}
166169

167170
/**
168171
* Captures the element name from a DOM event and stores it in the ELEMENT_NAME_TIMESTAMP_MAP.

0 commit comments

Comments
 (0)