Bug 206213 - No events are fired when a user enters the App Switcher on iOS
Summary: No events are fired when a user enters the App Switcher on iOS
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari 13
Hardware: iPhone / iPad iOS 13
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-13 21:33 PST by Philip Walton
Modified: 2020-01-14 22:53 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philip Walton 2020-01-13 21:33:39 PST
** Problem: **

When a user visits a web page and then enters the App Switcher, no events are fired.

STR:

1. Visit https://event-logger.glitch.me/
2. Swipe up from the bottom of the screen (tested on iPhone X) to enter the App Switcher
3. Return to Safari
4. Notice that no events are logged in the table.

Alternatively:

1. Visit https://event-logger.glitch.me/
2. Swipe up from the bottom of the screen (tested on iPhone X) to enter the App Switcher
3. Close Safari
4. Open Safari (which reloads https://event-logger.glitch.me/)
5. Notice that only the `pageshow` event is logged (from the current page load, not the old page).

The demo page at https://event-logger.glitch.me/ logs all `blur`, `visibilitychange`, `pagehide`, and `pageshow`, events.

If you focus/blur the elements on the page, switch tabs to another page, close the tab, refresh the page, or enter the Safari tab switcher, in all cases you will see events being logged.

On the other hand if you open the App Switcher you won't see any events logged. This means that if a user leaves the page by enter the App Switcher and then closes Safari, there's absolutely no developer-visible signal. There's only a developer visible signal if the user actually switches apps (in that case `blur` and `visibilitychange` are logged).

This is a problem because, without any signal that a user may be about to leave, there's no way for a developers to persist unsaved state (in order to restore it when the user comes back).

** Solution: **

It would be better (and consistent with Android) if both the `blur` and `visibilitychange` events were fired when the user entered the App Switcher, not just when they actually switched apps.

In fact, Safari *does* fire the `blur` event when using Safari's tab switcher, but no event is fired when using the OS's App Switcher. It seems like (at minimum) these two cases should be consistent.

Related issues: 
https://bugs.webkit.org/show_bug.cgi?id=205942
https://bugs.webkit.org/show_bug.cgi?id=199854
https://bugs.webkit.org/show_bug.cgi?id=151234
Comment 1 Radar WebKit Bug Importer 2020-01-14 22:53:18 PST
<rdar://problem/58596341>