Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-ignore-attribute-tagname-case.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"rrweb-snapshot": patch
"rrweb": patch
---

Lowercase the tag name in `ignoreAttribute` so `autoplay` mutations on `<video>`/`<audio>` are ignored on the attribute-mutation path, which passes the native uppercase `target.tagName`
4 changes: 3 additions & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ export function ignoreAttribute(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_value: unknown,
): boolean {
return ['video', 'audio'].includes(tagName) && name === 'autoplay';
return (
['video', 'audio'].includes(toLowerCase(tagName)) && name === 'autoplay'
);
}

export function _isBlockedElement(
Expand Down
19 changes: 19 additions & 0 deletions packages/rrweb-snapshot/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { describe, expect, it } from 'vitest';

import snapshot, {
_isBlockedElement,
ignoreAttribute,
serializeNodeWithId,
} from '../src/snapshot';
import { elementNode, serializedNodeWithId } from '../src/types';
Expand Down Expand Up @@ -159,6 +160,24 @@ describe('isBlockedElement()', () => {
});
});

describe('ignoreAttribute()', () => {
it('ignores autoplay on lowercase media tag names', () => {
expect(ignoreAttribute('video', 'autoplay', '')).toEqual(true);
expect(ignoreAttribute('audio', 'autoplay', '')).toEqual(true);
});

it('ignores autoplay on native uppercase media tag names', () => {
expect(ignoreAttribute('VIDEO', 'autoplay', '')).toEqual(true);
expect(ignoreAttribute('AUDIO', 'autoplay', '')).toEqual(true);
});

it('does not ignore other attributes or other elements', () => {
expect(ignoreAttribute('video', 'src', '')).toEqual(false);
expect(ignoreAttribute('DIV', 'autoplay', '')).toEqual(false);
expect(ignoreAttribute('div', 'autoplay', '')).toEqual(false);
});
});

describe('style elements', () => {
const render = (html: string): HTMLStyleElement => {
document.write(html);
Expand Down