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(canvas): Bind mutationCb outside of getCanvasManager #141

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Changes from all 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
77 changes: 47 additions & 30 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
MaskInputOptions,
SlimDOMOptions,
createMirror,
DataURLOptions,

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-unused-vars] 'DataURLOptions' is defined but never used.
} from '@sentry-internal/rrweb-snapshot';
import { initObservers, mutationBuffers } from './observer';
import {
Expand Down Expand Up @@ -337,16 +337,17 @@

const processedNodeManager = new ProcessedNodeManager();

const canvasManager: CanvasManagerInterface = getCanvasManager
? getCanvasManager({
recordCanvas,
blockClass,
blockSelector,
unblockSelector,
sampling: sampling['canvas'],
dataURLOptions,
})
: new CanvasManagerNoop();
const canvasManager: CanvasManagerInterface = _getCanvasManager(
getCanvasManager,
{
recordCanvas,
blockClass,
blockSelector,
unblockSelector,
sampling: sampling['canvas'],
dataURLOptions,
},
);

const shadowDomManager: ShadowDomManagerInterface =
typeof __RRWEB_EXCLUDE_SHADOW_DOM__ === 'boolean' &&
Expand Down Expand Up @@ -614,7 +615,7 @@
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

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

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

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
} catch (error) {
// TODO: handle internal error
console.warn(error);
Expand Down Expand Up @@ -733,27 +734,43 @@

export default record;

const wrappedCanvasMutationEmit = (p: canvasMutationParam) =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.CanvasMutation,
...p,
},
}),
);
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,
) {
return getCanvasManagerFn
? getCanvasManagerFn({
...options,
mirror,
win: window,
mutationCb: (p: canvasMutationParam) =>
wrappedEmit(
wrapEvent({
type: EventType.IncrementalSnapshot,
data: {
source: IncrementalSource.CanvasMutation,
...p,
},
}),
),
})
: new CanvasManagerNoop();
}

export function getCanvasManager(
options: Omit<
CanvasManagerConstructorOptions,
'mutationCb' | 'win' | 'mirror'
>,
options: PublicGetCanvasManagerOptions,
): CanvasManagerInterface {
return new CanvasManager({
...options,
mutationCb: wrappedCanvasMutationEmit,
win: window,
mirror,
});
return new CanvasManager(options as CanvasManagerConstructorOptions);
}
Loading