Skip to content

Commit

Permalink
fix: Ensure <input type='submit' value='Btn text'> is masked (#69)
Browse files Browse the repository at this point in the history
This should be considered "Text", and should thus be masked by
`maskAllText`.

This is both for `<input type='button'>` as well as `<input
type='submit'>`.
  • Loading branch information
mydea authored Mar 1, 2023
1 parent 209abfe commit 5df2651
Show file tree
Hide file tree
Showing 6 changed files with 784 additions and 143 deletions.
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,
m.attributeName!,
value!,
this.maskAllText,
Expand Down
Loading

0 comments on commit 5df2651

Please sign in to comment.