From f7a3c992f86def2b4388a764586f20afccf35c35 Mon Sep 17 00:00:00 2001 From: dphuang2 Date: Sat, 10 Aug 2019 02:29:23 -0700 Subject: [PATCH] Fix timeOffset on multiple stylesheet loads (#115) In the case that the replayer triggers multiple FullSnapshot events, it will call waitForStylesheetLoad multiple times. When the replayer resumes, it could already have a timeoffset set from a previous resume in a previous waitForStylesheetLoad call. In this case our new timeoffset should be the value of our current time in the replay (timer.timeOffset + getTimeOffset()). To solve this, I created a public getCurrentTime function which correctly returns the time in the replay and used that as our new timeoffset when resuming from a stylesheet load. --- src/replay/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 2701f083..8d0230a9 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -104,6 +104,10 @@ export class Replayer { }; } + public getCurrentTime(): number { + return this.timer.timeOffset + this.getTimeOffset(); + } + public getTimeOffset(): number { return this.baselineTime - this.events[0].timestamp; } @@ -315,7 +319,7 @@ export class Replayer { this.pause(); this.emitter.emit(ReplayerEvents.LoadStylesheetStart); timer = window.setTimeout(() => { - this.resume(this.timer.timeOffset); + this.resume(this.getCurrentTime()); // mark timer was called timer = -1; }, this.config.loadTimeout); @@ -324,7 +328,7 @@ export class Replayer { css.addEventListener('load', () => { unloadSheets.delete(css); if (unloadSheets.size === 0 && timer !== -1) { - this.resume(this.timer.timeOffset); + this.resume(this.getCurrentTime()); this.emitter.emit(ReplayerEvents.LoadStylesheetEnd); if (timer) { window.clearTimeout(timer);