diff --git a/guide.md b/guide.md index cb2fd1776d..3d46cf1e7d 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 \* | @@ -174,7 +174,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 5a2107e7d7..fa0a559eaf 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; }, @@ -1034,7 +1036,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; @@ -1330,7 +1332,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; @@ -1362,7 +1364,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 e8a81e6c33..65d4b80155 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<{ /**