Skip to content

Commit c98b380

Browse files
committed
feat: add new mask attributes fn
1 parent 4677e5c commit c98b380

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
@@ -81,6 +81,7 @@ export class Replay implements Integration {
8181
networkResponseHeaders = [],
8282

8383
mask = [],
84+
maskAttributes = ['title', 'placeholder'],
8485
unmask = [],
8586
block = [],
8687
unblock = [],
@@ -110,6 +111,14 @@ export class Replay implements Integration {
110111
maskInputOptions: { ...(maskInputOptions || {}), password: true },
111112
maskTextFn: maskFn,
112113
maskInputFn: maskFn,
114+
maskAttributeFn: (key: string, value: string): string => {
115+
// For now, always mask these attributes
116+
if (maskAttributes.includes(key)) {
117+
return value.replace(/[\S]/g, '*');
118+
}
119+
120+
return value;
121+
},
113122

114123
...getPrivacyOptions({
115124
mask,

packages/replay/src/types/replay.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,12 @@ export interface ReplayIntegrationPrivacyOptions {
264264
}
265265

266266
// These are optional for ReplayPluginOptions because the plugin sets default values
267-
type OptionalReplayPluginOptions = Partial<ReplayPluginOptions>;
267+
type OptionalReplayPluginOptions = Partial<ReplayPluginOptions> & {
268+
/**
269+
* Mask element attributes that are contained in list
270+
*/
271+
maskAttributes?: string[];
272+
};
268273

269274
export interface DeprecatedPrivacyOptions {
270275
/**
@@ -288,7 +293,7 @@ export interface DeprecatedPrivacyOptions {
288293
*/
289294
maskTextClass?: RecordingOptions['maskTextClass'];
290295
/**
291-
* @deprecated Use `mask` which accepts an array of CSS selectors
296+
* @derecated Use `mask` which accepts an array of CSS selectors
292297
*/
293298
maskTextSelector?: RecordingOptions['maskTextSelector'];
294299
}

0 commit comments

Comments
 (0)