Skip to content

Commit 81da5b1

Browse files
authored
Merge pull request #44 from pendo-io/jc-prevent-invalid-media-processing
fix: prevent invalid media processing
2 parents 1ee88fe + c283cbd commit 81da5b1

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

.changeset/tiny-rabbits-chew.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb": patch
3+
---
4+
5+
Make sure MediaInteraction events / mutations are only processed on MediaElements + exit early in addMediaElements if a MediaElement is a blocked element

packages/rrweb/src/replay/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,14 +1311,17 @@ export class Replayer {
13111311
return this.debugNodeNotFound(d, d.id);
13121312
}
13131313
const mediaEl = target as HTMLMediaElement | RRMediaElement;
1314-
const { events } = this.service.state.context;
1315-
1316-
this.mediaManager.mediaMutation({
1317-
target: mediaEl,
1318-
timeOffset: e.timestamp - events[0].timestamp,
1319-
mutation: d,
1320-
});
1321-
1314+
// sometimes we receive MediaInteraction events on non-media elements (e.g. DIV)
1315+
// only process media mutations on supported media elements to prevent errors during playback
1316+
if (this.mediaManager.isSupportedMediaElement(mediaEl)) {
1317+
const { events } = this.service.state.context;
1318+
1319+
this.mediaManager.mediaMutation({
1320+
target: mediaEl,
1321+
timeOffset: e.timestamp - events[0].timestamp,
1322+
mutation: d,
1323+
});
1324+
}
13221325
break;
13231326
}
13241327
case IncrementalSource.StyleSheetRule:

packages/rrweb/src/replay/media/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ export class MediaManager {
209209
const target = node as HTMLMediaElement;
210210
const serializedNode = mirror.getMeta(target);
211211
if (!serializedNode || !('attributes' in serializedNode)) return;
212+
213+
// don't process if the media element is blocked
214+
const isBlockedMediaElement =
215+
serializedNode.attributes.rr_width || serializedNode.attributes.rr_height;
216+
if (isBlockedMediaElement) return;
217+
212218
const playerIsPaused = this.service.state.matches('paused');
213219
const mediaAttributes = serializedNode.attributes as
214220
| mediaAttributes
@@ -284,7 +290,9 @@ export class MediaManager {
284290
this.syncTargetWithState(target);
285291
}
286292

287-
public isSupportedMediaElement(node: Node): node is HTMLMediaElement {
293+
public isSupportedMediaElement(
294+
node: Node | RRMediaElement,
295+
): node is HTMLMediaElement | RRMediaElement {
288296
return ['AUDIO', 'VIDEO'].includes(node.nodeName);
289297
}
290298

0 commit comments

Comments
 (0)