Skip to content

Commit

Permalink
feat(rrweb-snapshot): mask attributes wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lewgordon-amplitude committed Oct 15, 2024
1 parent 91e937c commit 5883944
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,23 +668,35 @@ function serializeElementNode(
}
// form fields
if (tagName === 'input' || tagName === 'textarea' || tagName === 'select') {
const value = (n as HTMLInputElement | HTMLTextAreaElement).value;
const checked = (n as HTMLInputElement).checked;
if (
attributes.type !== 'radio' &&
attributes.type !== 'checkbox' &&
attributes.type !== 'submit' &&
attributes.type !== 'button' &&
value
attributes.type !== 'button'
) {
attributes.value = maskInputValue({
element: n,
type: getInputType(n),
tagName,
value,
maskInputOptions,
maskInputFn,
});
// optionally mask attributes
for (const [maskedAttributeName, shouldMaskAttribute] of Object.entries(
maskInputOptions.attributes ?? {},
)) {
if (!shouldMaskAttribute) {
continue;
}

const elementAttrValue = (n as Partial<HTMLInputElement>)[
maskedAttributeName as keyof HTMLInputElement
];
if (elementAttrValue) {
attributes.placeholder = maskInputValue({
element: n,
type: getInputType(n),
tagName,
value: String(elementAttrValue),
maskInputOptions,
maskInputFn,
});
}
}
} else if (checked) {
attributes.checked = checked;
}
Expand Down
5 changes: 5 additions & 0 deletions packages/rrweb-snapshot/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export type MaskInputOptions = Partial<{
textarea: boolean;
select: boolean;
password: boolean;

// attributes to mask
attributes: {
[k in keyof HTMLInputElement | keyof HTMLTextAreaElement]?: boolean;
};
}>;

export type SlimDOMOptions = Partial<{
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function record<T = eventWithTime>(
const maskInputOptions: MaskInputOptions =
maskAllInputs === true
? {
...(_maskInputOptions ?? {}),
color: true,
date: true,
'datetime-local': true,
Expand Down

0 comments on commit 5883944

Please sign in to comment.