Skip to content

Commit 61094d4

Browse files
committed
Check if HTMLElement exists first
1 parent 5bc6f96 commit 61094d4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

packages/utils/src/browser.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,12 @@ function _htmlElementAsString(el: unknown, keyAttrs?: string[]): string {
8686
return '';
8787
}
8888

89-
// If using the component name annotation plugin, this value may be available on the DOM node
90-
if (elem instanceof HTMLElement && elem.dataset && elem.dataset['sentryComponent']) {
91-
return elem.dataset['sentryComponent'];
89+
// @ts-expect-error WINDOW has HTMLElement
90+
if (WINDOW.HTMLElement) {
91+
// If using the component name annotation plugin, this value may be available on the DOM node
92+
if (elem instanceof HTMLElement && elem.dataset && elem.dataset['sentryComponent']) {
93+
return elem.dataset['sentryComponent'];
94+
}
9295
}
9396

9497
out.push(elem.tagName.toLowerCase());
@@ -171,6 +174,11 @@ export function getDomElement<E = any>(selector: string): E | null {
171174
* @returns a string representation of the component for the provided DOM element, or `null` if not found
172175
*/
173176
export function getComponentName(elem: unknown): string | null {
177+
// @ts-expect-error WINDOW has HTMLElement
178+
if (!WINDOW.HTMLElement) {
179+
return null;
180+
}
181+
174182
let currentElem = elem as SimpleNode;
175183
const MAX_TRAVERSE_HEIGHT = 5;
176184
for (let i = 0; i < MAX_TRAVERSE_HEIGHT; i++) {

0 commit comments

Comments
 (0)