diff --git a/guide.md b/guide.md index cb2fd1776d..12b0b387fc 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 \* | diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 8f146fac42..5cfb604b90 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -331,16 +331,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) { @@ -360,7 +362,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 { @@ -479,7 +481,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; @@ -598,7 +600,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; @@ -690,7 +692,7 @@ function serializeElementNode( rootId: number | undefined; maskAllText: boolean; maskTextClass: string | RegExp; - unmaskTextClass: string | RegExp; + unmaskTextClass: string | RegExp | null; maskTextSelector: string | null; unmaskTextSelector: string | null; }, @@ -1016,7 +1018,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; @@ -1312,7 +1314,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; @@ -1344,7 +1346,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 7113e52942..3c84ff9fe0 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -63,7 +63,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 d2cf125b87..1d649e7742 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<{ /**