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.
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user