Skip to content

Commit 96f007e

Browse files
committed
fix(replay): Make maskAllText selector more specific
Sometimes, we seemed to be masking e.g. content of style tags. This new selector should be more specific to not mask anything that we know is not actually text.
1 parent 402ccd7 commit 96f007e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

packages/replay/src/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ export const MAX_SESSION_LIFE = 1_800_000; // 30 minutes
2525
*/
2626
export const DEFAULT_SESSION_SAMPLE_RATE = 0.1;
2727
export const DEFAULT_ERROR_SAMPLE_RATE = 1.0;
28+
29+
/** The select to use for the `maskAllText` option */
30+
export const MASK_ALL_TEXT_SELECTOR = 'body *:not(style,script)';

packages/replay/src/integration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BrowserClient, BrowserOptions } from '@sentry/browser';
22
import { getCurrentHub } from '@sentry/core';
33
import { Integration } from '@sentry/types';
44

5-
import { DEFAULT_ERROR_SAMPLE_RATE, DEFAULT_SESSION_SAMPLE_RATE } from './constants';
5+
import { DEFAULT_ERROR_SAMPLE_RATE, DEFAULT_SESSION_SAMPLE_RATE, MASK_ALL_TEXT_SELECTOR } from './constants';
66
import { ReplayContainer } from './replay';
77
import type { RecordingOptions, ReplayConfiguration, ReplayPluginOptions } from './types';
88
import { isBrowser } from './util/isBrowser';
@@ -107,7 +107,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
107107
// `maskAllText` is a more user friendly option to configure
108108
// `maskTextSelector`. This means that all nodes will have their text
109109
// content masked.
110-
this.recordingOptions.maskTextSelector = '*';
110+
this.recordingOptions.maskTextSelector = MASK_ALL_TEXT_SELECTOR;
111111
}
112112

113113
if (this.options.blockAllMedia) {

packages/replay/test/unit/index-integrationSettings.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { mockSdk } from './../index';
2+
import { MASK_ALL_TEXT_SELECTOR } from '../../src/constants';
23

34
describe('integration settings', () => {
45
beforeEach(() => {
@@ -168,13 +169,13 @@ describe('integration settings', () => {
168169
const { replay } = await mockSdk({ replayOptions: {} });
169170

170171
// Default is true
171-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
172+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
172173
});
173174

174175
it('works with true', async () => {
175176
const { replay } = await mockSdk({ replayOptions: { maskAllText: true } });
176177

177-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
178+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
178179
});
179180

180181
it('works with false', async () => {
@@ -186,7 +187,7 @@ describe('integration settings', () => {
186187
it('overwrites custom maskTextSelector option', async () => {
187188
const { replay } = await mockSdk({ replayOptions: { maskAllText: true, maskTextSelector: '[custom]' } });
188189

189-
expect(replay['_recordingOptions'].maskTextSelector).toBe('*');
190+
expect(replay['_recordingOptions'].maskTextSelector).toBe(MASK_ALL_TEXT_SELECTOR);
190191
});
191192
});
192193

0 commit comments

Comments
 (0)