Skip to content

Commit

Permalink
feat: Remove getCanvasManager, export CanvasManager class directly
Browse files Browse the repository at this point in the history
This simplifies the code a bit by exporting the CanvasManager directly. With [ReplayCanvas](getsentry/sentry-javascript#10112), we can rely on it for complex setup, but keeps it simple for our users.
  • Loading branch information
billyvg committed Jan 9, 2024
1 parent e4de658 commit cae5089
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
4 changes: 3 additions & 1 deletion packages/rrweb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ export {
mirror,
freezePage,
addCustomEvent,
getCanvasManager,
} from './record';

export {CanvasManager} from './record/observers/canvas/canvas-manager';
export type {CanvasManagerConstructorOptions} from './record/observers/canvas/canvas-manager';
58 changes: 15 additions & 43 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
MaskInputOptions,
SlimDOMOptions,
createMirror,
DataURLOptions,
} from '@sentry-internal/rrweb-snapshot';
import { initObservers, mutationBuffers } from './observer';
import {
Expand Down Expand Up @@ -41,7 +40,6 @@ import {
ShadowDomManagerNoop,
} from './shadow-dom-manager';
import {
CanvasManager,
CanvasManagerConstructorOptions,
CanvasManagerInterface,
CanvasManagerNoop,
Expand Down Expand Up @@ -340,6 +338,18 @@ function record<T = eventWithTime>(
const canvasManager: CanvasManagerInterface = _getCanvasManager(
getCanvasManager,
{
mirror,
win: window,
mutationCb: (p: canvasMutationParam) =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.CanvasMutation,
...p,
},
}),
),
recordCanvas,
blockClass,
blockSelector,
Expand Down Expand Up @@ -717,14 +727,6 @@ export function takeFullSnapshot(isCheckout?: boolean) {
_takeFullSnapshot(isCheckout);
}

function wrappedEmit(e: eventWithTime) {
if (!_wrappedEmit) {
return;
}

_wrappedEmit(e);
}

// record.addCustomEvent is removed because Sentry Session Replay does not use it
// record.freezePage is removed because Sentry Session Replay does not use it

Expand All @@ -734,43 +736,13 @@ record.takeFullSnapshot = takeFullSnapshot;

export default record;

type PrivateOptions = 'mutationCb' | 'win' | 'mirror';
type PublicGetCanvasManagerOptions = Omit<
CanvasManagerConstructorOptions,
PrivateOptions
>;

interface PrivateGetCanvasManagerOptions
extends PublicGetCanvasManagerOptions,
Pick<CanvasManagerConstructorOptions, PrivateOptions> {}

function _getCanvasManager(
getCanvasManagerFn:
| undefined
| ((options: PrivateGetCanvasManagerOptions) => CanvasManagerInterface),
options: PublicGetCanvasManagerOptions,
| ((options: Partial<CanvasManagerConstructorOptions>) => CanvasManagerInterface),
options: CanvasManagerConstructorOptions,
) {
return getCanvasManagerFn
? getCanvasManagerFn({
...options,
mirror,
win: window,
mutationCb: (p: canvasMutationParam) =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.CanvasMutation,
...p,
},
}),
),
})
? getCanvasManagerFn(options)
: new CanvasManagerNoop();
}

export function getCanvasManager(
options: PublicGetCanvasManagerOptions,
): CanvasManagerInterface {
return new CanvasManager(options as CanvasManagerConstructorOptions);
}

0 comments on commit cae5089

Please sign in to comment.