From eccaccf73eab37f7775b7ae9bfa6114e9fb69756 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 22 Feb 2023 16:21:37 +0100 Subject: [PATCH 1/4] feat: Ignore `autoplay` attribute on video/auto elements This element leads to weird issues when replaying, so it's better to strip this out. --- packages/rrweb-snapshot/src/snapshot.ts | 18 ++++++++++++------ packages/rrweb-snapshot/test/html/video.html | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 5d348a2108..309caafd66 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -252,6 +252,10 @@ export function transformAttribute( } } +function ignoreAttribute(tagName: string, name: string, _value: unknown) { + return (tagName === 'video' || tagName === 'audio') && name === 'autplay'; +} + export function _isBlockedElement( element: HTMLElement, blockClass: string | RegExp, @@ -614,12 +618,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 -