diff --git a/.changeset/old-dryers-hide.md b/.changeset/old-dryers-hide.md new file mode 100644 index 0000000000..1b3e3399b0 --- /dev/null +++ b/.changeset/old-dryers-hide.md @@ -0,0 +1,5 @@ +--- +'rrweb-snapshot': minor +--- + +feat: Ignore `autoplay` attribute on video/audio elements diff --git a/packages/rrweb-snapshot/src/index.ts b/packages/rrweb-snapshot/src/index.ts index b2417187ca..ef9d1b19fa 100644 --- a/packages/rrweb-snapshot/src/index.ts +++ b/packages/rrweb-snapshot/src/index.ts @@ -1,6 +1,7 @@ import snapshot, { serializeNodeWithId, transformAttribute, + ignoreAttribute, visitSnapshot, cleanupSnapshot, needMaskingText, @@ -24,6 +25,7 @@ export { addHoverClass, createCache, transformAttribute, + ignoreAttribute, visitSnapshot, cleanupSnapshot, needMaskingText, diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 5d348a2108..1a9f8813a5 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -252,6 +252,14 @@ export function transformAttribute( } } +export function ignoreAttribute( + tagName: string, + name: string, + _value: unknown, +): boolean { + return (tagName === 'video' || tagName === 'audio') && name === 'autoplay'; +} + export function _isBlockedElement( element: HTMLElement, blockClass: string | RegExp, @@ -614,12 +622,14 @@ function serializeElementNode( const len = n.attributes.length; for (let i = 0; i < len; i++) { const attr = n.attributes[i]; - attributes[attr.name] = transformAttribute( - doc, - tagName, - attr.name, - attr.value, - ); + if (!ignoreAttribute(tagName, attr.name, attr.value)) { + attributes[attr.name] = transformAttribute( + doc, + tagName, + attr.name, + attr.value, + ); + } } // remote css if (tagName === 'link' && inlineStylesheet) { diff --git a/packages/rrweb-snapshot/test/html/video.html b/packages/rrweb-snapshot/test/html/video.html index 653f7172d6..5424ca2895 100644 --- a/packages/rrweb-snapshot/test/html/video.html +++ b/packages/rrweb-snapshot/test/html/video.html @@ -7,7 +7,7 @@ video -