Skip to content
Draft
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
1 change: 0 additions & 1 deletion packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { objectHasValue } from './utils/objectUtils'
// eslint-disable-next-line no-restricted-syntax
export enum ExperimentalFeature {
TRACK_INTAKE_REQUESTS = 'track_intake_requests',
USE_TREE_WALKER_FOR_ACTION_NAME = 'use_tree_walker_for_action_name',
FEATURE_OPERATION_VITAL = 'feature_operation_vital',
SHORT_SESSION_INVESTIGATION = 'short_session_investigation',
AVOID_FETCH_KEEPALIVE = 'avoid_fetch_keepalive',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ExperimentalFeature } from '@datadog/browser-core'
import { mockExperimentalFeatures } from '../../../../core/test'
import { appendElement, mockRumConfiguration } from '../../../test'
import { NodePrivacyLevel } from '../privacyConstants'
import { getNodeSelfPrivacyLevel } from '../privacy'
Expand Down Expand Up @@ -115,7 +113,6 @@ describe('getActionNameFromElement', () => {
})

it('should introduce whitespace for block-level display values', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
const testCases = [
{ display: 'block', expected: 'space' },
{ display: 'inline-block', expected: 'no-space' },
Expand Down Expand Up @@ -484,7 +481,6 @@ describe('getActionNameFromElement', () => {
})

it('removes only the child with programmatic action name in textual content', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
const { name, nameSource } = getActionNameFromElement(
appendElement('<div>Foobar Baz<div data-dd-action-name="custom action">bar<div></div>'),
defaultConfiguration
Expand Down Expand Up @@ -512,7 +508,6 @@ describe('getActionNameFromElement', () => {
}

it('preserves privacy level of the element when defaultPrivacyLevel is mask-unless-allowlisted', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
const { name, nameSource } = getActionNameFromElement(
appendElement(`
<div data-dd-privacy="mask">
Expand Down Expand Up @@ -666,7 +661,6 @@ describe('getActionNameFromElement', () => {
},
]
testCases.forEach(({ html, defaultPrivacyLevel, allowlist, expectedName, expectedNameSource }) => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
;(window as BrowserWindow).$DD_ALLOW = new Set(allowlist)
const target = appendElement(html)
const { name, nameSource } = getActionNameFromElement(
Expand Down Expand Up @@ -883,7 +877,6 @@ describe('getActionNameFromElement', () => {
})

it('inherit privacy level and remove only the masked child', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
expect(
getActionNameFromElement(
appendElement(`
Expand Down
55 changes: 9 additions & 46 deletions packages/rum-core/src/domain/action/getActionNameFromElement.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExperimentalFeature, isExperimentalFeatureEnabled, safeTruncate } from '@datadog/browser-core'
import { getPrivacySelector, NodePrivacyLevel } from '../privacyConstants'
import { safeTruncate } from '@datadog/browser-core'
import { NodePrivacyLevel } from '../privacyConstants'
import { getNodePrivacyLevel, maskDisallowedTextContent, shouldMaskNode, shouldMaskAttribute } from '../privacy'
import type { NodePrivacyLevelCache } from '../privacy'
import type { RumConfiguration } from '../configuration'
Expand Down Expand Up @@ -228,50 +228,13 @@ function getTextualContent(
defaultPrivacyLevel,
} = rumConfiguration

if (isExperimentalFeatureEnabled(ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME)) {
return getTextualContentWithTreeWalker(
element,
userProgrammaticAttribute,
enablePrivacyForActionName,
defaultPrivacyLevel,
nodePrivacyLevelCache
)
}

if ('innerText' in element) {
let text = (element as HTMLElement).innerText

const removeTextFromElements = (query: string) => {
const list = element.querySelectorAll<Element | HTMLElement>(query)
for (let index = 0; index < list.length; index += 1) {
const element = list[index]
if ('innerText' in element) {
const textToReplace = element.innerText
if (textToReplace && textToReplace.trim().length > 0) {
text = text.replace(textToReplace, '')
}
}
}
}

// remove the text of elements with programmatic attribute value
removeTextFromElements(`[${DEFAULT_PROGRAMMATIC_ACTION_NAME_ATTRIBUTE}]`)

if (userProgrammaticAttribute) {
removeTextFromElements(`[${userProgrammaticAttribute}]`)
}

if (enablePrivacyForActionName) {
// remove the text of elements with privacy override
removeTextFromElements(
`${getPrivacySelector(NodePrivacyLevel.HIDDEN)}, ${getPrivacySelector(NodePrivacyLevel.MASK)}`
)
}

return text
}

return element.textContent
return getTextualContentWithTreeWalker(
element,
userProgrammaticAttribute,
enablePrivacyForActionName,
defaultPrivacyLevel,
nodePrivacyLevelCache
)
}

function getTextualContentWithTreeWalker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
relativeNow,
DefaultPrivacyLevel,
Observable,
ExperimentalFeature,
} from '@datadog/browser-core'
import type { Clock } from '@datadog/browser-core/test'
import { createNewEvent, mockClock, mockExperimentalFeatures } from '@datadog/browser-core/test'
import { createNewEvent, mockClock } from '@datadog/browser-core/test'
import { createFakeClick, createMutationRecord, mockRumConfiguration } from '../../../test'
import type { AssembledRumEvent } from '../../rawRumEvent.types'
import { RumEventType, ActionType, FrustrationType } from '../../rawRumEvent.types'
Expand Down Expand Up @@ -460,7 +459,6 @@ describe('trackClickActions', () => {
})

it('should mask action name when defaultPrivacyLevel is mask_unless_allowlisted and not in allowlist', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
startClickActionsTracking({
defaultPrivacyLevel: DefaultPrivacyLevel.MASK_UNLESS_ALLOWLISTED,
enablePrivacyForActionName: true,
Expand Down Expand Up @@ -505,7 +503,6 @@ describe('trackClickActions', () => {
})

it('should use allowlist masking when defaultPrivacyLevel is allow and node privacy level is mask-unless-allowlisted', () => {
mockExperimentalFeatures([ExperimentalFeature.USE_TREE_WALKER_FOR_ACTION_NAME])
button.setAttribute('data-dd-privacy', 'mask-unless-allowlisted')
startClickActionsTracking({
defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW,
Expand Down