Skip to content

Commit

Permalink
feat(replay): try/catch around stopRecording
Browse files Browse the repository at this point in the history
There were rare instances where stopping rrweb.record would cause an exception to bubble up from rrweb.
  • Loading branch information
billyvg authored and mydea committed Jan 23, 2023
1 parent f2e00b1 commit 04ebafc
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,18 @@ export class ReplayContainer implements ReplayContainerInterface {
* Returns true if it was stopped, else false.
*/
public stopRecording(): boolean {
if (this._stopRecording) {
this._stopRecording();
return true;
}
try {
if (this._stopRecording) {
this._stopRecording();
this._stopRecording = undefined;
return true;
}

return false;
return false;
} catch (err) {
this._handleException(err);
return false;
}
}

/**
Expand All @@ -226,7 +232,7 @@ export class ReplayContainer implements ReplayContainerInterface {
__DEBUG_BUILD__ && logger.log('[Replay] Stopping Replays');
this._isEnabled = false;
this._removeListeners();
this._stopRecording && this._stopRecording();
this.stopRecording();
this.eventBuffer && this.eventBuffer.destroy();
this.eventBuffer = null;
this._debouncedFlush.cancel();
Expand All @@ -242,14 +248,7 @@ export class ReplayContainer implements ReplayContainerInterface {
*/
public pause(): void {
this._isPaused = true;
try {
if (this._stopRecording) {
this._stopRecording();
this._stopRecording = undefined;
}
} catch (err) {
this._handleException(err);
}
this.stopRecording();
}

/**
Expand Down Expand Up @@ -634,8 +633,12 @@ export class ReplayContainer implements ReplayContainerInterface {
* create a new Replay event.
*/
private _triggerFullSnapshot(): void {
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
record.takeFullSnapshot(true);
try {
__DEBUG_BUILD__ && logger.log('[Replay] Taking full rrweb snapshot');
record.takeFullSnapshot(true);
} catch (err) {
this._handleException(err);
}
}

/**
Expand Down

0 comments on commit 04ebafc

Please sign in to comment.