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

Safari doesn't fire visibilitychange event on the page close #3

Closed
alekseykulikov opened this issue Jun 12, 2020 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@alekseykulikov
Copy link
Member

alekseykulikov commented Jun 12, 2020

web-vitals-reporter uses onHidden utility from web-vitals to detect the end of the session, which relies on a visibilitychange event.

Safari doesn't fire visibilitychange on the page close or refresh (similar issue).

It's possible to use pagehide event, but it fires before visibilitychange in Chromium/Firefox, and there's a potential of losing LCP/CLS values, which depends on onHidden.

@philipwalton, what do you think about this? Is it possible to detect proper support of visibilitychange and fallback to pagehide if not?

@alekseykulikov alekseykulikov added the bug Something isn't working label Jun 12, 2020
@alekseykulikov
Copy link
Member Author

The fix I ended up with: if a browser supports CLS/LCP, try to use onHidden; otherwise, use pagehide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant