From 77c70537518045f777f7ac558ea8cb3fa2a3c6e7 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Sat, 15 Jun 2019 14:41:36 +0800 Subject: [PATCH] add mask all inputs option to snapshot --- src/snapshot.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/snapshot.ts b/src/snapshot.ts index da6fcf1c..0ffa96d8 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -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, ]; }