-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathgetPrivacyOptions.ts
44 lines (35 loc) · 1.37 KB
/
getPrivacyOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { ReplayIntegrationPrivacyOptions } from '../types';
type GetPrivacyOptions = Required<Omit<ReplayIntegrationPrivacyOptions, 'maskFn'>>;
interface GetPrivacyReturn {
maskTextSelector: string;
unmaskTextSelector: string;
blockSelector: string;
unblockSelector: string;
ignoreSelector: string;
blockClass?: RegExp;
maskTextClass?: RegExp;
}
function getOption(selectors: string[], defaultSelectors: string[]): string {
return [
...selectors,
// sentry defaults
...defaultSelectors,
].join(',');
}
/**
* Returns privacy related configuration for use in rrweb
*/
export function getPrivacyOptions({ mask, unmask, block, unblock, ignore }: GetPrivacyOptions): GetPrivacyReturn {
const defaultBlockedElements = ['base', 'iframe[srcdoc]:not([src])'];
const maskSelector = getOption(mask, ['.sentry-mask', '[data-sentry-mask]']);
const unmaskSelector = getOption(unmask, []);
const options: GetPrivacyReturn = {
// We are making the decision to make text and input selectors the same
maskTextSelector: maskSelector,
unmaskTextSelector: unmaskSelector,
blockSelector: getOption(block, ['.sentry-block', '[data-sentry-block]', ...defaultBlockedElements]),
unblockSelector: getOption(unblock, []),
ignoreSelector: getOption(ignore, ['.sentry-ignore', '[data-sentry-ignore]', 'input[type="file"]']),
};
return options;
}