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

fix: masking on textarea #43

Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 19 additions & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,6 @@ export function transformAttribute(
} else if (maskAllText && ['placeholder', 'title', 'aria-label'].indexOf(name) > -1) {
return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
} else {
console.log({maskAllText})
return value;
}
}
Expand Down Expand Up @@ -688,6 +687,7 @@ function serializeNode(
let textContent = (n as Text).textContent;
const isStyle = parentTagName === 'STYLE' ? true : undefined;
const isScript = parentTagName === 'SCRIPT' ? true : undefined;

if (isStyle && textContent) {
try {
// try to read style sheet
Expand All @@ -709,10 +709,26 @@ function serializeNode(
}
textContent = absoluteToStylesheet(textContent, getHref());
}

if (isScript) {
textContent = 'SCRIPT_PLACEHOLDER';
}
if (

if (parentTagName === 'TEXTAREA' && textContent) {
// Ensure that textContent === attribute.value
// (masking options can make them different)
// replay will remove duplicate textContent.
textContent = maskInputValue({
input: n.parentNode as HTMLElement,
maskInputSelector,
unmaskInputSelector,
maskInputOptions,
tagName: parentTagName,
type: null,
value: textContent,
maskInputFn,
});
} else if (
!isStyle &&
!isScript &&
needMaskingText(
Expand All @@ -728,6 +744,7 @@ function serializeNode(
? maskTextFn(textContent)
: defaultMaskFn(textContent);
}

return {
type: NodeType.Text,
textContent: textContent || '',
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function maskInputValue({
value: string | null;
maskInputFn?: MaskInputFn;
}): string {
console.log('maskInputValue', tagName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this log or is it a debugging leftover?

let text = value || '';

if (unmaskInputSelector && input.matches(unmaskInputSelector)) {
Expand Down
Loading