Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replay: set data-dd-privacy attribute on snapshot node if hidden #726

Merged
Merged
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
6 changes: 3 additions & 3 deletions packages/rum-recorder/src/domain/privacy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const PRIVACY_ATTR_NAME = 'data-dd-privacy'
const PRIVACY_ATTR_VALUE_HIDDEN = 'hidden'
const PRIVACY_ATTR_VALUE_INPUT_IGNORED = 'input-ignored'
export const PRIVACY_ATTR_NAME = 'data-dd-privacy'
export const PRIVACY_ATTR_VALUE_HIDDEN = 'hidden'
export const PRIVACY_ATTR_VALUE_INPUT_IGNORED = 'input-ignored'

const PRIVACY_CLASS_HIDDEN = 'dd-privacy-hidden'
const PRIVACY_CLASS_INPUT_IGNORED = 'dd-privacy-input-ignored'
Expand Down
4 changes: 3 additions & 1 deletion packages/rum-recorder/src/domain/rrweb-snapshot/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-underscore-dangle */
import { nodeShouldBeHidden } from '../privacy'
import { PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN, nodeShouldBeHidden } from '../privacy'
import {
SerializedNode,
SerializedNodeWithId,
Expand Down Expand Up @@ -254,9 +254,11 @@ function serializeNode(
if (shouldBeHidden) {
const { width, height } = (n as HTMLElement).getBoundingClientRect()
attributes = {
id: attributes.id,
BenoitZugmeyer marked this conversation as resolved.
Show resolved Hide resolved
class: attributes.class,
rr_width: `${width}px`,
rr_height: `${height}px`,
[PRIVACY_ATTR_NAME]: PRIVACY_ATTR_VALUE_HIDDEN,
}
}
return {
Expand Down
14 changes: 11 additions & 3 deletions test/e2e/scenario/recorder.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('recorder', () => {
html`
<p id="foo">foo</p>
<p id="bar" data-dd-privacy="hidden">bar</p>
<p id="baz" class="dd-privacy-hidden">baz</p>
<p id="baz" class="dd-privacy-hidden baz">baz</p>
`
)
.run(async ({ events }) => {
Expand All @@ -83,8 +83,16 @@ describe('recorder', () => {
expect(fooNode).toBeTruthy()
expect(findTextContent(fooNode!)).toBe('foo')

expect(findNodeWithId(fullSnapshot, 'bar')).toBeFalsy()
expect(findNodeWithId(fullSnapshot, 'baz')).toBeFalsy()
const barNode = findNodeWithId(fullSnapshot, 'bar')
expect(barNode).toBeTruthy()
expect(barNode!.attributes['data-dd-privacy']).toBe('hidden')
expect(barNode!.childNodes.length).toBe(0)

const bazNode = findNodeWithId(fullSnapshot, 'baz')
expect(bazNode).toBeTruthy()
expect(bazNode!.attributes.class).toBe('dd-privacy-hidden baz')
expect(bazNode!.attributes['data-dd-privacy']).toBe('hidden')
expect(bazNode!.childNodes.length).toBe(0)
})
})

Expand Down