Skip to content

Commit

Permalink
OPTIMIZATION: getTextContent to use parentNodePrivacyLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
jagracey committed Aug 9, 2021
1 parent 3fce129 commit f83811b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/rum/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export const PRIVACY_ATTR_VALUE_INPUT_MASKED = 'input-masked' // DEPRECATED, ali
export const PRIVACY_ATTR_VALUE_ALLOW = 'allow'
export const PRIVACY_ATTR_VALUE_MASK = 'mask'
export const PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY = 'mask-forms-only'
export const PRIVACY_ATTR_VALUE_HIDDEN = 'hidden' // TODO: rename to `hide`?
export const PRIVACY_ATTR_VALUE_HIDDEN = 'hidden'

// Privacy Classes - not all customers can set plain HTML attributes, so support classes too
export const PRIVACY_CLASS_ALLOW = 'dd-privacy-allow'
export const PRIVACY_CLASS_MASK = 'dd-privacy-mask'
export const PRIVACY_CLASS_MASK_FORMS_ONLY = 'dd-privacy-mask-forms-only'
export const PRIVACY_CLASS_HIDDEN = 'dd-privacy-hidden' // TODO: rename to `hide`?
export const PRIVACY_CLASS_HIDDEN = 'dd-privacy-hidden'

// Private Replacement Templates
export const CENSORED_STRING_MARK = '***'
Expand Down
11 changes: 9 additions & 2 deletions packages/rum/src/domain/record/privacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ function getAttributeEntries(attributes: NamedNodeMap) {
return attributeEntries
}

export function getTextContent(textNode: Node, ignoreWhiteSpace: boolean): string | undefined {
export function getTextContent(
textNode: Node,
ignoreWhiteSpace: boolean,
parentNodePrivacyLevel?: NodePrivacyLevelInternal
): string | undefined {
// The parent node may not be a html element which has a tagName attribute.
// So just let it be undefined which is ok in this use case.
const parentTagName = textNode.parentElement?.tagName
Expand All @@ -350,7 +354,10 @@ export function getTextContent(textNode: Node, ignoreWhiteSpace: boolean): strin
return
}

const nodePrivacyLevel = getNodePrivacyLevel(textNode.parentNode as Node)
const nodePrivacyLevel = parentNodePrivacyLevel && textNode.parentElement
? remapInternalPrivacyLevels(textNode.parentElement, parentNodePrivacyLevel)
: getNodePrivacyLevel(textNode.parentNode as Node)

const isStyle = parentTagName === 'STYLE' ? true : undefined
const isScript = parentTagName === 'SCRIPT'

Expand Down
2 changes: 1 addition & 1 deletion packages/rum/src/domain/record/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function serializeTextNode(textNode: Text, options: SerializeOptions): TextNode
// The parent node may not be a html element which has a tagName attribute.
// So just let it be undefined which is ok in this use case.
const parentTagName = textNode.parentElement?.tagName
const textContent = getTextContent(textNode, options.ignoreWhiteSpace || false)
const textContent = getTextContent(textNode, options.ignoreWhiteSpace || false, options.parentNodePrivacyLevel)
if (!textContent) {
return
}
Expand Down

0 comments on commit f83811b

Please sign in to comment.