NEW 207256
visibilitychange event does not get always fired on background but it may on foreground
https://bugs.webkit.org/show_bug.cgi?id=207256
Summary visibilitychange event does not get always fired on background but it may on ...
Alexander Cerutti
Reported 2020-02-05 04:20:05 PST
Hello, this is my first bug here and I'm not too sure about the information I filled to report this problem, since I'm not that into Webkit. What I experienced is that I've tried to attach a `visibilitychange` listener on my application. It contains a `console.log` and some logics that depend on `document.hidden`. So, if home button or sleep button is pressed, the event is fired and we can see in the debugging console the log. I've been reported, and I've verified, that sometimes this event is not fired when, for sure on iPad (also iOS 13), one of those two buttons are pressed. Instead the event is fired when Safari goes back in foreground. So the log gets printed twice. Moreover, sometimes `document.hidden` is `false` in both events. So if some logic is based on a check on that property, wrong code block may be run. I wasn't able to find a steady way to reproduce this, and this seems to happen in different cases. For example, I'm developing a video player (here is where the event is created). We are importing a third-party video AD engine. What we experienced is that during some ADs, on home/sleep buttons, the event is not fired on background but twice on foreground. This happened also during other video contents playback, but I'm not sure it is related to multimedia contents playback but instead on the amount of work the engine that is has to do when the buttons get pressed or some kind of concurrency problem on Safari background (but these are only thoughts of mine). If I'll ever find more details I'll edit or add a comment to increase the details. I hope this bug report is good enough (but I think this won't be) to find the problem. Thank you.
Attachments
Repro html page (1.45 KB, text/html)
2020-02-05 09:43 PST, Alexander Cerutti
no flags
Alexander Cerutti
Comment 1 2020-02-05 09:43:03 PST
Created attachment 389818 [details] Repro html page
Alexander Cerutti
Comment 2 2020-02-05 09:43:11 PST
I've found a way to reproduce almost-steadly the problem while using sleep button. With the sample that I'm attaching, which is a normal video tag with a `visibilitychange` event attached on document, I've tried to lock and unlock the iPad with iOS 12, different times. The video was playing before this happened. Some unlocks (may vary from 3 to 5 or more), the video didn't came back to playing automatically and the `visibilitychanged` event started being fired only on foreground. This situation can persist for some other lock-unlock actions but it will recover somehow and then can fall back in this again. I don't know how this can be related or linked under the hood, but seems the only almost-steady way I found to reproduce this problem. Instead, I didn't found yet a way to reproduce the problem that happens when home button is pressed. Anyway, if the player is paused after unlock, pressing home button still fires the event `visibilitychanged`. I think that they might be two different but related problems.
Radar WebKit Bug Importer
Comment 3 2020-02-05 23:28:51 PST
Chris Dumez
Comment 4 2020-05-29 16:29:54 PDT
Likely related to process suspension on iOS. When you lock the screen or home out of Safari, our processes get suspended shortly after. As a result, we may or may not have time to fire the visibilitychange event before we get suspended. The event normally gets fired when the process resumes if it did to have time to get fired before suspension.
Kongpheng
Comment 5 2020-07-13 16:13:45 PDT
Any updates? This bug is still reproducible on iOS 13.5.1. I included a fiddle to reproduce the issue, without the need for a video element: https://jsfiddle.net/vkpheng/pv0omfrn/. To reproduce: * On iOS Safari, open this fiddle and run it * Click Home button to background Safari * Immediately click Safari icon to bring Safari back to the foreground * Notice that no alert pops up Expected: an alert pops up, since there was a visibility change. Please advise. Thanks!
Note You need to log in before you can comment on or make changes to this bug.