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

Check if navigator.sendBeacon is defined before calling it #56

Open
PascalKoe opened this issue Mar 3, 2025 · 1 comment
Open

Check if navigator.sendBeacon is defined before calling it #56

PascalKoe opened this issue Mar 3, 2025 · 1 comment

Comments

@PascalKoe
Copy link

When browsing the DaisyUI Website that uses minimal-analytics, the navigation to links does not work. In the console of the browser an error is displayed linking to code of minimal-analytics: Uncaught (in promise) TypeError: navigator.sendBeacon is not a function. Source Location.
I guess my company modified the default Firefox installation to disable sending beacons using this API.

Is it possible to check if the API is available before calling it, so in case of corporate browsers like mine we do not run into exception but degrade gracefully?

@jahilldev
Copy link
Owner

Hey @PascalKoe,

Yes this should be a fairly simple change, we'd just need to fall back to making a fetch request instead. The only consideration being sendBeacon ensures to request is made, regardless of navigation away from the page that initiates it, whereas fetch does not. I believe this is a fairly reasonable compromise (it being the only one, really).

I'll try and get to this when I have some time, but feel free to open a PR, all contributions welcome 👍

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

2 participants