Skip to content

$el_text cannot be set after autocapture is enabled #343

Closed

Description

@inbreaks

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)
}

Activity

  1. pauldambra commented on May 15, 2023

    @pauldambra
    Member

    fixed in #563

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions