feat: Ignore autoplay attribute on video/audio elements (#1152)
* feat: Ignore `autoplay` attribute on video/auto elements This element leads to weird issues when replaying, so it's better to strip this out. * add changeset * fix check fix typo * Apply formatting changes --------- Co-authored-by: mydea <mydea@users.noreply.github.com>
This commit is contained in:
5
.changeset/old-dryers-hide.md
Normal file
5
.changeset/old-dryers-hide.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'rrweb-snapshot': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: Ignore `autoplay` attribute on video/audio elements
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import snapshot, {
|
import snapshot, {
|
||||||
serializeNodeWithId,
|
serializeNodeWithId,
|
||||||
transformAttribute,
|
transformAttribute,
|
||||||
|
ignoreAttribute,
|
||||||
visitSnapshot,
|
visitSnapshot,
|
||||||
cleanupSnapshot,
|
cleanupSnapshot,
|
||||||
needMaskingText,
|
needMaskingText,
|
||||||
@@ -24,6 +25,7 @@ export {
|
|||||||
addHoverClass,
|
addHoverClass,
|
||||||
createCache,
|
createCache,
|
||||||
transformAttribute,
|
transformAttribute,
|
||||||
|
ignoreAttribute,
|
||||||
visitSnapshot,
|
visitSnapshot,
|
||||||
cleanupSnapshot,
|
cleanupSnapshot,
|
||||||
needMaskingText,
|
needMaskingText,
|
||||||
|
|||||||
@@ -255,6 +255,14 @@ export function transformAttribute(
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ignoreAttribute(
|
||||||
|
tagName: string,
|
||||||
|
name: string,
|
||||||
|
_value: unknown,
|
||||||
|
): boolean {
|
||||||
|
return (tagName === 'video' || tagName === 'audio') && name === 'autoplay';
|
||||||
|
}
|
||||||
|
|
||||||
export function _isBlockedElement(
|
export function _isBlockedElement(
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
blockClass: string | RegExp,
|
blockClass: string | RegExp,
|
||||||
@@ -617,12 +625,14 @@ function serializeElementNode(
|
|||||||
const len = n.attributes.length;
|
const len = n.attributes.length;
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const attr = n.attributes[i];
|
const attr = n.attributes[i];
|
||||||
attributes[attr.name] = transformAttribute(
|
if (!ignoreAttribute(tagName, attr.name, attr.value)) {
|
||||||
doc,
|
attributes[attr.name] = transformAttribute(
|
||||||
tagName,
|
doc,
|
||||||
attr.name,
|
tagName,
|
||||||
attr.value,
|
attr.name,
|
||||||
);
|
attr.value,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// remote css
|
// remote css
|
||||||
if (tagName === 'link' && inlineStylesheet) {
|
if (tagName === 'link' && inlineStylesheet) {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<title>video</title>
|
<title>video</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<video controls>
|
<video controls autoplay>
|
||||||
<source src=http://techslides.com/demos/sample-videos/small.webm
|
<source src=http://techslides.com/demos/sample-videos/small.webm
|
||||||
type=video/webm> <source
|
type=video/webm> <source
|
||||||
src=http://techslides.com/demos/sample-videos/small.ogv type=video/ogg>
|
src=http://techslides.com/demos/sample-videos/small.ogv type=video/ogg>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import {
|
|||||||
serializeNodeWithId,
|
serializeNodeWithId,
|
||||||
transformAttribute,
|
transformAttribute,
|
||||||
IGNORED_NODE,
|
IGNORED_NODE,
|
||||||
|
ignoreAttribute,
|
||||||
isShadowRoot,
|
isShadowRoot,
|
||||||
needMaskingText,
|
needMaskingText,
|
||||||
maskInputValue,
|
maskInputValue,
|
||||||
@@ -557,7 +558,7 @@ export default class MutationBuffer {
|
|||||||
styleObj[pname] = false; // delete
|
styleObj[pname] = false; // delete
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!ignoreAttribute(target.tagName, m.attributeName!, value)) {
|
||||||
// overwrite attribute if the mutations was triggered in same time
|
// overwrite attribute if the mutations was triggered in same time
|
||||||
item.attributes[m.attributeName!] = transformAttribute(
|
item.attributes[m.attributeName!] = transformAttribute(
|
||||||
this.doc,
|
this.doc,
|
||||||
|
|||||||
Reference in New Issue
Block a user