feat(rrweb): attributeFilter option for native MutationObserver filtering (adopt upstream #1873) - #4129
Merged
Conversation
…iltering Port of upstream rrweb #1873. When session_recording.attributeFilter is set, the list is passed through to MutationObserver.observe so mutations to unlisted attributes never fire the observer callback at all - zero recording CPU for e.g. inline-style animation churn. Beyond the upstream diff: the filter is also wired into the shadow-DOM manager's bypassOptions so it applies inside shadow roots (upstream only covered the main document), and an empty array is treated as unset so a bad config value cannot silently disable attribute recording. Off by default; no behaviour change unless configured. Generated-By: PostHog Code Task-Id: b089f2a6-9e07-4abf-aae1-cda53f9d8f56
Contributor
Contributor
posthog-js Compliance ReportDate: 2026-07-11 13:42:25 UTC ✅ All Tests Passed!26/26 tests passed Capture Tests✅ 26/26 tests passed View Details
|
Contributor
|
Size Change: +4.45 kB (+0.03%) Total Size: 17.4 MB
ℹ️ View Unchanged
|
pauldambra
marked this pull request as ready for review
July 11, 2026 15:33
pauldambra
requested review from
a team,
TueHaulund,
arnohillen,
fasyy612 and
ksvat
and removed request for
a team
July 11, 2026 15:33
arnohillen
approved these changes
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Adopts upstream rrweb #1873 (open, reviewed line-by-line before porting), tracked in #3765 — the biggest recording-performance lever in the batch-1 adoption plan.
CSS/JS animations (carousels, sliders, animated badges) generate 1,000+ inline-
styleattribute mutations per second with zero user interaction; on some sites nearly all recorded events are attribute mutations from animations. Today there is no way to stop these before they cost CPU:ignoreCSSAttributesonly intercepts CSSOMsetPropertycalls, and ourMutationThrottlerdrops events after rrweb has already done the expensive serialization work.Changes
session_recording.attributeFilter: string[]— passed straight through to the nativeMutationObserver.observe({ attributeFilter }), so mutations to unlisted attributes never fire the observer callback at all (zero per-mutation CPU, in every frame the observer covers).bypassOptions, so it applies inside shadow roots (upstream only covered the main document — web-component-heavy sites are exactly where animation floods live); same-origin iframes get it via the sharedobserve(doc)pathstyle).Refs #3765.
Release info Sub-libraries affected
Libraries affected
Checklist
packages/rrweb/rrweb/test/record/attribute-filter.test.tscovering main doc, shadow roots, empty-array safety, and that childList/characterData are unaffected; jest test for the config passthrough)If releasing new changes
pnpm changesetto generate a changeset file🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Ported as part of the batch-1 (recording-performance-first) adoption plan on #3765 (PostHog Code session). The upstream PR is from a low-trust author, so the diff was reviewed line-by-line rather than cherry-picked; review found the shadow-DOM gap and the empty-array footgun fixed above. Verified via the existing rrweb record suite (34/34), the new 5-test puppeteer suite, the full lazy-sessionrecording jest suite (240/240), and the types config-snapshot test.
Created with PostHog Code