Skip to content

Commit

Permalink
add snapshot delay setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadman97 committed Jul 19, 2023
1 parent 2cc726b commit 137e02c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ function record<T = eventWithTime>(
mirror,
sampling: sampling?.canvas?.fps,
clearWebGLBuffer: sampling?.canvas?.clearWebGLBuffer,
initialSnapshotDelay: sampling?.canvas?.initialSnapshotDelay,
dataURLOptions,
resizeFactor: sampling?.canvas?.resizeFactor,
maxSnapshotDimension: sampling?.canvas?.maxSnapshotDimension,
Expand Down
15 changes: 12 additions & 3 deletions packages/rrweb/src/record/observers/canvas/canvas-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class CanvasManager {
mirror: Mirror;
sampling?: 'all' | number;
clearWebGLBuffer?: boolean;
initialSnapshotDelay?: number;
dataURLOptions: DataURLOptions;
resizeFactor?: number;
maxSnapshotDimension?: number;
Expand All @@ -89,6 +90,7 @@ export class CanvasManager {
recordCanvas,
recordVideos,
clearWebGLBuffer,
initialSnapshotDelay,
dataURLOptions,
} = options;
this.mutationCb = options.mutationCb;
Expand All @@ -106,6 +108,7 @@ export class CanvasManager {
blockSelector,
{
clearWebGLBuffer,
initialSnapshotDelay,
dataURLOptions,
},
options.resizeFactor,
Expand Down Expand Up @@ -154,6 +157,7 @@ export class CanvasManager {
blockSelector: string | null,
options: {
clearWebGLBuffer?: boolean;
initialSnapshotDelay?: number;
dataURLOptions: DataURLOptions;
},
resizeFactor?: number,
Expand Down Expand Up @@ -404,16 +408,21 @@ export class CanvasManager {
}
}),
);
await Promise.all(promises);
Promise.all(promises).catch(console.error);

rafId = requestAnimationFrame(takeSnapshots);
};

rafId = requestAnimationFrame(takeSnapshots);
const delay = setTimeout(() => {
rafId = requestAnimationFrame(takeSnapshots);
}, options.initialSnapshotDelay);

this.resetObservers = () => {
canvasContextReset();
cancelAnimationFrame(rafId);
clearTimeout(delay);
if (rafId) {
cancelAnimationFrame(rafId);
}
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ export type CanvasSamplingStrategy = Partial<{
* Set to false to disable the clearing (in case there are visual glitches in the canvas).
*/
clearWebGLBuffer?: boolean;
/**
* Time (in milliseconds) to wait before the initial snapshot of canvas/video elements.
*/
initialSnapshotDelay?: number;
/**
* Adjust the quality of the canvas blob serialization.
*/
Expand Down

0 comments on commit 137e02c

Please sign in to comment.