Bug 225265 - visibilitychange fires in a bad order
Summary: visibilitychange fires in a bad order
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Safari 14
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-04-30 20:15 PDT by Rob Snow
Modified: 2022-09-29 16:38 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Rob Snow 2021-04-30 20:15:05 PDT
we're trying to use visibility change to determine if we should show a focus ring or not when a user is coming back to a page
unfortunately in Safari the order of events is not what we expected
when coming back to a tab, the focus events run first, then visibilitychange
this is opposite to what happens when the user leaves the tab where blur runs, then visibilitychange runs

I think that running visibilitychange last when leaving and first when arriving makes the most sense.
https://jsfiddle.net/snowystinger/fhxjm2pz/2/

On another note, I also noticed that focus is fired twice.
Comment 1 Chris Dumez 2021-05-03 08:52:04 PDT
Adding Wenson to CC. On my Safari, I am having trouble even focusing the button. Even clicking the button does not seem to fire its focus event.

On Chrome, I can click the button and I get the focus event. The order of the events is what I would expect in Chrome.
Comment 2 Radar WebKit Bug Importer 2021-05-07 20:16:14 PDT
<rdar://problem/77685855>
Comment 3 Ahmad Saleem 2022-09-29 15:28:32 PDT
*** Safari 16 ***

"visibility changed", "hidden"
"visibility changed", "visible"

*** Chrome Canary 108 ***

visibility changed hidden
visibility changed visible

*** Firefox Nightly 107 ***

visibility changed hidden show:57:33
visibility changed visible show:57:33

______

All browsers are matching with each other, do we need to do anything more? Thanks!
Comment 4 Rob Snow 2022-09-29 16:38:50 PDT
Doesn't look like they all behave the same. Note the order of blur/focus VS visibility. Everything is still in the same order as it was when I first filed the issue.

*** Safari 16 ***
[Log] blurred (show, line 57)
[Log] visibility changed – "hidden" (show, line 57)
[Log] focused (show, line 57)
[Log] visibility changed – "visible" (show, line 57)

*** Chrome 105 ***
blurred
visibility changed hidden
visibility changed visible
focused

*** Firefox 105 ***
blurred show:57:33
visibility changed hidden show:57:33
visibility changed visible show:57:33
focused show:57:33

See how Safari still fires visibility change after focused instead of before?