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 <input type='submit' value='Btn text'> is masked #69

Merged
merged 2 commits into from
Mar 1, 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
18 changes: 14 additions & 4 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ function getHref() {

export function transformAttribute(
doc: Document,
element: HTMLElement,
tagName: string,
name: string,
value: string | null,
Expand Down Expand Up @@ -265,7 +266,13 @@ export function transformAttribute(
return absoluteToDoc(doc, value);
} else if (
maskAllText &&
['placeholder', 'title', 'aria-label'].indexOf(name) > -1
(['placeholder', 'title', 'aria-label'].indexOf(name) > -1 ||
(tagName === 'input' &&
name === 'value' &&
element.getAttribute('type') &&
['submit', 'button'].indexOf(
element.getAttribute('type')!.toLowerCase(),
) > -1))
) {
return maskTextFn ? maskTextFn(value) : defaultMaskFn(value);
}
Expand Down Expand Up @@ -468,8 +475,8 @@ function serializeNode(
} = options;
// Only record root id when document object is not the base document
let rootId: number | undefined;
if (((doc as unknown) as INode).__sn) {
const docId = ((doc as unknown) as INode).__sn.id;
if ((doc as unknown as INode).__sn) {
const docId = (doc as unknown as INode).__sn.id;
rootId = docId === 1 ? undefined : docId;
}
switch (n.nodeType) {
Expand Down Expand Up @@ -509,6 +516,7 @@ function serializeNode(
if (!skipAttribute(tagName, name, value)) {
attributes[name] = transformAttribute(
doc,
n as HTMLElement,
tagName,
name,
value,
Expand Down Expand Up @@ -773,7 +781,9 @@ function serializeNode(
}
}

function lowerIfExists(maybeAttr: string | number | boolean | null | undefined): string {
function lowerIfExists(
maybeAttr: string | number | boolean | null | undefined,
): string {
if (maybeAttr === undefined || maybeAttr === null) {
return '';
} else {
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, 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, 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
4 changes: 3 additions & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,11 @@ export default class MutationBuffer {
}
} else {
// overwrite attribute if the mutations was triggered in same time
const element = m.target as HTMLElement;
item.attributes[m.attributeName!] = transformAttribute(
this.doc,
(m.target as HTMLElement).tagName,
element,
element.tagName,
Comment on lines +549 to +550
Copy link
Member

Choose a reason for hiding this comment

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

l: We probably don't need both of these parameters

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I thought the same, wasn't sure - in one call site there is this getValidTagName method, not sure if we need this here...?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can always revisit this/clean this up later.

m.attributeName!,
value!,
this.maskAllText,
Expand Down
Loading