-
Notifications
You must be signed in to change notification settings - Fork 335
fix(replay): ignore autoplay mutations regardless of tag name case #4837
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
Open
pauldambra
wants to merge
3
commits into
main
Choose a base branch
from
posthog/fix-media-autoplay-attribute-case
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−17
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'posthog-js': patch | ||
| --- | ||
|
|
||
| Stop recording `autoplay` attribute mutations on `<video>` and `<audio>` during session replay. The check compared a lowercase tag name against `Element.tagName`, which is uppercase for HTML elements, so a looping background video emitted a mutation for every `autoplay` toggle. |
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
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
74 changes: 74 additions & 0 deletions
74
packages/rrweb/rrweb/test/record/mutation-attributes.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // @vitest-environment jsdom | ||
| import { Mirror } from '@posthog/rrweb-snapshot'; | ||
| import type { attributeCursor, mutationRecord } from '@posthog/rrweb-types'; | ||
| import MutationBuffer from '../../src/record/mutation'; | ||
|
|
||
| type AttributeProbe = { | ||
| attributes: attributeCursor[]; | ||
| processMutation: (m: mutationRecord) => void; | ||
| }; | ||
|
|
||
| function createProbe() { | ||
| // Exercise the attributes branch without JSDOM's recorder/observer setup. | ||
| // Built-SDK Playwright tests cover the actual buffered payloads. | ||
| const buffer = new MutationBuffer(); | ||
| Object.assign(buffer, { | ||
| blockClass: 'ph-no-capture', | ||
| blockSelector: null, | ||
| doc: document, | ||
| mirror: new Mirror(), | ||
| slimDOMOptions: {}, | ||
| maskInputOptions: {}, | ||
| dataURLOptions: {}, | ||
| keepIframeSrcFn: () => true, | ||
| }); | ||
| return buffer as unknown as AttributeProbe; | ||
| } | ||
|
|
||
| function attributeMutation( | ||
| target: Element, | ||
| attributeName: string, | ||
| ): mutationRecord { | ||
| return { | ||
| type: 'attributes', | ||
| target, | ||
| attributeName, | ||
| attributeNamespace: null, | ||
| oldValue: null, | ||
| } as unknown as mutationRecord; | ||
| } | ||
|
|
||
| function recordedNames(buffer: AttributeProbe): string[] { | ||
| return buffer.attributes.flatMap((item) => Object.keys(item.attributes)); | ||
| } | ||
|
|
||
| function mutate(target: Element, name: string, value: string) { | ||
| const buffer = createProbe(); | ||
| document.body.append(target); | ||
| target.setAttribute(name, value); | ||
| buffer.processMutation(attributeMutation(target, name)); | ||
| return buffer; | ||
| } | ||
|
|
||
| describe('attribute mutations', () => { | ||
| afterEach(() => { | ||
| document.body.innerHTML = ''; | ||
| }); | ||
|
|
||
| // `tagName` is uppercase for HTML elements, so the media check has to | ||
| // normalise it before comparing (upstream rrweb #1921). | ||
| it.each(['video', 'audio'])('ignores autoplay mutations on <%s>', (tag) => { | ||
| const buffer = mutate(document.createElement(tag), 'autoplay', ''); | ||
| expect(recordedNames(buffer)).toEqual([]); | ||
| }); | ||
|
|
||
| it('records other attributes on media elements', () => { | ||
| const buffer = mutate(document.createElement('video'), 'width', '320'); | ||
| expect(buffer.attributes[0].attributes).toEqual({ width: '320' }); | ||
| }); | ||
|
|
||
| it('records autoplay on elements that are not media elements', () => { | ||
| const buffer = mutate(document.createElement('div'), 'autoplay', ''); | ||
| expect(buffer.attributes[0].attributes).toEqual({ autoplay: '' }); | ||
| }); | ||
| }); |
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.
Uh oh!
There was an error while loading. Please reload this page.