iOS 13+ WebClips have no way of knowing when the user has brought it to the front (Bug)

I install full screen web apps to the home screen of an iOS device and have some

javascript
run 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 as when the webclip is alive in the App Switcher, it will just continue where it left of when it's brought back to the front. I'm assuming this is by design, so users can switch to say a calender and back to the web app without it restarting.


So 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
or
visibilitychange
or maybe looking at
document.activeElement
,
document.hasFocus()
or
document.hidden
.


Here's the gotcha...

iOS 13 has 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 13.1.1 (FB7144365)


Bug

If you have more than one home screen web app, it's as if they all share the same web container or something. 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 or become front and centre again. 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?