From bc36b505dfce3cba98112d603f092080ac4f42ec Mon Sep 17 00:00:00 2001 From: Lucky Feng Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] fix: sometimes currentTime is smaller than the totalTime when player is finished (#445) plus: fix the problem that sometimes return value of getCurrentTime() is negative --- src/replay/index.ts | 2 +- src/replay/timer.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 700bef19..ca506b24 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -508,7 +508,7 @@ export class Replayer { // defer finish event if the last event is a mouse move setTimeout(() => { finish(); - }, Math.max(0, -event.data.positions[0].timeOffset)); + }, Math.max(0, -event.data.positions[0].timeOffset + 50)); // Add 50 to make sure the timer would check the last mousemove event. Otherwise, the timer may be stopped by the service before checking the last event. } else { finish(); } diff --git a/src/replay/timer.ts b/src/replay/timer.ts index f256b8eb..1ec786da 100644 --- a/src/replay/timer.ts +++ b/src/replay/timer.ts @@ -39,7 +39,8 @@ export class Timer { let lastTimestamp = performance.now(); const { actions } = this; const self = this; - function check(time: number) { + function check() { + const time = performance.now(); self.timeOffset += (time - lastTimestamp) * self.speed; lastTimestamp = time; while (actions.length) {