Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added support maskInputFn with HTMLElement #1188

Merged
merged 6 commits into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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