Skip to content

feat(replays): Add an SDK _experiments configuration flag to enable canvas recording #9723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Dec 7, 2023
Merged
7 changes: 7 additions & 0 deletions packages/replay/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export class ReplayContainer implements ReplayContainerInterface {
*/
public startRecording(): void {
try {
const canvas = this._options._experiments.canvas;
this._stopRecording = record({
...this._recordingOptions,
// When running in error sampling mode, we need to overwrite `checkoutEveryNms`
Expand All @@ -339,6 +340,12 @@ export class ReplayContainer implements ReplayContainerInterface {
...(this.recordingMode === 'buffer' && { checkoutEveryNms: BUFFER_CHECKOUT_TIME }),
emit: getHandleRecordingEmit(this),
onMutation: this._onMutationHandler,
...(canvas && {
recordCanvas: true,
sampling: { canvas: canvas.fps || 4 },
dataURLOptions: { quality: canvas.quality || 0.6 },
getCanvasManager: canvas.manager,
}),
});
} catch (err) {
this._handleException(err);
Expand Down
7 changes: 6 additions & 1 deletion packages/replay/src/types/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { SKIPPED, THROTTLED } from '../util/throttle';
import type { AllPerformanceEntry, AllPerformanceEntryData, ReplayPerformanceEntry } from './performance';
import type { ReplayFrameEvent } from './replayFrame';
import type { ReplayNetworkRequestOrResponse } from './request';
import type { ReplayEventWithTime, RrwebRecordOptions } from './rrweb';
import type { CanvasManagerInterface, GetCanvasManagerOptions, ReplayEventWithTime, RrwebRecordOptions } from './rrweb';

export type RecordingEvent = ReplayFrameEvent | ReplayEventWithTime;
export type RecordingOptions = RrwebRecordOptions;
Expand Down Expand Up @@ -232,6 +232,11 @@ export interface ReplayPluginOptions extends ReplayNetworkOptions {
_experiments: Partial<{
captureExceptions: boolean;
traceInternals: boolean;
canvas: {
fps?: number;
quality?: number;
manager: (options: GetCanvasManagerOptions) => CanvasManagerInterface;
};
}>;
}

Expand Down
20 changes: 20 additions & 0 deletions packages/replay/src/types/rrweb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,23 @@ export type RrwebRecordOptions = {
blockSelector?: string;
maskInputOptions?: Record<string, boolean>;
} & Record<string, unknown>;

export interface CanvasManagerInterface {
reset(): void;
freeze(): void;
unfreeze(): void;
lock(): void;
unlock(): void;
}

export interface GetCanvasManagerOptions {
recordCanvas: boolean;
blockClass: string | RegExp;
blockSelector: string | null;
unblockSelector: string | null;
sampling?: 'all' | number;
dataURLOptions: Partial<{
type: string;
quality: number;
}>;
}