From b310e6f4de79371f6538591825ec1e6a1c03e15c Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 7 Jul 2023 11:11:27 +0200 Subject: [PATCH] feat: Better masking of option/radio/checkbox values --- .changeset/little-moons-camp.md | 6 + packages/rrweb-snapshot/src/snapshot.ts | 59 +- packages/rrweb-snapshot/src/types.ts | 2 + packages/rrweb-snapshot/src/utils.ts | 34 +- .../__snapshots__/integration.test.ts.snap | 6 + packages/rrweb/src/record/index.ts | 2 + packages/rrweb/src/record/mutation.ts | 6 +- packages/rrweb/src/record/observer.ts | 36 +- .../__snapshots__/integration.test.ts.snap | 1144 +++++++++++------ packages/rrweb/test/html/form.html | 16 +- .../cross-origin-iframes.test.ts.snap | 373 ++++-- 11 files changed, 1167 insertions(+), 517 deletions(-) create mode 100644 .changeset/little-moons-camp.md diff --git a/.changeset/little-moons-camp.md b/.changeset/little-moons-camp.md new file mode 100644 index 0000000000..776f214f40 --- /dev/null +++ b/.changeset/little-moons-camp.md @@ -0,0 +1,6 @@ +--- +'rrweb-snapshot': minor +'rrweb': minor +--- + +feat: Better masking of option/radio/checkbox values diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index bb18542d26..419c20c689 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -21,7 +21,9 @@ import { isNativeShadowDom, getCssRulesString, getInputType, + getInputValue, toLowerCase, + toUpperCase, validateStringifiedCssRule, } from './utils'; @@ -514,6 +516,8 @@ function serializeNode( maskTextClass, maskTextSelector, maskTextFn, + maskInputOptions, + maskInputFn, rootId, }); case n.CDATA_SECTION_NODE: @@ -545,10 +549,19 @@ function serializeTextNode( maskTextClass: string | RegExp; maskTextSelector: string | null; maskTextFn: MaskTextFn | undefined; + maskInputOptions: MaskInputOptions; + maskInputFn: MaskInputFn | undefined; rootId: number | undefined; }, ): serializedNode { - const { maskTextClass, maskTextSelector, maskTextFn, rootId } = options; + const { + maskTextClass, + maskTextSelector, + maskTextFn, + maskInputFn, + maskInputOptions, + rootId, + } = options; // The parent node may not be a html element which has a tagName attribute. // So just let it be undefined which is ok in this use case. const parentTagName = n.parentNode && (n.parentNode as HTMLElement).tagName; @@ -590,6 +603,18 @@ function serializeTextNode( : textContent.replace(/[\S]/g, '*'); } + // Handle