add mask all inputs option to snapshot

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent 06f1a28a0a
commit 6ecaaa2560

View File

@@ -100,6 +100,7 @@ function serializeNode(
doc: Document,
blockClass: string | RegExp,
inlineStylesheet: boolean,
maskAllInputs: boolean,
): serializedNode | false {
switch (n.nodeType) {
case n.DOCUMENT_NODE:
@@ -177,7 +178,7 @@ function serializeNode(
attributes.type !== 'checkbox' &&
value
) {
attributes.value = value;
attributes.value = maskAllInputs ? '*'.repeat(value.length) : value;
} else if ((n as HTMLInputElement).checked) {
attributes.checked = (n as HTMLInputElement).checked;
}
@@ -241,8 +242,15 @@ export function serializeNodeWithId(
blockClass: string | RegExp,
skipChild = false,
inlineStylesheet = true,
maskAllInputs = false,
): serializedNodeWithId | null {
const _serializedNode = serializeNode(n, doc, blockClass, inlineStylesheet);
const _serializedNode = serializeNode(
n,
doc,
blockClass,
inlineStylesheet,
maskAllInputs,
);
if (!_serializedNode) {
// TODO: dev only
console.warn(n, 'not serialized');
@@ -290,10 +298,19 @@ function snapshot(
n: Document,
blockClass: string | RegExp = 'rr-block',
inlineStylesheet = true,
maskAllInputs = false,
): [serializedNodeWithId | null, idNodeMap] {
const idNodeMap: idNodeMap = {};
return [
serializeNodeWithId(n, n, idNodeMap, blockClass, false, inlineStylesheet),
serializeNodeWithId(
n,
n,
idNodeMap,
blockClass,
false,
inlineStylesheet,
maskAllInputs,
),
idNodeMap,
];
}