WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
199854
Safari on iOS doesn't fire any events when the tab/app is closed
https://bugs.webkit.org/show_bug.cgi?id=199854
Summary
Safari on iOS doesn't fire any events when the tab/app is closed
Jason Gissing
Reported
2019-07-17 04:20:48 PDT
Created
attachment 374286
[details]
test page demonstrating the issue On iOS, the document's visibilitychange event is fired when changing tab, but not when a tab is closed, or if the Safari app is suspended/killed. pagehide, beforeunload & unload all seem not to fire at all on iOS. We have an application which sets up sessions for clients, but we seem to have no way of detecting that a client has (even possibly) gone away, and so sessions are not cleaned up. Safari on desktop does not have these issues, and neither do browsers on Android. Most related bugs seem to be linked to fault
https://bugs.webkit.org/show_bug.cgi?id=116769
, but this has had no activity since 2013. Attached is a simple test page, which tries to send a beacon to a publicly accessible endpoint (it has daily limits, so change the endpoint to your own if need be) on pagehide, unload, beforeunload & visibilitychange events. None of these are fired if the tab or app is closed.
Attachments
test page demonstrating the issue
(2.28 KB, text/html)
2019-07-17 04:20 PDT
,
Jason Gissing
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Radar WebKit Bug Importer
Comment 1
2019-07-19 23:51:07 PDT
<
rdar://problem/53339572
>
Antoine Quint
Comment 2
2019-08-12 09:06:05 PDT
I think this behaves correctly, but someone else should advise on whether that is the case. Cc'ing Ryosuke who may know.
Ryosuke Niwa
Comment 3
2019-08-13 16:37:14 PDT
If we're not firing page hide when a tab / MobileSafari is closed explicitly by the user, that would be a WebKit bug. If WebContent process dies (e.g. due to jetsam / crash) or MobileSafari itself is killed, then the fact pagehide event not firing is by design. If there is no process left, or we ran out of memory, then we can't run any scripts.
Simon Lieschke
Comment 4
2020-02-28 15:47:06 PST
FWIW I've also observed with the test page that none of the events are fired when navigating to another page in the same tab. Curiously however if the test page is reload a pagehide and an unload event do get fired. (Observed with Safari 13 on iOS 13.3.1.)
Alexey Proskuryakov
Comment 5
2020-07-01 09:27:56 PDT
***
Bug 213770
has been marked as a duplicate of this bug. ***
max
Comment 6
2023-04-17 07:16:26 PDT
I can confirm that none of the following event listeners are triggered when a tab is closed in iOS Safari. Tested on iOS 16.3.1. addEventListener('visibilitychange', trackEvent, true); addEventListener('pagehide', trackEvent, true); addEventListener('freeze', trackEvent, true); addEventListener('resume', trackEvent, true); addEventListener('beforeunload', trackEvent, true); addEventListener('unload', trackEvent, true); document.addEventListener('beforeunload', trackEvent, true); document.addEventListener('unload', trackEvent, true); document.body.addEventListener('beforeunload', trackEvent, true); document.body.addEventListener('unload', trackEvent, true); window.onunload = trackEvent; This means there's absolutely no way we can use navigator.sendBeacon to send analytics data to our backend when a user closes the tab. Same issue when the browser is force killed on the iPhone (i.e. Safari is force closed rather than put in the background). The most closely related issue I can find is this:
https://bugs.webkit.org/show_bug.cgi?id=151610
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug