-
Notifications
You must be signed in to change notification settings - Fork 10
fix(rrweb): Do not call setAttribute on TEXT nodes #253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Not sure yet how this is happening during recording, but prevent player from calling `setAttribute` on TEXT nodes (which does not have that method). This additionally prevents the player from freezing while trying to process these invalid mutations.
c8e0fc8 to
aba4b9b
Compare
|
@sentry review |
packages/rrweb/src/replay/index.ts
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The guard condition only checks for Text nodes (nodeType !== 3), but other node types such as COMMENT_NODE (8), PROCESSING_INSTRUCTION_NODE (7), or DOCUMENT_FRAGMENT_NODE (11) also lack the setAttribute method. While the immediate issue may only manifest with Text nodes, consider using a more robust check like instanceof Element or typeof target.setAttribute === 'function' to make the code more defensive against future edge cases and document types that might appear during recording.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we record any of those types, so this should suffice
| // prevents calling `setAttribute` on Text nodes (which does not | ||
| // have `setAttribute` method). | ||
| if (target.nodeType !== 3) { | ||
| (target as Element | RRElement).setAttribute( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Sentry suggestion to check typeof target.setAttribute === 'function' seems reasonable instead of going with nodeType=3 no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I want it to be more specific since this shouldn't happen at all. Something seems to be wrong during recording where we are getting the wrong mutations (or the wrong element references for the mutation), so ideally this is just temporary assuming we can repro and fix the recording side.
Not sure yet how this is happening during recording, but prevent player from calling
setAttributeon TEXT nodes (which does not have that method). This additionally prevents the player from freezing while trying to process these invalid mutations.