Skip to content

Commit 21b231e

Browse files
committed
Squarespace dispatches media events on non-media elements. These cause an error upon replay.
Found in the wild at https://static1.squarespace.com/static/vta/5c5a519771c10ba3470d8101/scripts/416.b27e99ad04cb589ced2b.js
1 parent 0d6b02b commit 21b231e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/rrweb/src/record/observer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,7 @@ function initMediaInteractionObserver({
14651465
const target = getEventTarget(event);
14661466
if (
14671467
!target ||
1468+
!(target instanceof HTMLMediaElement) ||
14681469
isBlocked(target as Node, blockClass, blockSelector, true)
14691470
) {
14701471
return;

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export class MediaManager {
5454
this.mediaMap.forEach((_mediaState, target) => {
5555
this.syncTargetWithState(target);
5656
if (options.pause) {
57-
target.pause();
57+
try {
58+
target.pause();
59+
} catch (error) {
60+
this.warn(
61+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
62+
`Failed to sync media element: ${error.message || error}`,
63+
);
64+
}
5865
}
5966
});
6067
}
@@ -104,7 +111,14 @@ export class MediaManager {
104111

105112
target.currentTime = seekToTime;
106113
} else {
107-
target.pause();
114+
try {
115+
target.pause();
116+
} catch (error) {
117+
this.warn(
118+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
119+
`Failed to pause during seek: ${error.message || error}`,
120+
);
121+
}
108122
target.currentTime = mediaState.currentTimeAtLastInteraction;
109123
}
110124
}

0 commit comments

Comments
 (0)