Skip to content

Commit

Permalink
feat: Added support maskInputFn with HTMLElement (rrweb-io#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored and eoghanmurray committed Aug 8, 2023
1 parent c7d7a4b commit d294a71
Show file tree
Hide file tree
Showing 11 changed files with 917 additions and 9 deletions.
6 changes: 6 additions & 0 deletions .changeset/nervous-tables-travel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'rrweb-snapshot': minor
'rrweb': minor
---

feat: Extends maskInputFn to pass the HTMLElement to the deciding function
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ function serializeElementNode(
) {
const type = getInputType(n);
attributes.value = maskInputValue({
element: n,
type,
tagName,
value,
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export type DataURLOptions = Partial<{
}>;

export type MaskTextFn = (text: string) => string;
export type MaskInputFn = (text: string) => string;
export type MaskInputFn = (text: string, element: HTMLElement) => string;

export type KeepIframeSrcFn = (src: string) => boolean;

Expand Down
4 changes: 3 additions & 1 deletion packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,14 @@ export function createMirror(): Mirror {
}

export function maskInputValue({
element,
maskInputOptions,
tagName,
type,
value,
maskInputFn,
}: {
element: HTMLElement;
maskInputOptions: MaskInputOptions;
tagName: string;
type: string | null;
Expand All @@ -174,7 +176,7 @@ export function maskInputValue({
(actualType && maskInputOptions[actualType as keyof MaskInputOptions])
) {
if (maskInputFn) {
text = maskInputFn(text);
text = maskInputFn(text, element);
} else {
text = '*'.repeat(text.length);
}
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ export default class MutationBuffer {
const type = getInputType(target);

value = maskInputValue({
element: target,
maskInputOptions: this.maskInputOptions,
tagName: target.tagName,
type,
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ function initInputObserver({
maskInputOptions[type as keyof MaskInputOptions]
) {
text = maskInputValue({
element: target,
maskInputOptions,
tagName,
type,
Expand Down
Loading

0 comments on commit d294a71

Please sign in to comment.