diff --git a/packages/core/src/domain/configuration/configuration.ts b/packages/core/src/domain/configuration/configuration.ts index 71c575a038..c8a3ba21c3 100644 --- a/packages/core/src/domain/configuration/configuration.ts +++ b/packages/core/src/domain/configuration/configuration.ts @@ -4,12 +4,12 @@ import { catchUserErrors } from '../../tools/catchUserErrors' import { includes, objectHasValue, ONE_KILO_BYTE, ONE_SECOND } from '../../tools/utils' import { computeTransportConfiguration, TransportConfiguration } from './transportConfiguration' -export const InitialPrivacyLevel = { +export const DefaultPrivacyLevel = { ALLOW: 'allow', MASK: 'mask', - MASK_FORMS_ONLY: 'mask-forms-only', + MASK_USER_INPUT: 'mask-user-input', } as const -export type InitialPrivacyLevel = typeof InitialPrivacyLevel[keyof typeof InitialPrivacyLevel] +export type DefaultPrivacyLevel = typeof DefaultPrivacyLevel[keyof typeof DefaultPrivacyLevel] export const DEFAULT_CONFIGURATION = { allowedTracingOrigins: [] as Array, @@ -21,7 +21,7 @@ export const DEFAULT_CONFIGURATION = { silentMultipleInit: false, trackInteractions: false, trackViewsManually: false, - initialPrivacyLevel: InitialPrivacyLevel.ALLOW as InitialPrivacyLevel, + defaultPrivacyLevel: DefaultPrivacyLevel.MASK_USER_INPUT as DefaultPrivacyLevel, /** * arbitrary value, byte precision not needed @@ -67,7 +67,7 @@ export interface InitConfiguration { proxyHost?: string proxyUrl?: string beforeSend?: BeforeSendCallback - initialPrivacyLevel?: InitialPrivacyLevel + defaultPrivacyLevel?: DefaultPrivacyLevel service?: string env?: string @@ -143,11 +143,8 @@ export function buildConfiguration(initConfiguration: InitConfiguration, buildEn configuration.actionNameAttribute = initConfiguration.actionNameAttribute } - if ( - configuration.isEnabled('initial-privacy-level-option') && - objectHasValue(InitialPrivacyLevel, initConfiguration.initialPrivacyLevel) - ) { - configuration.initialPrivacyLevel = initConfiguration.initialPrivacyLevel + if (objectHasValue(DefaultPrivacyLevel, initConfiguration.defaultPrivacyLevel)) { + configuration.defaultPrivacyLevel = initConfiguration.defaultPrivacyLevel } return configuration diff --git a/packages/core/src/domain/configuration/index.ts b/packages/core/src/domain/configuration/index.ts index 7070394dda..3a3c448b47 100644 --- a/packages/core/src/domain/configuration/index.ts +++ b/packages/core/src/domain/configuration/index.ts @@ -4,6 +4,6 @@ export { InitConfiguration, buildCookieOptions, BeforeSendCallback, - InitialPrivacyLevel, + DefaultPrivacyLevel, buildConfiguration, } from './configuration' diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 6e616d2be6..5d2919786c 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -4,7 +4,7 @@ export { InitConfiguration, buildCookieOptions, BeforeSendCallback, - InitialPrivacyLevel, + DefaultPrivacyLevel, } from './domain/configuration' export { trackConsoleError } from './domain/error/trackConsoleError' export { trackRuntimeError } from './domain/error/trackRuntimeError' diff --git a/packages/rum-core/src/boot/rumPublicApi.spec.ts b/packages/rum-core/src/boot/rumPublicApi.spec.ts index b6c59574b8..b4639ee030 100644 --- a/packages/rum-core/src/boot/rumPublicApi.spec.ts +++ b/packages/rum-core/src/boot/rumPublicApi.spec.ts @@ -1,4 +1,4 @@ -import { ONE_SECOND, RelativeTime, getTimeStamp, display, TimeStamp, InitialPrivacyLevel } from '@datadog/browser-core' +import { ONE_SECOND, RelativeTime, getTimeStamp, display, TimeStamp, DefaultPrivacyLevel } from '@datadog/browser-core' import { noopRecorderApi, setup, TestSetupBuilder } from '../../test/specHelper' import { ActionType } from '../rawRumEvent.types' import { makeRumPublicApi, RumPublicApi, RumInitConfiguration, StartRum, RecorderApi } from './rumPublicApi' @@ -668,30 +668,19 @@ describe('rum public api', () => { setupBuilder.cleanup() }) - it('recording is started with the default initialPrivacyLevel', () => { + it('recording is started with the default defaultPrivacyLevel', () => { rumPublicApi.init(DEFAULT_INIT_CONFIGURATION) - expect(recorderApiOnRumStartSpy.calls.mostRecent().args[2].initialPrivacyLevel).toBe(InitialPrivacyLevel.ALLOW) - }) - - describe('initial-privacy-level-option feature enabled', () => { - it('recording is started with the configured initialPrivacyLevel', () => { - rumPublicApi.init({ - ...DEFAULT_INIT_CONFIGURATION, - initialPrivacyLevel: InitialPrivacyLevel.MASK, - enableExperimentalFeatures: ['initial-privacy-level-option'], - }) - expect(recorderApiOnRumStartSpy.calls.mostRecent().args[2].initialPrivacyLevel).toBe(InitialPrivacyLevel.MASK) - }) + expect(recorderApiOnRumStartSpy.calls.mostRecent().args[2].defaultPrivacyLevel).toBe( + DefaultPrivacyLevel.MASK_USER_INPUT + ) }) - describe('initial-privacy-level-option feature disabled', () => { - it('recording ignores the configured initialPrivacyLevel', () => { - rumPublicApi.init({ - ...DEFAULT_INIT_CONFIGURATION, - initialPrivacyLevel: InitialPrivacyLevel.MASK, - }) - expect(recorderApiOnRumStartSpy.calls.mostRecent().args[2].initialPrivacyLevel).toBe(InitialPrivacyLevel.ALLOW) + it('recording is started with the configured defaultPrivacyLevel', () => { + rumPublicApi.init({ + ...DEFAULT_INIT_CONFIGURATION, + defaultPrivacyLevel: DefaultPrivacyLevel.MASK, }) + expect(recorderApiOnRumStartSpy.calls.mostRecent().args[2].defaultPrivacyLevel).toBe(DefaultPrivacyLevel.MASK) }) }) }) diff --git a/packages/rum-core/src/boot/rumPublicApi.ts b/packages/rum-core/src/boot/rumPublicApi.ts index b7ff7d1df2..79ae9f89fc 100644 --- a/packages/rum-core/src/boot/rumPublicApi.ts +++ b/packages/rum-core/src/boot/rumPublicApi.ts @@ -18,7 +18,7 @@ import { InternalMonitoring, callMonitored, createHandlingStack, - InitialPrivacyLevel, + DefaultPrivacyLevel, } from '@datadog/browser-core' import { LifeCycle } from '../domain/lifeCycle' import { ParentContexts } from '../domain/parentContexts' @@ -32,7 +32,7 @@ import { startRum } from './startRum' export interface RumInitConfiguration extends InitConfiguration { applicationId: string beforeSend?: (event: RumEvent, context: RumEventDomainContext) => void | boolean - initialPrivacyLevel?: InitialPrivacyLevel + defaultPrivacyLevel?: DefaultPrivacyLevel } export type RumPublicApi = ReturnType diff --git a/packages/rum-slim/src/index.ts b/packages/rum-slim/src/index.ts index 7032320b52..5cbafd22cd 100644 --- a/packages/rum-slim/src/index.ts +++ b/packages/rum-slim/src/index.ts @@ -21,4 +21,4 @@ export { RumOtherResourceEventDomainContext, RumLongTaskEventDomainContext, } from '@datadog/browser-rum-core' -export { InitialPrivacyLevel } from '@datadog/browser-core' +export { DefaultPrivacyLevel } from '@datadog/browser-core' diff --git a/packages/rum/src/boot/startRecording.spec.ts b/packages/rum/src/boot/startRecording.spec.ts index 848f40433a..522ff5035e 100644 --- a/packages/rum/src/boot/startRecording.spec.ts +++ b/packages/rum/src/boot/startRecording.spec.ts @@ -1,4 +1,4 @@ -import { HttpRequest } from '@datadog/browser-core' +import { HttpRequest, DefaultPrivacyLevel } from '@datadog/browser-core' import { LifeCycle, LifeCycleEventType } from '@datadog/browser-rum-core' import { inflate } from 'pako' import { createRumSessionMock, RumSessionMock } from '../../../rum-core/test/mockRumSession' @@ -52,6 +52,9 @@ describe('startRecording', () => { }, }) .withSession(session) + .withConfiguration({ + defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW, + }) .beforeBuild(({ lifeCycle, applicationId, configuration, parentContexts, session }) => { ;({ stop: stopRecording } = startRecording(lifeCycle, applicationId, configuration, session, parentContexts)) return { stop: stopRecording } diff --git a/packages/rum/src/boot/startRecording.ts b/packages/rum/src/boot/startRecording.ts index bda6432618..3e47e931ee 100644 --- a/packages/rum/src/boot/startRecording.ts +++ b/packages/rum/src/boot/startRecording.ts @@ -28,7 +28,7 @@ export function startRecording( const { stop: stopRecording, takeFullSnapshot, flushMutations } = record({ emit: addRawRecord, - initialPrivacyLevel: configuration.initialPrivacyLevel, + defaultPrivacyLevel: configuration.defaultPrivacyLevel, }) const { unsubscribe: unsubscribeViewEnded } = lifeCycle.subscribe(LifeCycleEventType.VIEW_ENDED, () => { diff --git a/packages/rum/src/constants.ts b/packages/rum/src/constants.ts index 9551e27d48..754713da87 100644 --- a/packages/rum/src/constants.ts +++ b/packages/rum/src/constants.ts @@ -1,7 +1,7 @@ -import { InitialPrivacyLevel } from '@datadog/browser-core' +import { DefaultPrivacyLevel } from '@datadog/browser-core' export const NodePrivacyLevel = { - ...InitialPrivacyLevel, + ...DefaultPrivacyLevel, IGNORE: 'ignore', HIDDEN: 'hidden', } as const @@ -10,21 +10,21 @@ export type NodePrivacyLevel = typeof NodePrivacyLevel[keyof typeof NodePrivacyL export const PRIVACY_ATTR_NAME = 'data-dd-privacy' // Deprecate via temporary Alias -export const PRIVACY_CLASS_INPUT_IGNORED = 'dd-privacy-input-ignored' // DEPRECATED, aliased to mask-forms-only -export const PRIVACY_CLASS_INPUT_MASKED = 'dd-privacy-input-masked' // DEPRECATED, aliased to mask-forms-only -export const PRIVACY_ATTR_VALUE_INPUT_IGNORED = 'input-ignored' // DEPRECATED, aliased to mask-forms-only -export const PRIVACY_ATTR_VALUE_INPUT_MASKED = 'input-masked' // DEPRECATED, aliased to mask-forms-only +export const PRIVACY_CLASS_INPUT_IGNORED = 'dd-privacy-input-ignored' // DEPRECATED, aliased to mask-user-input +export const PRIVACY_CLASS_INPUT_MASKED = 'dd-privacy-input-masked' // DEPRECATED, aliased to mask-user-input +export const PRIVACY_ATTR_VALUE_INPUT_IGNORED = 'input-ignored' // DEPRECATED, aliased to mask-user-input +export const PRIVACY_ATTR_VALUE_INPUT_MASKED = 'input-masked' // DEPRECATED, aliased to mask-user-input // Privacy Attrs 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_MASK_USER_INPUT = 'mask-user-input' 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_MASK_USER_INPUT = 'dd-privacy-mask-user-input' export const PRIVACY_CLASS_HIDDEN = 'dd-privacy-hidden' // Private Replacement Templates diff --git a/packages/rum/src/domain/record/mutationObserver.spec.ts b/packages/rum/src/domain/record/mutationObserver.spec.ts index 29f1ee582e..35e69a5cad 100644 --- a/packages/rum/src/domain/record/mutationObserver.spec.ts +++ b/packages/rum/src/domain/record/mutationObserver.spec.ts @@ -1,4 +1,4 @@ -import { InitialPrivacyLevel } from '@datadog/browser-core' +import { DefaultPrivacyLevel } from '@datadog/browser-core' import { isIE } from '../../../../core/test/specHelper' import { collectAsyncCalls, createMutationPayloadValidator } from '../../../test/utils' import { @@ -8,7 +8,7 @@ import { PRIVACY_ATTR_VALUE_INPUT_IGNORED, PRIVACY_ATTR_VALUE_INPUT_MASKED, PRIVACY_ATTR_VALUE_MASK, - PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY, + PRIVACY_ATTR_VALUE_MASK_USER_INPUT, } from '../../constants' import { serializeDocument } from './serialize' import { sortAddedAndMovedNodes, startMutationObserver, MutationController } from './mutationObserver' @@ -18,14 +18,14 @@ describe('startMutationCollection', () => { let sandbox: HTMLElement let stopMutationCollection: () => void - function startMutationCollection(initialPrivacyLevel: InitialPrivacyLevel = InitialPrivacyLevel.ALLOW) { + function startMutationCollection(defaultPrivacyLevel: DefaultPrivacyLevel = DefaultPrivacyLevel.ALLOW) { const mutationCallbackSpy = jasmine.createSpy() const mutationController = new MutationController() ;({ stop: stopMutationCollection } = startMutationObserver( mutationController, mutationCallbackSpy, - initialPrivacyLevel + defaultPrivacyLevel )) return { @@ -401,9 +401,9 @@ describe('startMutationCollection', () => { }) }) - it('respects the initial privacy level setting', () => { + it('respects the default privacy level setting', () => { const serializedDocument = serializeDocument(document, NodePrivacyLevel.ALLOW) - const { mutationController, getLatestMutationPayload } = startMutationCollection(InitialPrivacyLevel.MASK) + const { mutationController, getLatestMutationPayload } = startMutationCollection(DefaultPrivacyLevel.MASK) sandbox.innerText = 'foo bar' mutationController.flush() @@ -462,9 +462,9 @@ describe('startMutationCollection', () => { expect(mutationCallbackSpy).not.toHaveBeenCalled() }) - it('respects the initial privacy level setting', () => { + it('respects the default privacy level setting', () => { const serializedDocument = serializeDocument(document, NodePrivacyLevel.ALLOW) - const { mutationController, getLatestMutationPayload } = startMutationCollection(InitialPrivacyLevel.MASK) + const { mutationController, getLatestMutationPayload } = startMutationCollection(DefaultPrivacyLevel.MASK) textNode.data = 'foo bar' mutationController.flush() @@ -491,7 +491,7 @@ describe('startMutationCollection', () => { const serializedDocument = serializeDocument(document, NodePrivacyLevel.MASK) const { mutationController, mutationCallbackSpy, getLatestMutationPayload } = startMutationCollection( - InitialPrivacyLevel.MASK + DefaultPrivacyLevel.MASK ) div.firstChild!.textContent = 'bazz 7' @@ -563,9 +563,9 @@ describe('startMutationCollection', () => { }) }) - it('respects the initial privacy level setting', () => { + it('respects the default privacy level setting', () => { const serializedDocument = serializeDocument(document, NodePrivacyLevel.ALLOW) - const { mutationController, getLatestMutationPayload } = startMutationCollection(InitialPrivacyLevel.MASK) + const { mutationController, getLatestMutationPayload } = startMutationCollection(DefaultPrivacyLevel.MASK) sandbox.setAttribute('data-foo', 'biz') mutationController.flush() @@ -812,10 +812,10 @@ describe('startMutationCollection', () => { expectedAttributesMutation: { value: '***' }, }, { - privacyAttributeValue: PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY, + privacyAttributeValue: PRIVACY_ATTR_VALUE_MASK_USER_INPUT, privacyAttributeOn: 'input', expectedSerializedAttributes: { - [PRIVACY_ATTR_NAME]: PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY, + [PRIVACY_ATTR_NAME]: PRIVACY_ATTR_VALUE_MASK_USER_INPUT, value: '***', }, expectedAttributesMutation: { value: '***' }, @@ -848,7 +848,7 @@ describe('startMutationCollection', () => { expectedAttributesMutation: { value: '***' }, }, { - privacyAttributeValue: PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY, + privacyAttributeValue: PRIVACY_ATTR_VALUE_MASK_USER_INPUT, privacyAttributeOn: 'ancestor', expectedSerializedAttributes: { value: '***' }, expectedAttributesMutation: { value: '***' }, diff --git a/packages/rum/src/domain/record/mutationObserver.ts b/packages/rum/src/domain/record/mutationObserver.ts index abd9cc8847..4b61c8eac0 100644 --- a/packages/rum/src/domain/record/mutationObserver.ts +++ b/packages/rum/src/domain/record/mutationObserver.ts @@ -1,4 +1,4 @@ -import { InitialPrivacyLevel, monitor, noop } from '@datadog/browser-core' +import { DefaultPrivacyLevel, monitor, noop } from '@datadog/browser-core' import { getMutationObserverConstructor } from '@datadog/browser-rum-core' import { NodePrivacyLevel } from '../../constants' import { getNodePrivacyLevel, getTextContent } from './privacy' @@ -32,7 +32,7 @@ type WithSerializedTarget = T & { target: NodeWithSerializedNode } export function startMutationObserver( controller: MutationController, mutationCallback: MutationCallBack, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { const MutationObserver = getMutationObserverConstructor() if (!MutationObserver) { @@ -42,7 +42,7 @@ export function startMutationObserver( processMutations( mutations.concat(observer.takeRecords() as RumMutationRecord[]), mutationCallback, - initialPrivacyLevel + defaultPrivacyLevel ) }) @@ -84,7 +84,7 @@ export class MutationController { function processMutations( mutations: RumMutationRecord[], mutationCallback: MutationCallBack, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { // Discard any mutation with a 'target' node that: // * isn't injected in the current document or isn't known/serialized yet: those nodes are likely @@ -94,14 +94,14 @@ function processMutations( (mutation): mutation is WithSerializedTarget => document.contains(mutation.target) && nodeAndAncestorsHaveSerializedNode(mutation.target) && - getNodePrivacyLevel(mutation.target, initialPrivacyLevel) !== NodePrivacyLevel.HIDDEN + getNodePrivacyLevel(mutation.target, defaultPrivacyLevel) !== NodePrivacyLevel.HIDDEN ) const { adds, removes, hasBeenSerialized } = processChildListMutations( filteredMutations.filter( (mutation): mutation is WithSerializedTarget => mutation.type === 'childList' ), - initialPrivacyLevel + defaultPrivacyLevel ) const texts = processCharacterDataMutations( @@ -109,7 +109,7 @@ function processMutations( (mutation): mutation is WithSerializedTarget => mutation.type === 'characterData' && !hasBeenSerialized(mutation.target) ), - initialPrivacyLevel + defaultPrivacyLevel ) const attributes = processAttributesMutations( @@ -117,7 +117,7 @@ function processMutations( (mutation): mutation is WithSerializedTarget => mutation.type === 'attributes' && !hasBeenSerialized(mutation.target) ), - initialPrivacyLevel + defaultPrivacyLevel ) if (!texts.length && !attributes.length && !removes.length && !adds.length) { @@ -134,7 +134,7 @@ function processMutations( function processChildListMutations( mutations: Array>, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { // First, we iterate over mutations to collect: // @@ -184,7 +184,7 @@ function processChildListMutations( continue } - const parentNodePrivacyLevel = getNodePrivacyLevel(node.parentNode!, initialPrivacyLevel) + const parentNodePrivacyLevel = getNodePrivacyLevel(node.parentNode!, defaultPrivacyLevel) if (parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === NodePrivacyLevel.IGNORE) { continue } @@ -236,7 +236,7 @@ function processChildListMutations( function processCharacterDataMutations( mutations: Array>, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { const textMutations: TextMutation[] = [] @@ -257,7 +257,7 @@ function processCharacterDataMutations( continue } - const parentNodePrivacyLevel = getNodePrivacyLevel(mutation.target.parentNode!, initialPrivacyLevel) + const parentNodePrivacyLevel = getNodePrivacyLevel(mutation.target.parentNode!, defaultPrivacyLevel) if (parentNodePrivacyLevel === NodePrivacyLevel.HIDDEN || parentNodePrivacyLevel === NodePrivacyLevel.IGNORE) { continue } @@ -274,7 +274,7 @@ function processCharacterDataMutations( function processAttributesMutations( mutations: Array>, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { const attributeMutations: AttributeMutation[] = [] @@ -300,7 +300,7 @@ function processAttributesMutations( if (uncensoredValue === mutation.oldValue) { continue } - const privacyLevel = getNodePrivacyLevel(mutation.target, initialPrivacyLevel) + const privacyLevel = getNodePrivacyLevel(mutation.target, defaultPrivacyLevel) const attributeValue = serializeAttribute(mutation.target, privacyLevel, mutation.attributeName!) let transformedValue: string | null diff --git a/packages/rum/src/domain/record/observer.spec.ts b/packages/rum/src/domain/record/observer.spec.ts index e734cb75ed..11725382e2 100644 --- a/packages/rum/src/domain/record/observer.spec.ts +++ b/packages/rum/src/domain/record/observer.spec.ts @@ -1,4 +1,4 @@ -import { InitialPrivacyLevel } from '@datadog/browser-core' +import { DefaultPrivacyLevel } from '@datadog/browser-core' import { createNewEvent, isIE } from '../../../../core/test/specHelper' import { NodePrivacyLevel, PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_INPUT_MASKED } from '../../constants' import { initInputObserver } from './observer' @@ -31,7 +31,7 @@ describe('initInputObserver', () => { }) it('collects input values when an "input" event is dispatched', () => { - stopInputObserver = initInputObserver(inputCallbackSpy, InitialPrivacyLevel.ALLOW) + stopInputObserver = initInputObserver(inputCallbackSpy, DefaultPrivacyLevel.ALLOW) dispatchInputEvent('foo') expect(inputCallbackSpy).toHaveBeenCalledOnceWith({ @@ -41,7 +41,7 @@ describe('initInputObserver', () => { }) it('masks input values according to the element privacy level', () => { - stopInputObserver = initInputObserver(inputCallbackSpy, InitialPrivacyLevel.ALLOW) + stopInputObserver = initInputObserver(inputCallbackSpy, DefaultPrivacyLevel.ALLOW) sandbox.setAttribute(PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_INPUT_MASKED) dispatchInputEvent('foo') @@ -50,7 +50,7 @@ describe('initInputObserver', () => { }) it('masks input values according to a parent element privacy level', () => { - stopInputObserver = initInputObserver(inputCallbackSpy, InitialPrivacyLevel.ALLOW) + stopInputObserver = initInputObserver(inputCallbackSpy, DefaultPrivacyLevel.ALLOW) input.setAttribute(PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_INPUT_MASKED) dispatchInputEvent('foo') @@ -58,8 +58,8 @@ describe('initInputObserver', () => { expect((inputCallbackSpy.calls.first().args[0] as { text?: string }).text).toBe('***') }) - it('masks input values according to a the initial privacy level', () => { - stopInputObserver = initInputObserver(inputCallbackSpy, InitialPrivacyLevel.MASK) + it('masks input values according to a the default privacy level', () => { + stopInputObserver = initInputObserver(inputCallbackSpy, DefaultPrivacyLevel.MASK) dispatchInputEvent('foo') diff --git a/packages/rum/src/domain/record/observer.ts b/packages/rum/src/domain/record/observer.ts index e2c21d49fd..b9e9099664 100644 --- a/packages/rum/src/domain/record/observer.ts +++ b/packages/rum/src/domain/record/observer.ts @@ -6,7 +6,7 @@ import { addEventListeners, addEventListener, includes, - InitialPrivacyLevel, + DefaultPrivacyLevel, } from '@datadog/browser-core' import { NodePrivacyLevel } from '../../constants' import { getNodePrivacyLevel, shouldMaskNode } from './privacy' @@ -36,13 +36,13 @@ const MOUSE_MOVE_OBSERVER_THRESHOLD = 50 const SCROLL_OBSERVER_THRESHOLD = 100 export function initObservers(o: ObserverParam): ListenerHandler { - const mutationHandler = initMutationObserver(o.mutationController, o.mutationCb, o.initialPrivacyLevel) + const mutationHandler = initMutationObserver(o.mutationController, o.mutationCb, o.defaultPrivacyLevel) const mousemoveHandler = initMoveObserver(o.mousemoveCb) - const mouseInteractionHandler = initMouseInteractionObserver(o.mouseInteractionCb, o.initialPrivacyLevel) - const scrollHandler = initScrollObserver(o.scrollCb, o.initialPrivacyLevel) + const mouseInteractionHandler = initMouseInteractionObserver(o.mouseInteractionCb, o.defaultPrivacyLevel) + const scrollHandler = initScrollObserver(o.scrollCb, o.defaultPrivacyLevel) const viewportResizeHandler = initViewportResizeObserver(o.viewportResizeCb) - const inputHandler = initInputObserver(o.inputCb, o.initialPrivacyLevel) - const mediaInteractionHandler = initMediaInteractionObserver(o.mediaInteractionCb, o.initialPrivacyLevel) + const inputHandler = initInputObserver(o.inputCb, o.defaultPrivacyLevel) + const mediaInteractionHandler = initMediaInteractionObserver(o.mediaInteractionCb, o.defaultPrivacyLevel) const styleSheetObserver = initStyleSheetObserver(o.styleSheetRuleCb) const focusHandler = initFocusObserver(o.focusCb) @@ -62,9 +62,9 @@ export function initObservers(o: ObserverParam): ListenerHandler { function initMutationObserver( mutationController: MutationController, cb: MutationCallBack, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ) { - return startMutationObserver(mutationController, cb, initialPrivacyLevel).stop + return startMutationObserver(mutationController, cb, defaultPrivacyLevel).stop } function initMoveObserver(cb: MousemoveCallBack): ListenerHandler { @@ -107,11 +107,11 @@ const eventTypeToMouseInteraction = { } function initMouseInteractionObserver( cb: MouseInteractionCallBack, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ): ListenerHandler { const handler = (event: MouseEvent | TouchEvent) => { const target = event.target as Node - if (getNodePrivacyLevel(target, initialPrivacyLevel) === NodePrivacyLevel.HIDDEN || !hasSerializedNode(target)) { + if (getNodePrivacyLevel(target, defaultPrivacyLevel) === NodePrivacyLevel.HIDDEN || !hasSerializedNode(target)) { return } const { clientX, clientY } = isTouchEvent(event) ? event.changedTouches[0] : event @@ -128,13 +128,13 @@ function initMouseInteractionObserver( }).stop } -function initScrollObserver(cb: ScrollCallback, initialPrivacyLevel: InitialPrivacyLevel): ListenerHandler { +function initScrollObserver(cb: ScrollCallback, defaultPrivacyLevel: DefaultPrivacyLevel): ListenerHandler { const { throttled: updatePosition } = throttle( monitor((event: UIEvent) => { const target = event.target as HTMLElement | Document if ( !target || - getNodePrivacyLevel(target, initialPrivacyLevel) === NodePrivacyLevel.HIDDEN || + getNodePrivacyLevel(target, defaultPrivacyLevel) === NodePrivacyLevel.HIDDEN || !hasSerializedNode(target) ) { return @@ -177,10 +177,10 @@ function initViewportResizeObserver(cb: ViewportResizeCallback): ListenerHandler export const INPUT_TAGS = ['INPUT', 'TEXTAREA', 'SELECT'] const lastInputStateMap: WeakMap = new WeakMap() -export function initInputObserver(cb: InputCallback, initialPrivacyLevel: InitialPrivacyLevel): ListenerHandler { +export function initInputObserver(cb: InputCallback, defaultPrivacyLevel: DefaultPrivacyLevel): ListenerHandler { function eventHandler(event: { target: EventTarget | null }) { const target = event.target as HTMLInputElement | HTMLTextAreaElement - const nodePrivacyLevel = getNodePrivacyLevel(target, initialPrivacyLevel) + const nodePrivacyLevel = getNodePrivacyLevel(target, defaultPrivacyLevel) if ( !target || !target.tagName || @@ -314,13 +314,13 @@ function initStyleSheetObserver(cb: StyleSheetRuleCallback): ListenerHandler { function initMediaInteractionObserver( mediaInteractionCb: MediaInteractionCallback, - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel ): ListenerHandler { const handler = (event: Event) => { const target = event.target as Node if ( !target || - getNodePrivacyLevel(target, initialPrivacyLevel) === NodePrivacyLevel.HIDDEN || + getNodePrivacyLevel(target, defaultPrivacyLevel) === NodePrivacyLevel.HIDDEN || !hasSerializedNode(target) ) { return diff --git a/packages/rum/src/domain/record/privacy.spec.ts b/packages/rum/src/domain/record/privacy.spec.ts index 65d900bdbb..d17b210469 100644 --- a/packages/rum/src/domain/record/privacy.spec.ts +++ b/packages/rum/src/domain/record/privacy.spec.ts @@ -79,33 +79,33 @@ describe('privacy helpers', () => { expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.ALLOW) expect(getNodePrivacyLevel(node, NodePrivacyLevel.IGNORE)).toBe(NodePrivacyLevel.IGNORE) expect(getNodePrivacyLevel(node, NodePrivacyLevel.MASK)).toBe(NodePrivacyLevel.MASK) - expect(getNodePrivacyLevel(node, NodePrivacyLevel.MASK_FORMS_ONLY)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.MASK_USER_INPUT)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('considers a DOM Element with a data-dd-privacy="input-ignored" attribute to be MASK_FORMS_ONLY (alias)', () => { + it('considers a DOM Element with a data-dd-privacy="input-ignored" attribute to be MASK_USER_INPUT (alias)', () => { const node = document.createElement('input') node.setAttribute('data-dd-privacy', 'input-ignored') - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('considers a DOM Element with a dd-privacy-input-ignored class to be MASK_FORMS_ONLY (alias)', () => { + it('considers a DOM Element with a dd-privacy-input-ignored class to be MASK_USER_INPUT (alias)', () => { const node = document.createElement('input') node.className = 'dd-privacy-input-ignored' - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('considers a DOM HTMLInputElement with a type of "password" to be MASK_FORMS_ONLY (alias)', () => { + it('considers a DOM HTMLInputElement with a type of "password" to be MASK_USER_INPUT (alias)', () => { const node = document.createElement('input') node.type = 'password' expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK) }) describe('input mode priority', () => { - it('consider a DOM Element to be MASK_FORMS_ONLY if both modes can apply', () => { + it('consider a DOM Element to be MASK_USER_INPUT if both modes can apply', () => { const node = document.createElement('input') node.className = 'dd-privacy-input-ignored' - node.setAttribute('data-dd-privacy', 'mask-forms-only') - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + node.setAttribute('data-dd-privacy', 'mask-user-input') + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) it('forces an element to be hidden if an ancestor is hidden', () => { @@ -128,7 +128,7 @@ describe('privacy helpers', () => { it('consider a DOM element to be ALLOW even if an ancestor is MASK', () => { const node = document.createElement('input') node.setAttribute('data-dd-privacy', 'allow') - expect(getNodePrivacyLevel(node, NodePrivacyLevel.MASK_FORMS_ONLY)).toBe(NodePrivacyLevel.ALLOW) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.MASK_USER_INPUT)).toBe(NodePrivacyLevel.ALLOW) }) }) @@ -140,30 +140,30 @@ describe('privacy helpers', () => { expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.ALLOW) }) - it('considers DOM Element with parent node with dd-privacy="input-ignored" attr to be MASK_FORMS_ONLY', () => { + it('considers DOM Element with parent node with dd-privacy="input-ignored" attr to be MASK_USER_INPUT', () => { const node = document.createElement('input') const parent = document.createElement('form') parent.setAttribute('data-dd-privacy', 'input-ignored') parent.appendChild(node) - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('considers DOM Element with parent node with dd-privacy-input-ignored class to be MASK_FORMS_ONLY', () => { + it('considers DOM Element with parent node with dd-privacy-input-ignored class to be MASK_USER_INPUT', () => { const node = document.createElement('input') const parent = document.createElement('form') parent.className = 'dd-privacy-input-ignored' parent.appendChild(node) - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) // eslint-disable-next-line max-len - it('considers a DOM Element with a "masked" privacy mode but within a parent with a "ignored" privacy mode to be MASK_FORMS_ONLY', () => { + it('considers a DOM Element with a "masked" privacy mode but within a parent with a "ignored" privacy mode to be MASK_USER_INPUT', () => { const node = document.createElement('input') const parent = document.createElement('form') parent.setAttribute('data-dd-privacy', 'input-ignored') parent.appendChild(node) node.setAttribute('data-dd-privacy', 'input-masked') - expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodePrivacyLevel(node, NodePrivacyLevel.ALLOW)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) }) }) @@ -195,21 +195,21 @@ describe('given privacy attributes getNodeSelfPrivacyLevel', function testOWnPri const el = buildFromHTML('hello') expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK) }) - it('classifies `mask-forms-only` class', () => { + it('classifies `mask-user-input` class', () => { const el = buildFromHTML( - 'hello' + 'hello' ) - expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('classifies deprecated `dd-privacy-input-ignored` class as `mask-forms-only`', () => { + it('classifies deprecated `dd-privacy-input-ignored` class as `mask-user-input`', () => { // eslint-disable-next-line max-len const el = buildFromHTML('hello') - expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) - it('classifies deprecated `dd-privacy-input-masked` class as `mask-forms-only`', () => { + it('classifies deprecated `dd-privacy-input-masked` class as `mask-user-input`', () => { // eslint-disable-next-line max-len const el = buildFromHTML('hello') - expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_FORMS_ONLY) + expect(getNodeSelfPrivacyLevel(el)).toBe(NodePrivacyLevel.MASK_USER_INPUT) }) it('classifies unknown class `dd-privacy-foo` class as undefined', () => { const el = buildFromHTML('hello') @@ -250,9 +250,9 @@ describe('Inherited Privacy Level derivePrivacyLevelGivenParent() ... ', functi msg: 'Override allow (for hidden)', }, { - args: [NodePrivacyLevel.ALLOW, NodePrivacyLevel.MASK_FORMS_ONLY], + args: [NodePrivacyLevel.ALLOW, NodePrivacyLevel.MASK_USER_INPUT], expect: NodePrivacyLevel.ALLOW, - msg: 'Override mask-forms-only', + msg: 'Override mask-user-input', }, { @@ -317,13 +317,13 @@ describe('serializeDocumentNode handles', function testAllowDomTree() { }) }) - describe('for privacy tag `mask-forms-only`, a DOM tree', function testMaskFormsOnlyDomTree() { + describe('for privacy tag `mask-user-input`, a DOM tree', function testMaskFormsOnlyDomTree() { it("doesn't mask text content", () => { - const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-forms-only') + const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-user-input') expect(JSON.stringify(serializedDoc)).not.toContain('᙮᙮') }) it('keeps form fields private', () => { - const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-forms-only') + const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-user-input') expect(JSON.stringify(serializedDoc)).toContain('**') }) }) @@ -358,30 +358,30 @@ describe('shouldMaskNode', () => { it('returns true if the privacy level is not ALLOW', () => { const element = document.createElement('input') expect(shouldMaskNode(element, NodePrivacyLevel.MASK)).toBeTrue() - expect(shouldMaskNode(element, NodePrivacyLevel.MASK_FORMS_ONLY)).toBeTrue() + expect(shouldMaskNode(element, NodePrivacyLevel.MASK_USER_INPUT)).toBeTrue() expect(shouldMaskNode(element, NodePrivacyLevel.IGNORE)).toBeTrue() expect(shouldMaskNode(element, NodePrivacyLevel.HIDDEN)).toBeTrue() }) }) describe('for text nodes contained in form elements', () => { - it('returns true if the privacy level is MASK or MASK_FORMS_ONLY', () => { + it('returns true if the privacy level is MASK or MASK_USER_INPUT', () => { const element = document.createElement('input') const text = document.createTextNode('foo') element.appendChild(text) expect(shouldMaskNode(text, NodePrivacyLevel.MASK)).toBeTrue() - expect(shouldMaskNode(text, NodePrivacyLevel.MASK_FORMS_ONLY)).toBeTrue() + expect(shouldMaskNode(text, NodePrivacyLevel.MASK_USER_INPUT)).toBeTrue() }) }) describe('for other elements', () => { - it('returns false if the privacy level is ALLOW or MASK_FORMS_ONLY', () => { + it('returns false if the privacy level is ALLOW or MASK_USER_INPUT', () => { const element = document.createElement('div') expect(shouldMaskNode(element, NodePrivacyLevel.ALLOW)).toBeFalse() - expect(shouldMaskNode(element, NodePrivacyLevel.MASK_FORMS_ONLY)).toBeFalse() + expect(shouldMaskNode(element, NodePrivacyLevel.MASK_USER_INPUT)).toBeFalse() }) - it('returns true if the privacy level is not ALLOW nor MASK_FORMS_ONLY', () => { + it('returns true if the privacy level is not ALLOW nor MASK_USER_INPUT', () => { const element = document.createElement('div') expect(shouldMaskNode(element, NodePrivacyLevel.MASK)).toBeTrue() expect(shouldMaskNode(element, NodePrivacyLevel.IGNORE)).toBeTrue() diff --git a/packages/rum/src/domain/record/privacy.ts b/packages/rum/src/domain/record/privacy.ts index ba43ee200d..3bb94c048a 100644 --- a/packages/rum/src/domain/record/privacy.ts +++ b/packages/rum/src/domain/record/privacy.ts @@ -3,11 +3,11 @@ import { PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_ALLOW, PRIVACY_ATTR_VALUE_MASK, - PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY, + PRIVACY_ATTR_VALUE_MASK_USER_INPUT, PRIVACY_ATTR_VALUE_HIDDEN, PRIVACY_CLASS_ALLOW, PRIVACY_CLASS_MASK, - PRIVACY_CLASS_MASK_FORMS_ONLY, + PRIVACY_CLASS_MASK_USER_INPUT, PRIVACY_CLASS_HIDDEN, FORM_PRIVATE_TAG_NAMES, CENSORED_STRING_MARK, @@ -32,10 +32,10 @@ const TEXT_MASKING_CHAR = 'x' * * derivePrivacyLevelGivenParent(getNodeSelfPrivacyLevel(node), parentNodePrivacyLevel) */ -export function getNodePrivacyLevel(node: Node, initialPrivacyLevel: NodePrivacyLevel): NodePrivacyLevel { +export function getNodePrivacyLevel(node: Node, defaultPrivacyLevel: NodePrivacyLevel): NodePrivacyLevel { const parentNodePrivacyLevel = node.parentNode - ? getNodePrivacyLevel(node.parentNode, initialPrivacyLevel) - : initialPrivacyLevel + ? getNodePrivacyLevel(node.parentNode, defaultPrivacyLevel) + : defaultPrivacyLevel const selfNodePrivacyLevel = getNodeSelfPrivacyLevel(node) return reducePrivacyLevel(selfNodePrivacyLevel, parentNodePrivacyLevel) } @@ -56,7 +56,7 @@ export function reducePrivacyLevel( switch (childPrivacyLevel) { case NodePrivacyLevel.ALLOW: case NodePrivacyLevel.MASK: - case NodePrivacyLevel.MASK_FORMS_ONLY: + case NodePrivacyLevel.MASK_USER_INPUT: case NodePrivacyLevel.HIDDEN: case NodePrivacyLevel.IGNORE: return childPrivacyLevel @@ -101,10 +101,10 @@ export function getNodeSelfPrivacyLevel(node: Node): NodePrivacyLevel | undefine return NodePrivacyLevel.ALLOW case PRIVACY_ATTR_VALUE_MASK: return NodePrivacyLevel.MASK - case PRIVACY_ATTR_VALUE_MASK_FORMS_ONLY: + case PRIVACY_ATTR_VALUE_MASK_USER_INPUT: case PRIVACY_ATTR_VALUE_INPUT_IGNORED: // Deprecated, now aliased case PRIVACY_ATTR_VALUE_INPUT_MASKED: // Deprecated, now aliased - return NodePrivacyLevel.MASK_FORMS_ONLY + return NodePrivacyLevel.MASK_USER_INPUT case PRIVACY_ATTR_VALUE_HIDDEN: return NodePrivacyLevel.HIDDEN } @@ -117,11 +117,11 @@ export function getNodeSelfPrivacyLevel(node: Node): NodePrivacyLevel | undefine } else if (node.classList.contains(PRIVACY_CLASS_HIDDEN)) { return NodePrivacyLevel.HIDDEN } else if ( - node.classList.contains(PRIVACY_CLASS_MASK_FORMS_ONLY) || + node.classList.contains(PRIVACY_CLASS_MASK_USER_INPUT) || node.classList.contains(PRIVACY_CLASS_INPUT_MASKED) || // Deprecated, now aliased node.classList.contains(PRIVACY_CLASS_INPUT_IGNORED) // Deprecated, now aliased ) { - return NodePrivacyLevel.MASK_FORMS_ONLY + return NodePrivacyLevel.MASK_USER_INPUT } else if (shouldIgnoreElement(node)) { // such as for scripts return NodePrivacyLevel.IGNORE @@ -129,11 +129,11 @@ export function getNodeSelfPrivacyLevel(node: Node): NodePrivacyLevel | undefine } /** - * Helper aiming to unify `mask` and `mask-forms-only` privacy levels: + * Helper aiming to unify `mask` and `mask-user-input` privacy levels: * * In the `mask` case, it is trivial: we should mask the element. * - * In the `mask-forms-only` case, we should mask the element only if it is a "form" element or the + * In the `mask-user-input` case, we should mask the element only if it is a "form" element or the * direct parent is a form element for text nodes). * * Other `shouldMaskNode` cases are edge cases that should not matter too much (ex: should we mask a @@ -145,7 +145,7 @@ export function shouldMaskNode(node: Node, privacyLevel: NodePrivacyLevel) { case NodePrivacyLevel.HIDDEN: case NodePrivacyLevel.IGNORE: return true - case NodePrivacyLevel.MASK_FORMS_ONLY: + case NodePrivacyLevel.MASK_USER_INPUT: return isTextNode(node) ? isFormElement(node.parentNode) : isFormElement(node) default: return false diff --git a/packages/rum/src/domain/record/record.spec.ts b/packages/rum/src/domain/record/record.spec.ts index dd1ce8f053..c50b92b1d4 100644 --- a/packages/rum/src/domain/record/record.spec.ts +++ b/packages/rum/src/domain/record/record.spec.ts @@ -1,4 +1,4 @@ -import { InitialPrivacyLevel } from 'packages/core/src/domain/configuration' +import { DefaultPrivacyLevel } from 'packages/core/src/domain/configuration' import { Clock, createNewEvent, isIE } from '../../../../core/test/specHelper' import { collectAsyncCalls } from '../../../test/utils' import { RecordType, IncrementalSource, RawRecord, IncrementalSnapshotRecord, FocusRecord } from '../../types' @@ -183,7 +183,7 @@ describe('record', () => { function startRecording() { recordApi = record({ emit: emitSpy, - initialPrivacyLevel: InitialPrivacyLevel.ALLOW, + defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW, }) } diff --git a/packages/rum/src/domain/record/record.ts b/packages/rum/src/domain/record/record.ts index 873aaf1e10..2043986d09 100644 --- a/packages/rum/src/domain/record/record.ts +++ b/packages/rum/src/domain/record/record.ts @@ -35,7 +35,7 @@ export function record(options: RecordOptions): RecordAPI { emit({ data: { - node: serializeDocument(document, options.initialPrivacyLevel), + node: serializeDocument(document, options.defaultPrivacyLevel), initialOffset: { left: window.pageXOffset !== undefined @@ -61,7 +61,7 @@ export function record(options: RecordOptions): RecordAPI { const stopObservers = initObservers({ mutationController, - initialPrivacyLevel: options.initialPrivacyLevel, + defaultPrivacyLevel: options.defaultPrivacyLevel, inputCb: (v) => emit({ data: { diff --git a/packages/rum/src/domain/record/serialize.spec.ts b/packages/rum/src/domain/record/serialize.spec.ts index a5ad8b34e1..27c2dccdda 100644 --- a/packages/rum/src/domain/record/serialize.spec.ts +++ b/packages/rum/src/domain/record/serialize.spec.ts @@ -12,7 +12,7 @@ import { AST_ALLOW, AST_HIDDEN, AST_MASK, - AST_MASK_FORMS_ONLY, + AST_MASK_USER_INPUT, generateLeanSerializedDoc, } from '../../../test/htmlAst' import { hasSerializedNode } from './serializationUtils' @@ -447,10 +447,10 @@ describe('serializeDocumentNode handles', function testAllowDomTree() { }) }) - describe('for privacy tag `mask-forms-only`, a DOM tree', function testMaskFormsOnlyDomTree() { + describe('for privacy tag `mask-user-input`, a DOM tree', function testMaskFormsOnlyDomTree() { it('is serialized correctly', () => { - const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-forms-only') - expect(toJSONObj(serializedDoc)).toEqual(AST_MASK_FORMS_ONLY) + const serializedDoc = generateLeanSerializedDoc(HTML, 'mask-user-input') + expect(toJSONObj(serializedDoc)).toEqual(AST_MASK_USER_INPUT) }) }) diff --git a/packages/rum/src/domain/record/serialize.ts b/packages/rum/src/domain/record/serialize.ts index 1b5c5ebd09..b1907daaba 100644 --- a/packages/rum/src/domain/record/serialize.ts +++ b/packages/rum/src/domain/record/serialize.ts @@ -38,7 +38,7 @@ import { forEach } from './utils' type ParentNodePrivacyLevel = | typeof NodePrivacyLevel.ALLOW | typeof NodePrivacyLevel.MASK - | typeof NodePrivacyLevel.MASK_FORMS_ONLY + | typeof NodePrivacyLevel.MASK_USER_INPUT export interface SerializeOptions { document: Document @@ -49,12 +49,12 @@ export interface SerializeOptions { export function serializeDocument( document: Document, - initialPrivacyLevel: ParentNodePrivacyLevel + defaultPrivacyLevel: ParentNodePrivacyLevel ): SerializedNodeWithId { // We are sure that Documents are never ignored, so this function never returns null return serializeNodeWithId(document, { document, - parentNodePrivacyLevel: initialPrivacyLevel, + parentNodePrivacyLevel: defaultPrivacyLevel, })! } diff --git a/packages/rum/src/domain/record/types.ts b/packages/rum/src/domain/record/types.ts index 4068b709cb..0734d52e01 100644 --- a/packages/rum/src/domain/record/types.ts +++ b/packages/rum/src/domain/record/types.ts @@ -1,4 +1,4 @@ -import { InitialPrivacyLevel } from '@datadog/browser-core' +import { DefaultPrivacyLevel } from '@datadog/browser-core' import { FocusRecord, RawRecord } from '../../types' import { MutationController } from './mutationObserver' @@ -62,7 +62,7 @@ export type IncrementalData = export interface RecordOptions { emit?: (record: RawRecord) => void - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel } export interface RecordAPI { @@ -72,7 +72,7 @@ export interface RecordAPI { } export interface ObserverParam { - initialPrivacyLevel: InitialPrivacyLevel + defaultPrivacyLevel: DefaultPrivacyLevel mutationController: MutationController mutationCb: MutationCallBack mousemoveCb: MousemoveCallBack diff --git a/packages/rum/src/index.ts b/packages/rum/src/index.ts index e7e5a279ae..40f2efe482 100644 --- a/packages/rum/src/index.ts +++ b/packages/rum/src/index.ts @@ -21,4 +21,4 @@ export { RumOtherResourceEventDomainContext, RumLongTaskEventDomainContext, } from '@datadog/browser-rum-core' -export { InitialPrivacyLevel } from '@datadog/browser-core' +export { DefaultPrivacyLevel } from '@datadog/browser-core' diff --git a/packages/rum/test/htmlAst.ts b/packages/rum/test/htmlAst.ts index 50506b1a1d..e6610765be 100644 --- a/packages/rum/test/htmlAst.ts +++ b/packages/rum/test/htmlAst.ts @@ -409,7 +409,7 @@ export const AST_MASK = { ], } -export const AST_MASK_FORMS_ONLY = { +export const AST_MASK_USER_INPUT = { type: 0, childNodes: [ { @@ -422,7 +422,7 @@ export const AST_MASK_FORMS_ONLY = { type: 2, tagName: 'html', attributes: { - 'data-dd-privacy': 'mask-forms-only', + 'data-dd-privacy': 'mask-user-input', }, childNodes: [ { diff --git a/test/e2e/scenario/recorder.scenario.ts b/test/e2e/scenario/recorder.scenario.ts index 77dacf83bb..2ffa729346 100644 --- a/test/e2e/scenario/recorder.scenario.ts +++ b/test/e2e/scenario/recorder.scenario.ts @@ -1,6 +1,7 @@ import { CreationReason, IncrementalSource, RecordType, Segment } from '@datadog/browser-rum/cjs/types' import { InputData, StyleSheetRuleData, NodeType } from '@datadog/browser-rum/cjs/domain/record/types' import { RumInitConfiguration } from '@datadog/browser-rum-core' +import { DefaultPrivacyLevel } from '@datadog/browser-rum' import { createTest, bundleSetup, html, EventRegistry } from '../lib/framework' import { browserExecute } from '../lib/helpers/browser' @@ -443,7 +444,9 @@ describe('recorder', () => { describe('input observers', () => { createTest('record input interactions') - .withRum() + .withRum({ + defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW, + }) .withRumInit(initRumAndStartRecording) .withSetup(bundleSetup) .withBody( @@ -523,7 +526,9 @@ describe('recorder', () => { }) createTest("don't record ignored input interactions") - .withRum() + .withRum({ + defaultPrivacyLevel: DefaultPrivacyLevel.ALLOW, + }) .withRumInit(initRumAndStartRecording) .withSetup(bundleSetup) .withBody(