Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posthog-js crash with TypeError: Argument 1 ('element') to Window.getComputedStyle must be an instance of Element #1692

Open
supermar1010 opened this issue Jan 26, 2025 · 0 comments

Comments

@supermar1010
Copy link
Contributor

Hello,
we saw a crash with posthog-js in our sentry tracking. The stacktrace is similiar to what was fixed with this PR: #1620
Might also be caused by rxdb. I could not really get to the root of this issue. It seems that for some reason this code runs the window?.getComputedStyle(curEl) even though curEl is not of type element.

    while (curEl && isElementNode(curEl) && !isTag(curEl, 'body')) {
        if (curEl === breakOnElement) {
            return false
        }

        if (includes(matches, window?.getComputedStyle(curEl).position)) {
            return true
        }

        curEl = getParentElement(curEl)
    }

Maybe the code checking if it is an Element is not working as expected? Maybe something weird with Safari (Apple Mail 605.1.15)?

export function isElementNode(el: Node | Element | undefined | null): el is Element {
    return !!el && el.nodeType === 1 // Node.ELEMENT_NODE - use integer constant for browser portability
}

The browser according to sentry is: Apple Mail 605.1.15

Stacktrace:

TypeError: Argument 1 ('element') to Window.getComputedStyle must be an instance of Element
  at getComputedStyle([native code])
  at s(../../../../node_modules/.pnpm/[email protected]/node_modules/posthog-js/dist/module.js:1:110971)
  at s(../../../../node_modules/.pnpm/[email protected]/node_modules/posthog-js/dist/module.js:1:111026)
  at this._mouseMoveTimeout(../../../../node_modules/.pnpm/[email protected]/node_modules/posthog-js/dist/module.js:1:111551)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant