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: Ensure unmaskTextSelector is used for masked attributes #81

Merged
merged 3 commits into from
Mar 17, 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
30 changes: 23 additions & 7 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ export function transformAttribute(
name: string,
value: string | null,
maskAllText: boolean,
unmaskTextSelector: string | undefined | null,
maskTextFn: MaskTextFn | undefined,
): string | null {
if (!value) {
Expand All @@ -266,20 +267,34 @@ export function transformAttribute(
return absoluteToDoc(doc, value);
} else if (
maskAllText &&
(['placeholder', 'title', 'aria-label'].indexOf(name) > -1 ||
(tagName === 'input' &&
name === 'value' &&
element.getAttribute('type') &&
['submit', 'button'].indexOf(
element.getAttribute('type')!.toLowerCase(),
) > -1))
_shouldMaskAttribute(element, name, tagName, unmaskTextSelector)
) {
return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
}

return value;
}

function _shouldMaskAttribute(
element: HTMLElement,
attribute: string,
tagName: string,
unmaskTextSelector: string | undefined | null,
): boolean {
if (unmaskTextSelector && element.matches(unmaskTextSelector)) {
return false;
}
return (
['placeholder', 'title', 'aria-label'].indexOf(attribute) > -1 ||
(tagName === 'input' &&
attribute === 'value' &&
element.hasAttribute('type') &&
['submit', 'button'].indexOf(
element.getAttribute('type')!.toLowerCase(),
) > -1)
);
}

export function _isBlockedElement(
element: HTMLElement,
blockClass: string | RegExp,
Expand Down Expand Up @@ -521,6 +536,7 @@ function serializeNode(
name,
value,
maskAllText,
unmaskTextSelector,
maskTextFn,
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/typings/snapshot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { serializedNodeWithId, INode, idNodeMap, MaskInputOptions, SlimDOMOption
export declare const IGNORED_NODE = -2;
export declare function absoluteToStylesheet(cssText: string | null, href: string): string;
export declare function absoluteToDoc(doc: Document, attributeValue: string): string;
export declare function transformAttribute(doc: Document, element: HTMLElement, tagName: string, name: string, value: string | null, maskAllText: boolean, maskTextFn: MaskTextFn | undefined): string | null;
export declare function transformAttribute(doc: Document, element: HTMLElement, tagName: string, name: string, value: string | null, maskAllText: boolean, unmaskTextSelector: string | undefined | null, maskTextFn: MaskTextFn | undefined): string | null;
export declare function _isBlockedElement(element: HTMLElement, blockClass: string | RegExp, blockSelector: string | null, unblockSelector: string | null): boolean;
export declare function needMaskingText(node: Node | null, maskTextClass: string | RegExp, maskTextSelector: string | null, unmaskTextSelector: string | null, maskAllText: boolean): boolean;
export declare function serializeNodeWithId(n: Node | INode, options: {
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 @@ -562,6 +562,7 @@ export default class MutationBuffer {
m.attributeName!,
value!,
this.maskAllText,
this.unmaskTextSelector,
this.maskTextFn
);
}
Expand Down
Loading