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

upstream: Add config option to turn off all snapshotting and related observers #163

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
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
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 @@
sampling = {},
dataURLOptions = {},
mousemoveWait,
recordDOM = true,
recordCanvas = false,
recordCrossOriginIframes = false,
recordAfter = options.recordAfter === 'DOMContentLoaded'
Expand Down Expand Up @@ -390,6 +391,9 @@
});

const takeFullSnapshot = (isCheckout = false) => {
if (!recordDOM) {
return;
}
wrappedEmit(
{
type: EventType.Meta,
Expand Down Expand Up @@ -573,6 +577,7 @@
maskInputOptions,
inlineStylesheet,
sampling,
recordDOM,
recordCanvas,
inlineImages,
userTriggeredOnInput,
Expand All @@ -597,7 +602,7 @@
plugins
?.filter((p) => p.observer)
?.map((p) => ({
observer: p.observer!,

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

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

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

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

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
} catch (error) {
// TODO: handle internal error
console.warn(error);
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 @@ -158,7 +158,7 @@
| IncrementalSource.TouchMove
| IncrementalSource.Drag,
) => {
const totalOffset = Date.now() - timeBaseline!;

Check warning on line 161 in packages/rrweb/src/record/observer.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/record/observer.ts#L161

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
mousemoveCb(
positions.map((p) => {
p.timeOffset -= totalOffset;
Expand Down Expand Up @@ -1278,7 +1278,7 @@

export function initObservers(
o: observerParam,
_hooks: hooksParam = {},

Check warning on line 1281 in packages/rrweb/src/record/observer.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb/src/record/observer.ts#L1281

[@typescript-eslint/no-unused-vars] '_hooks' is assigned a value but never used.
): listenerHandler {
const currentWindow = o.doc.defaultView; // basically document.window
if (!currentWindow) {
Expand All @@ -1288,7 +1288,11 @@
}

// 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 @@
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, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

win: currentWindow,
});
if (o.collectFonts) {
fontObserver = initFontObserver(o);
}
}
const selectionObserver = initSelectionObserver(o);
const customElementObserver = initCustomElementObserver(o);

Expand All @@ -1321,7 +1333,7 @@

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
Loading