Skip to content

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

Open
@supermar1010

Description

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)

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