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

fix: safe pause #1461

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/safe-pause.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

fix: safe pause
19 changes: 15 additions & 4 deletions packages/rrweb/src/replay/media/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,22 @@ export class MediaManager {
});
}

private safePause(target: HTMLMediaElement | RRMediaElement) {
// https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause
// RRMediaElement inherits from BaseRRMediaElementImpl, which has a pause method
// but we received a type error when trying to call it directly (target.pause is not a function)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (typeof target.pause === 'function') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
target.pause();
}
}

private syncAllMediaElements(options = { pause: false }) {
this.mediaMap.forEach((mediaState, target) => {
this.syncTargetWithState(target);
if (options.pause) {
target.pause();
this.safePause(target);
}
});
}
Expand Down Expand Up @@ -103,7 +114,7 @@ export class MediaManager {

target.currentTime = seekToTime;
} else {
target.pause();
this.safePause(target);
target.currentTime = mediaState.currentTimeAtLastInteraction;
}
}
Expand Down Expand Up @@ -194,7 +205,7 @@ export class MediaManager {
// unexpected behavior
void target.play();
} else {
target.pause();
this.safePause(target);
}
} catch (error) {
this.warn(
Expand All @@ -220,7 +231,7 @@ export class MediaManager {
} else {
isPlaying = target.getAttribute('autoplay') !== null;
}
if (isPlaying && playerIsPaused) target.pause();
if (isPlaying && playerIsPaused) this.safePause(target);

let playbackRate = 1;
if (typeof mediaAttributes.rr_mediaPlaybackRate === 'number') {
Expand Down
Loading