<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>225265</bug_id>
          
          <creation_ts>2021-04-30 20:15:05 -0700</creation_ts>
          <short_desc>visibilitychange fires in a bad order</short_desc>
          <delta_ts>2022-09-29 16:38:50 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>UI Events</component>
          <version>Safari 14</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Rob Snow">rsnow</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1755910</commentid>
    <comment_count>0</comment_count>
    <who name="Rob Snow">rsnow</who>
    <bug_when>2021-04-30 20:15:05 -0700</bug_when>
    <thetext>we&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1756192</commentid>
    <comment_count>1</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2021-05-03 08:52:04 -0700</bug_when>
    <thetext>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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1758149</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-05-07 20:16:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/77685855&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902205</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2022-09-29 15:28:32 -0700</bug_when>
    <thetext>*** Safari 16 ***

&quot;visibility changed&quot;, &quot;hidden&quot;
&quot;visibility changed&quot;, &quot;visible&quot;

*** 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!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902221</commentid>
    <comment_count>4</comment_count>
    <who name="Rob Snow">rsnow</who>
    <bug_when>2022-09-29 16:38:50 -0700</bug_when>
    <thetext>Doesn&apos;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 – &quot;hidden&quot; (show, line 57)
[Log] focused (show, line 57)
[Log] visibility changed – &quot;visible&quot; (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?</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>