Skip to content

Commit

Permalink
upstream: Add config option to turn off all snapshotting and related …
Browse files Browse the repository at this point in the history
…observers

* Add config option to turn off all snapshotting and related observers

- allows RRWEB to be used for click/movement tracking alone, e.g. for a
heatmaps use case
- could also be used if there was a separate process for recording the
DOM (in which case a 3rd party library like
https://github.com/antonmedv/finder could be added to record targets
instead of the mirror)
---------

Authored-by: eoghanmurray <eoghanmurray@users.noreply.github.com>
Co-authored-by: Justin Halsall <Juice10@users.noreply.github.com>
  • Loading branch information
billyvg and Juice10 authored Apr 24, 2024
1 parent f7867ec commit 3ff48e1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
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 @@ -98,6 +98,7 @@ function record<T = eventWithTime>(
sampling = {},
dataURLOptions = {},
mousemoveWait,
recordDOM = true,
recordCanvas = false,
recordCrossOriginIframes = false,
recordAfter = options.recordAfter === 'DOMContentLoaded'
Expand Down Expand Up @@ -390,6 +391,9 @@ function record<T = eventWithTime>(
});

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

// We do not use hooks, so we skip this
const mutationObserver = initMutationObserver(o, o.doc);
// mergeHooks(o, hooks);
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 @@ -1298,16 +1302,24 @@ 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)
: () => {
//
};
// eslint-disable-next-line @typescript-eslint/no-empty-function
let styleSheetObserver = () => {};
// eslint-disable-next-line @typescript-eslint/no-empty-function
let adoptedStyleSheetObserver = () => {};
// eslint-disable-next-line @typescript-eslint/no-empty-function
let styleDeclarationObserver = () => {};
// eslint-disable-next-line @typescript-eslint/no-empty-function
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);
const customElementObserver = initCustomElementObserver(o);

Expand All @@ -1321,7 +1333,7 @@ export function initObservers(

return callbackWrapper(() => {
mutationBuffers.forEach((b) => b.reset());
mutationObserver.disconnect();
mutationObserver?.disconnect();
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 @@ -72,6 +72,7 @@ export type recordOptions<T> = {
packFn?: PackFn;
sampling?: SamplingStrategy;
dataURLOptions?: DataURLOptions;
recordDOM?: boolean;
recordCanvas?: boolean;
recordCrossOriginIframes?: boolean;
recordAfter?: 'DOMContentLoaded' | 'load';
Expand Down Expand Up @@ -121,6 +122,7 @@ export type observerParam = {
customElementCb: customElementCallback;
fontCb: fontCallback;
sampling: SamplingStrategy;
recordDOM: boolean;
recordCanvas: boolean;
inlineImages: boolean;
userTriggeredOnInput: boolean;
Expand Down

0 comments on commit 3ff48e1

Please sign in to comment.