From e2ecbfedb7e76152363e45d2ac3d79b1fbd497d8 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Thu, 25 Jan 2024 14:00:44 +0100 Subject: [PATCH] fix(snaptshot): Ensure `attr.name` is defined when collecting element attributes (#160) Probably fixes https://github.com/getsentry/sentry-javascript/issues/10292 Not sure how `attr.name` could be undefined here but according to the issue, it happens and we should probably guard adding the attribute. --- packages/rrweb-snapshot/src/snapshot.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 5e981034e0..054446bf58 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -814,7 +814,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,