Skip to content

Commit 152b713

Browse files
committed
prevent invalid media processing
1 parent fd9d274 commit 152b713

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

.changeset/tiny-rabbits-chew.md

+5
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

+11-8
Original file line numberDiff line numberDiff line change
@@ -1303,14 +1303,17 @@ export class Replayer {
13031303
return this.debugNodeNotFound(d, d.id);
13041304
}
13051305
const mediaEl = target as HTMLMediaElement | RRMediaElement;
1306-
const { events } = this.service.state.context;
1307-
1308-
this.mediaManager.mediaMutation({
1309-
target: mediaEl,
1310-
timeOffset: e.timestamp - events[0].timestamp,
1311-
mutation: d,
1312-
});
1313-
1306+
// sometimes we receive MediaInteraction events on non-media elements (e.g. DIV)
1307+
// only process media mutations on supported media elements to prevent errors during playback
1308+
if (this.mediaManager.isSupportedMediaElement(mediaEl)) {
1309+
const { events } = this.service.state.context;
1310+
1311+
this.mediaManager.mediaMutation({
1312+
target: mediaEl,
1313+
timeOffset: e.timestamp - events[0].timestamp,
1314+
mutation: d,
1315+
});
1316+
}
13141317
break;
13151318
}
13161319
case IncrementalSource.StyleSheetRule:

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ export class MediaManager {
210210
const target = node as HTMLMediaElement;
211211
const serializedNode = mirror.getMeta(target);
212212
if (!serializedNode || !('attributes' in serializedNode)) return;
213+
214+
// don't process if the media element is blocked
215+
const isBlockedMediaElement =
216+
serializedNode.attributes.rr_width || serializedNode.attributes.rr_height;
217+
if (isBlockedMediaElement) return;
218+
213219
const playerIsPaused = this.service.state.matches('paused');
214220
const mediaAttributes = serializedNode.attributes as
215221
| mediaAttributes
@@ -285,7 +291,9 @@ export class MediaManager {
285291
this.syncTargetWithState(target);
286292
}
287293

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

0 commit comments

Comments
 (0)