From 070adc1e1a64090fd2b8f5756ba498ec3442483b Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Tue, 23 Jan 2024 10:02:48 +0100 Subject: [PATCH 1/2] fix(snaptshot): Ensure `attr.name` is defined when collecting element attributes --- packages/rrweb-snapshot/src/snapshot.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 67583f8555..334cf44a5a 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -740,7 +740,7 @@ function serializeTextNode( unmaskTextSelector, isInputMasked, ), - element: n as unknown as HTMLElement, + element: (n as unknown) as HTMLElement, value: textContent, maskInputFn, }); @@ -813,7 +813,9 @@ function serializeElementNode( const len = n.attributes.length; for (let i = 0; i < len; i++) { const attr = n.attributes[i]; - if (!ignoreAttribute(tagName, attr.name, attr.value)) { + // Looks like `attr.name` can be undefined although the types say differently + // see: https://github.com/getsentry/sentry-javascript/issues/10292 + if (attr.name && !ignoreAttribute(tagName, attr.name, attr.value)) { attributes[attr.name] = transformAttribute( doc, tagName, From 941df56410111924db8226791a155716ee8974d2 Mon Sep 17 00:00:00 2001 From: Lms24 Date: Tue, 23 Jan 2024 09:05:41 +0000 Subject: [PATCH 2/2] Apply formatting changes --- packages/rrweb-snapshot/src/snapshot.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 334cf44a5a..04a7383c16 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -740,7 +740,7 @@ function serializeTextNode( unmaskTextSelector, isInputMasked, ), - element: (n as unknown) as HTMLElement, + element: n as unknown as HTMLElement, value: textContent, maskInputFn, });