Created attachment 403167 [details] Test page to reproduce bug +++ This bug was initially created as a clone of Bug #199854 +++ Cloning this bug since it's fairly old and I'm still encountering on iOS 13. I've run into a similar issue with a page that needs to fire a POST request when being closed for analytics and cleanup. Using document.visibilitychange works on chrome, firefox, and edge on windows, as well as chrome on android. But, upon investigation it seems Safari fires this event only when hiding the page by pressing the home button or switching to a new tab. When closing the tab or navigating away to a different page, document.visibilitychange is never fired. See the test-page in the cloned bug, as well as what I've attached which adds a cookie logging the visibilitystate upon document.visibilitytransition events. Cookies will be added when pressing the home button or opening a new tab, but not when closing or navigating away from the page. The closest workaround I've found is to use the focus and blur events which are being fired properly, but this presents problems with being triggered on desktop in cases that they shouldn't be (i.e. the user clicking off the page). visibilitychange should be triggered in these cases; see https://www.igvita.com/2015/11/20/dont-lose-user-and-app-state-use-page-visibility/ (which seems to document this as bugged dating back to 2015).
> Cloning this bug since it's fairly old and I'm still encountering on iOS 13. This is not a good way to raise attention. A new bug is less visible than a comment on the original one, and far more confusing. > I've run into a similar issue with a page that needs to fire a POST request when being closed for analytics and cleanup. Beacons may be able to solve this use case. Even if visibilitystate were fired, the POST would not necessarily be sent - a closed page is a closed page, everything is being cleaned up. *** This bug has been marked as a duplicate of bug 199854 ***