feat(tracker): add custom sanitizer function
This commit is contained in:
parent
a6f0a73c1c
commit
6239f5f9a5
1 changed files with 17 additions and 0 deletions
|
|
@ -5,6 +5,8 @@ import { isElementNode } from './guards.js'
|
|||
export interface Options {
|
||||
obscureTextEmails: boolean
|
||||
obscureTextNumbers: boolean
|
||||
customCallback: boolean
|
||||
domSanitizer: (node: Node) => [isMasked: boolean, isHtmlContainer: boolean]
|
||||
}
|
||||
|
||||
export default class Sanitizer {
|
||||
|
|
@ -17,12 +19,27 @@ export default class Sanitizer {
|
|||
{
|
||||
obscureTextEmails: true,
|
||||
obscureTextNumbers: false,
|
||||
customCallback: false,
|
||||
domSanitizer: () => [false, false],
|
||||
},
|
||||
options,
|
||||
)
|
||||
}
|
||||
|
||||
handleNode(id: number, parentID: number, node: Node) {
|
||||
if (this.options.customCallback) {
|
||||
if (this.masked.has(parentID)) {
|
||||
this.masked.add(id)
|
||||
} else if (this.maskedContainers.has(parentID)) {
|
||||
this.maskedContainers.add(id)
|
||||
} else {
|
||||
const [shouldMask, isHtmlContainer] = this.options.domSanitizer(node)
|
||||
if (shouldMask) {
|
||||
const addMasked = isHtmlContainer ? this.maskedContainers.add : this.masked.add
|
||||
addMasked(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
this.masked.has(parentID) ||
|
||||
(isElementNode(node) && hasOpenreplayAttribute(node, 'masked'))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue