Skip to content
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

feat: Remove getCanvasManager, export CanvasManager class directly #153

Merged
merged 9 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/rrweb/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ export { record, Replayer, utils, canvasMutation };

export { deserializeArg } from './replay/canvas/deserialize-args';

export {
takeFullSnapshot,
mirror,
freezePage,
addCustomEvent,
getCanvasManager,
} from './record';
export { takeFullSnapshot, mirror, freezePage, addCustomEvent } from './record';

export { CanvasManager } from './record/observers/canvas/canvas-manager';
export type { CanvasManagerConstructorOptions } from './record/observers/canvas/canvas-manager';
60 changes: 17 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 @@
MaskInputOptions,
SlimDOMOptions,
createMirror,
DataURLOptions,
} from '@sentry-internal/rrweb-snapshot';
import { initObservers, mutationBuffers } from './observer';
import {
Expand Down Expand Up @@ -41,7 +40,6 @@
ShadowDomManagerNoop,
} from './shadow-dom-manager';
import {
CanvasManager,
CanvasManagerConstructorOptions,
CanvasManagerInterface,
CanvasManagerNoop,
Expand Down Expand Up @@ -340,6 +338,18 @@
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 @@ -615,7 +625,7 @@
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,

Check warning on line 628 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/record/index.ts#L628

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
options: p.options,
callback: (payload: object) =>
wrappedEmit(
Expand All @@ -635,7 +645,7 @@

iframeManager.addLoadListener((iframeEl) => {
try {
handlers.push(observe(iframeEl.contentDocument!));

Check warning on line 648 in packages/rrweb/src/record/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/record/index.ts#L648

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
} catch (error) {
// TODO: handle internal error
console.warn(error);
Expand Down Expand Up @@ -717,14 +727,6 @@
_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,48 +736,20 @@

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,
) {
try {
return getCanvasManagerFn
? getCanvasManagerFn({
...options,
mirror,
win: window,
mutationCb: (p: canvasMutationParam) =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.CanvasMutation,
...p,
},
}),
),
})
? getCanvasManagerFn(options)
: new CanvasManagerNoop();
} catch {
console.warn('Unable to initialize CanvasManager');
return new CanvasManagerNoop();
}
}

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