amplitude / Amplitude-TypeScript

TypeScript Amplitude Analytics SDK
https://amplitude.github.io/Amplitude-TypeScript/
MIT License
126 stars 33 forks source link

SyntaxError: Failed to execute 'matches' on 'Element': The provided selector is empty. #804

Closed priemskiyyy closed 2 weeks ago

priemskiyyy commented 2 weeks ago

Expected Behavior

No errors should occur in this section of the code.

Current Behavior

A few days ago, we noticed a significant increase in error events in Sentry originating from rrweb package. Previously, there were no issues. The stack trace indicates that the error occurs in the following part of rrweb code:

    if (blockSelector) {
        if (el.matches(blockSelector))
            return true;
        if (checkAncestors && el.closest(blockSelector) !== null)
            return true;
    } 

Additionally, sometimes we encounter this error:

SyntaxError: '' is not a valid selector.

Possible Solution

Extra checks in the highlighted part of the code to ensure blockSelector is valid before using it?

Steps to Reproduce

  1. Install @amplitude/analytics-browser, @amplitude/plugin-session-replay-browser
  2. Initialize Amplitude and add the session replay plugin
  3. Observe issues in Sentry

Environment

lewgordon-amplitude commented 2 weeks ago

Hi @priemskiyyy ! Thanks for opening this. In a more recent version we pre-filter invalid selector so that rrweb won't hit errors. This comes with the side effect that this may not block as expected, but incur less errors. Does this work for you or would you want some other precheck mechanism (e.g. fast fail on startup)?

priemskiyyy commented 2 weeks ago

Hey @lewgordon-amplitude , Sorry for the delay. I tested the latest version, and it works fine. Thanks for addressing the issue and for your support!

lewgordon-amplitude commented 2 weeks ago

Awesome, glad to hear!