Skip to content

Commit f6853e5

Browse files
committed
feat: add new mask attributes fn
1 parent c120b52 commit f6853e5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

packages/browser-integration-tests/suites/replay/customEvents/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ sentryTest(
117117
nodeId: expect.any(Number),
118118
node: {
119119
attributes: {
120-
'aria-label': '** ***** ** **********',
120+
'aria-label': 'An Error in aria-label',
121121
class: 'btn btn-error',
122122
id: 'error',
123123
role: 'button',

packages/replay/src/integration.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export class Replay implements Integration {
7979
networkResponseHeaders = [],
8080

8181
mask = [],
82+
maskAttributes = ['title', 'placeholder'],
8283
unmask = [],
8384
block = [],
8485
unblock = [],
@@ -108,6 +109,14 @@ export class Replay implements Integration {
108109
maskInputOptions: { ...(maskInputOptions || {}), password: true },
109110
maskTextFn: maskFn,
110111
maskInputFn: maskFn,
112+
maskAttributeFn: (key: string, value: string): string => {
113+
// For now, always mask these attributes
114+
if (maskAttributes.includes(key)) {
115+
return value.replace(/[\S]/g, '*');
116+
}
117+
118+
return value;
119+
},
111120

112121
...getPrivacyOptions({
113122
mask,

packages/replay/src/types/replay.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,12 @@ export interface ReplayIntegrationPrivacyOptions {
259259
}
260260

261261
// These are optional for ReplayPluginOptions because the plugin sets default values
262-
type OptionalReplayPluginOptions = Partial<ReplayPluginOptions>;
262+
type OptionalReplayPluginOptions = Partial<ReplayPluginOptions> & {
263+
/**
264+
* Mask element attributes that are contained in list
265+
*/
266+
maskAttributes?: string[];
267+
};
263268

264269
export interface DeprecatedPrivacyOptions {
265270
/**
@@ -283,7 +288,7 @@ export interface DeprecatedPrivacyOptions {
283288
*/
284289
maskTextClass?: RecordingOptions['maskTextClass'];
285290
/**
286-
* @deprecated Use `mask` which accepts an array of CSS selectors
291+
* @derecated Use `mask` which accepts an array of CSS selectors
287292
*/
288293
maskTextSelector?: RecordingOptions['maskTextSelector'];
289294
}

0 commit comments

Comments
 (0)