posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

$el_text cannot be set after `autocapture` is enabled

Open inbreaks opened this issue 4 years ago • 0 comments

Consider the following Element, after the button is clicked

<button>
<span>Click me</span>
</button>

Open https://app.posthog.com/events

Expect to get clicked button with text Click me Actually get clicked button

Here is the relevant code https://github.com/PostHog/posthog-js/blob/master/src/autocapture-utils.js#L29

export function getSafeText(el) {
    var elText = ''

    if (shouldCaptureElement(el) && !isSensitiveElement(el) && el.childNodes && el.childNodes.length) {
        _.each(el.childNodes, function (child) {
            if (isTextNode(child) && child.textContent) {
                elText += _.trim(child.textContent)
                    // scrub potentially sensitive values
                    .split(/(\s+)/)
                    .filter(shouldCaptureValue)
                    .join('')
                    // normalize whitespace
                    .replace(/[\r\n]/g, ' ')
                    .replace(/[ ]+/g, ' ')
                    // truncate
                    .substring(0, 255)
            }
        })
    }

    return _.trim(elText)
}

inbreaks avatar Dec 07 '21 07:12 inbreaks