From 3379659fbd76a2a199115b346f5725065cf4ee97 Mon Sep 17 00:00:00 2001 From: Michael Dellanoce Date: Fri, 10 Feb 2023 12:48:53 -0500 Subject: [PATCH] remove default for unmaskTextClass #1096 --- guide.md | 4 ++-- packages/rrweb-snapshot/src/snapshot.ts | 26 +++++++++++++------------ packages/rrweb/src/record/index.ts | 2 +- packages/types/src/index.ts | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/guide.md b/guide.md index 7200df1f9e..fd6267a19b 100644 --- a/guide.md +++ b/guide.md @@ -146,7 +146,7 @@ The parameter of `rrweb.record` accepts the following options. | ignoreCSSAttributes | null | array of CSS attributes that should be ignored | | maskAllText | false | mask all text content as \* | | maskTextClass | 'rr-mask' | Use a string or RegExp to configure which elements should be masked, refer to the [privacy](#privacy) chapter | -| unmaskTextClass | 'rr-unmask' | Use a string or RegExp to configure which elements should be unmasked, refer to the [privacy](#privacy) chapter | +| unmaskTextClass | null | Use a string or RegExp to configure which elements should be unmasked, refer to the [privacy](#privacy) chapter | | maskTextSelector | null | Use a string to configure which selector should be masked, refer to the [privacy](#privacy) chapter | | unmaskTextSelector | null | Use a string to configure which selector should be unmasked, refer to the [privacy](#privacy) chapter | | maskAllInputs | false | mask all input content as \* | @@ -175,7 +175,7 @@ You may find some contents on the webpage which are not willing to be recorded, - An element with the class name `.rr-block` will not be recorded. Instead, it will replay as a placeholder with the same dimension. - An element with the class name `.rr-ignore` will not record its input events. - All text of elements with the class name `.rr-mask` and their children will be masked. -- All text of elements with the class name `.rr-unmask` and their children will be unmasked, unless any child is marked with `.rr-mask`. +- All text of elements with the optional unmasking class name `unmaskTextClass` and their children will be unmasked, unless any child is marked with `.rr-mask`. - `input[type="password"]` will be masked by default. - Mask options to mask the content in input elements. diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 302c5b7512..c91cfbb996 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -343,16 +343,18 @@ function distanceToSelectorMatch(el: HTMLElement, selector: string): number { function distanceToMatch( el: HTMLElement, - className: string | RegExp, + className: string | RegExp | null, selector: string | null, ): number { let classDistance = -1; let selectorDistance = -1; - if (typeof className === 'string') { - classDistance = distanceToSelectorMatch(el, `.${className}`); - } else { - classDistance = distanceToClassRegexMatch(el, className, true); + if (className) { + if (typeof className === 'string') { + classDistance = distanceToSelectorMatch(el, `.${className}`); + } else { + classDistance = distanceToClassRegexMatch(el, className, true); + } } if (selector) { @@ -372,7 +374,7 @@ export function needMaskingText( node: Node, maskTextClass: string | RegExp, maskTextSelector: string | null, - unmaskTextClass: string | RegExp, + unmaskTextClass: string | RegExp | null, unmaskTextSelector: string | null, maskAllText: boolean, ): boolean { @@ -491,7 +493,7 @@ function serializeNode( blockSelector: string | null; maskAllText: boolean; maskTextClass: string | RegExp; - unmaskTextClass: string | RegExp; + unmaskTextClass: string | RegExp | null; maskTextSelector: string | null; unmaskTextSelector: string | null; inlineStylesheet: boolean; @@ -610,7 +612,7 @@ function serializeTextNode( options: { maskAllText: boolean; maskTextClass: string | RegExp; - unmaskTextClass: string | RegExp; + unmaskTextClass: string | RegExp | null; maskTextSelector: string | null; unmaskTextSelector: string | null; maskTextFn: MaskTextFn | undefined; @@ -702,7 +704,7 @@ function serializeElementNode( rootId: number | undefined; maskAllText: boolean; maskTextClass: string | RegExp; - unmaskTextClass: string | RegExp; + unmaskTextClass: string | RegExp | null; maskTextSelector: string | null; unmaskTextSelector: string | null; }, @@ -1041,7 +1043,7 @@ export function serializeNodeWithId( blockClass: string | RegExp; blockSelector: string | null; maskTextClass: string | RegExp; - unmaskTextClass: string | RegExp; + unmaskTextClass: string | RegExp | null; maskTextSelector: string | null; unmaskTextSelector: string | null; skipChild: boolean; @@ -1337,7 +1339,7 @@ function snapshot( blockSelector?: string | null; maskAllText?: boolean; maskTextClass?: string | RegExp; - unmaskTextClass?: string | RegExp; + unmaskTextClass?: string | RegExp | null; maskTextSelector?: string | null; unmaskTextSelector?: string | null; inlineStylesheet?: boolean; @@ -1369,7 +1371,7 @@ function snapshot( blockSelector = null, maskAllText = false, maskTextClass = 'rr-mask', - unmaskTextClass = 'rr-unmask', + unmaskTextClass = null, maskTextSelector = null, unmaskTextSelector = null, inlineStylesheet = true, diff --git a/packages/rrweb/src/record/index.ts b/packages/rrweb/src/record/index.ts index fe7776b76c..211842fb4a 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -65,7 +65,7 @@ function record( ignoreClass = 'rr-ignore', maskAllText = false, maskTextClass = 'rr-mask', - unmaskTextClass = 'rr-unmask', + unmaskTextClass = null, maskTextSelector = null, unmaskTextSelector = null, inlineStylesheet = true, diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 283eeeea63..27ab5c9819 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -179,7 +179,7 @@ export type canvasEventWithTime = eventWithTime & { export type blockClass = string | RegExp; export type maskTextClass = string | RegExp; -export type unmaskTextClass = string | RegExp; +export type unmaskTextClass = string | RegExp | null; export type SamplingStrategy = Partial<{ /**