Skip to content
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

feat: Ignore autoplay attribute on video/audio elements #1152

Merged
merged 4 commits into from
Mar 3, 2023
Merged
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
5 changes: 5 additions & 0 deletions .changeset/old-dryers-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb-snapshot': minor
---

feat: Ignore `autoplay` attribute on video/audio elements
2 changes: 2 additions & 0 deletions packages/rrweb-snapshot/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import snapshot, {
serializeNodeWithId,
transformAttribute,
ignoreAttribute,
visitSnapshot,
cleanupSnapshot,
needMaskingText,
Expand All @@ -24,6 +25,7 @@ export {
addHoverClass,
createCache,
transformAttribute,
ignoreAttribute,
visitSnapshot,
cleanupSnapshot,
needMaskingText,
Expand Down
22 changes: 16 additions & 6 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/test/html/video.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<title>video</title>
</head>
<body>
<video controls>
<video controls autoplay>
<source src=http://techslides.com/demos/sample-videos/small.webm
type=video/webm> <source
src=http://techslides.com/demos/sample-videos/small.ogv type=video/ogg>
Expand Down
3 changes: 2 additions & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
serializeNodeWithId,
transformAttribute,
IGNORED_NODE,
ignoreAttribute,
isShadowRoot,
needMaskingText,
maskInputValue,
Expand Down Expand Up @@ -557,7 +558,7 @@ export default class MutationBuffer {
styleObj[pname] = false; // delete
}
}
} else {
} else if (!ignoreAttribute(target.tagName, m.attributeName!, value)) {
// overwrite attribute if the mutations was triggered in same time
item.attributes[m.attributeName!] = transformAttribute(
this.doc,
Expand Down