Monday, 23 September 2019

Detecting when iOS Webclip is launched whilst working around an iOS 13 bug

Background

I install full screen web apps to the home screen of an iOS device and run some javascript each time the web app is launched. Apple have made a change in iOS 13 whereby scripts are only run the first time it is launched. Each subsequent launch presents the web app from where it left off without refreshing back to the start (unless it has been removed from the app switcher).

I believe this is a much requested feature from Web App developers to stop a webpage refreshing if the user switches to another app and back again

To make javascript run some code each time the app is brought to the foreground or launched, I thought I could simply use some notifications watching focus, blur & visibilitychange or maybe looking at document.activeElement, document.hasFocus() or document.hidden.

Here's the gotcha...

iOS 13 has also introduced a bug that I have reported but doesn't look like it's going to be fixed any time soon and is still present in 13GM & 13.1 beta.

Bug

If you have more than one home screen web app, it's as if they all share the same web container. Launching a 2nd web app causes all the focus type notifications to fire on previously opened web apps as if they had become front and centre again. This means any javascript code is going to run as if it had been launched, even when it hasn't.

Question

I am trying to find a way around this bug and be notified when a web app is launched front and centre. Using onLoad type code will only run once whilst the web app is left in the app switcher. Watching focus type events will fire unnecessarily as other web apps are launched. Are there any other events or methods I can try calling, or any tricks I could try to implement?



from Detecting when iOS Webclip is launched whilst working around an iOS 13 bug

No comments:

Post a Comment