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

Attribution FID eventTarget is empty for SVG elements #344

Closed
chrisopperwall-qz opened this issue Apr 27, 2023 · 2 comments · Fixed by #354
Closed

Attribution FID eventTarget is empty for SVG elements #344

chrisopperwall-qz opened this issue Apr 27, 2023 · 2 comments · Fixed by #354

Comments

@chrisopperwall-qz
Copy link

Hi there 👋

We noticed a bug in getSelector when the FID eventTarget is an SVG. When the eventTarget is an SVG, the value of className is an SVGAnimatedString, which doesn't have a trim() method, so an exception is thrown and caught by the catch and an empty selector string is returned (or whatever the selector was up until the SVG element was encountered). https://github.com/GoogleChrome/web-vitals/blob/main/src/lib/getSelector.ts#L33

I believe using el.getAttribute('class') would work correctly in this case, with the caveat that getAttribute can return null as well as a string. We also noticed that el.classList.value worked in this case, but I'm not sure what the compatibility requirements for this project are.

I'll can put up a quick PR with the classList solution (or fallback to using getAttribute if that's preferred)

@tunetheweb
Copy link
Member

Good spot. The classList.value option seems good to me and seems supported long enough to cover all browsers supported by this project.

@chrisopperwall-qz
Copy link
Author

Awesome, thanks for the fix!!

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

Successfully merging a pull request may close this issue.

2 participants