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: Remove autoplay attribute from audio/video tags #59

Merged
merged 1 commit into from
Feb 22, 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
9 changes: 8 additions & 1 deletion packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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';
}
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we expect a snapshot file diff?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because we are removing the autoplay attribute :D the snapshot changes without the change (which is expected), so IMHO the fact that this stays static is basically the test for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh right :)

<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