Add record option maskInputFn for custom mask input function (#409)

This commit is contained in:
Yaozu Lv
2020-11-15 16:39:17 +08:00
committed by GitHub
parent 5c9919e481
commit a2cd3e2da0
3 changed files with 14 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ function record<T = eventWithTime>(
inlineStylesheet = true, inlineStylesheet = true,
maskAllInputs, maskAllInputs,
maskInputOptions: _maskInputOptions, maskInputOptions: _maskInputOptions,
maskInputFn,
hooks, hooks,
packFn, packFn,
sampling = {}, sampling = {},
@@ -293,6 +294,7 @@ function record<T = eventWithTime>(
blockClass, blockClass,
ignoreClass, ignoreClass,
maskInputOptions, maskInputOptions,
maskInputFn,
inlineStylesheet, inlineStylesheet,
sampling, sampling,
recordCanvas, recordCanvas,

View File

@@ -35,6 +35,7 @@ import {
canvasMutationCallback, canvasMutationCallback,
fontCallback, fontCallback,
fontParam, fontParam,
MaskInputFn,
} from '../types'; } from '../types';
import MutationBuffer from './mutation'; import MutationBuffer from './mutation';
@@ -223,6 +224,7 @@ function initInputObserver(
blockClass: blockClass, blockClass: blockClass,
ignoreClass: string, ignoreClass: string,
maskInputOptions: MaskInputOptions, maskInputOptions: MaskInputOptions,
maskInputFn: MaskInputFn | undefined,
sampling: SamplingStrategy, sampling: SamplingStrategy,
): listenerHandler { ): listenerHandler {
function eventHandler(event: Event) { function eventHandler(event: Event) {
@@ -252,7 +254,11 @@ function initInputObserver(
] || ] ||
maskInputOptions[type as keyof MaskInputOptions] maskInputOptions[type as keyof MaskInputOptions]
) { ) {
text = '*'.repeat(text.length); if(maskInputFn) {
text = maskInputFn(text)
} else {
text = '*'.repeat(text.length);
}
} }
cbWithDedup(target, { text, isChecked }); cbWithDedup(target, { text, isChecked });
// if a radio was checked // if a radio was checked
@@ -593,6 +599,7 @@ export function initObservers(
o.blockClass, o.blockClass,
o.ignoreClass, o.ignoreClass,
o.maskInputOptions, o.maskInputOptions,
o.maskInputFn,
o.sampling, o.sampling,
); );
const mediaInteractionHandler = initMediaInteractionObserver( const mediaInteractionHandler = initMediaInteractionObserver(

View File

@@ -174,6 +174,7 @@ export type recordOptions<T> = {
ignoreClass?: string; ignoreClass?: string;
maskAllInputs?: boolean; maskAllInputs?: boolean;
maskInputOptions?: MaskInputOptions; maskInputOptions?: MaskInputOptions;
maskInputFn?: MaskInputFn;
inlineStylesheet?: boolean; inlineStylesheet?: boolean;
hooks?: hooksParam; hooks?: hooksParam;
packFn?: PackFn; packFn?: PackFn;
@@ -195,6 +196,7 @@ export type observerParam = {
blockClass: blockClass; blockClass: blockClass;
ignoreClass: string; ignoreClass: string;
maskInputOptions: MaskInputOptions; maskInputOptions: MaskInputOptions;
maskInputFn?: MaskInputFn;
inlineStylesheet: boolean; inlineStylesheet: boolean;
styleSheetRuleCb: styleSheetRuleCallback; styleSheetRuleCb: styleSheetRuleCallback;
canvasMutationCb: canvasMutationCallback; canvasMutationCb: canvasMutationCallback;
@@ -461,3 +463,5 @@ export enum ReplayerEvents {
Flush = 'flush', Flush = 'flush',
StateChange = 'state-change', StateChange = 'state-change',
} }
export type MaskInputFn = (text: string) => string;