-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Description
It looks like focus works differently with bfcache in Safari, Firefox, and Chrome (thanks @tkent-google for noticing!)
If we navigate away from a page that has a focused element (e.g. submitting a text-input form), and we go back & restore it from bfcache (tester page) :
- Safari: The focused element stays focused. The
blur
event is never fired. Thefocus
event is only fired when the element initially gets focused. - Firefox: The focused element stays focused. The
blur
event is fired afterpagehide
(when navigating away) but before pageshow (when navigating back). Thefocus
event is fired for the second time afterpageshow
. - Chrome: The focused element will lose focus on navigation away from the page (with the
blur
event fired beforepagehide
), and won't be focused again when we navigate back.
I think it would be ideal to restore the focused element when navigating back (like Safari & Firefox is currently doing), but I'm not sure whether it should be "focus is kept all this time" (so no blur
event should be fired), or "focus was lost, but it's back again" (so we fire blur
when navigating away, then fire focus
when navigating back). Maybe the latter makes more sense as the entire document/page is no longer in focus after we navigate away from it.