From 8eaccfef56865e03c581a6007891eb15329efba3 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 22 Feb 2023 16:02:43 +0100 Subject: [PATCH] feat: Remove `autoplay` attribute from audio/video tags These can lead to weird results when replaying this later, so we just want to omit these. --- packages/rrweb-snapshot/src/snapshot.ts | 9 ++++++++- packages/rrweb-snapshot/test/html/video.html | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index a657f22ab7..0f2af24876 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -500,7 +500,9 @@ function serializeNode( const tagName = getValidTagName(n as HTMLElement); let attributes: attributes = {}; for (const { name, value } of Array.from((n as HTMLElement).attributes)) { - attributes[name] = transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn); + if (!skipAttribute(tagName, name, value)) { + attributes[name] = transformAttribute(doc, tagName, name, value, maskAllText, maskTextFn); + } } // remote css if (tagName === 'link' && inlineStylesheet) { @@ -1243,3 +1245,8 @@ export function cleanupSnapshot() { } export default snapshot; + +/** We want to skip `autoplay` attribute, as this has weird results when replaying. */ +function skipAttribute(tagName: string, attributeName: string, value?: unknown) { + return (tagName === 'video' || tagName === 'audio') && attributeName === 'autoplay'; +} \ No newline at end of file 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 -