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

Add config option to turn off all snapshotting and related observers #1311

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions .changeset/polite-olives-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

Add 'recordDOM' config option to turn off recording of DOM (making recordings unreplayable). Specialist use case e.g. only heatmap click/scroll recording
5 changes: 5 additions & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ function record<T = eventWithTime>(
sampling = {},
dataURLOptions = {},
mousemoveWait,
recordDOM = true,
recordCanvas = false,
recordCrossOriginIframes = false,
recordAfter = options.recordAfter === 'DOMContentLoaded'
Expand Down Expand Up @@ -345,6 +346,9 @@ function record<T = eventWithTime>(
});

takeFullSnapshot = (isCheckout = false) => {
if (!recordDOM) {
return;
}
wrappedEmit(
wrapEvent({
type: EventType.Meta,
Expand Down Expand Up @@ -529,6 +533,7 @@ function record<T = eventWithTime>(
maskInputOptions,
inlineStylesheet,
sampling,
recordDOM,
recordCanvas,
inlineImages,
userTriggeredOnInput,
Expand Down
33 changes: 21 additions & 12 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,10 @@ export function initObservers(
}

mergeHooks(o, hooks);
const mutationObserver = initMutationObserver(o, o.doc);
let mutationObserver: MutationObserver | undefined;
if (o.recordDOM) {
mutationObserver = initMutationObserver(o, o.doc);
}
const mousemoveHandler = initMoveObserver(o);
const mouseInteractionHandler = initMouseInteractionObserver(o);
const scrollHandler = initScrollObserver(o);
Expand All @@ -1292,16 +1295,20 @@ export function initObservers(
const inputHandler = initInputObserver(o);
const mediaInteractionHandler = initMediaInteractionObserver(o);

const styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
const adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
const styleDeclarationObserver = initStyleDeclarationObserver(o, {
win: currentWindow,
});
const fontObserver = o.collectFonts
? initFontObserver(o)
: () => {
//
};
let styleSheetObserver = () => {};
let adoptedStyleSheetObserver = () => {};
let styleDeclarationObserver = () => {};
let fontObserver = () => {};
if (o.recordDOM) {
styleSheetObserver = initStyleSheetObserver(o, { win: currentWindow });
adoptedStyleSheetObserver = initAdoptedStyleSheetObserver(o, o.doc);
styleDeclarationObserver = initStyleDeclarationObserver(o, {
win: currentWindow,
});
if (o.collectFonts) {
fontObserver = initFontObserver(o);
}
}
const selectionObserver = initSelectionObserver(o);

// plugins
Expand All @@ -1314,7 +1321,9 @@ export function initObservers(

return callbackWrapper(() => {
mutationBuffers.forEach((b) => b.reset());
mutationObserver.disconnect();
if (mutationObserver) {
mutationObserver.disconnect();
}
eoghanmurray marked this conversation as resolved.
Show resolved Hide resolved
mousemoveHandler();
mouseInteractionHandler();
scrollHandler();
Expand Down
2 changes: 2 additions & 0 deletions packages/rrweb/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export type recordOptions<T> = {
packFn?: PackFn;
sampling?: SamplingStrategy;
dataURLOptions?: DataURLOptions;
recordDOM?: boolean;
recordCanvas?: boolean;
recordCrossOriginIframes?: boolean;
recordAfter?: 'DOMContentLoaded' | 'load';
Expand Down Expand Up @@ -98,6 +99,7 @@ export type observerParam = {
canvasMutationCb: canvasMutationCallback;
fontCb: fontCallback;
sampling: SamplingStrategy;
recordDOM: boolean;
recordCanvas: boolean;
inlineImages: boolean;
userTriggeredOnInput: boolean;
Expand Down