Skip to content

Back-forward cache: Restoring focus #5878

@rakina

Description

@rakina

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. The focus event is only fired when the element initially gets focused.
  • Firefox: The focused element stays focused. The blur event is fired after pagehide (when navigating away) but before pageshow (when navigating back). The focus event is fired for the second time after pageshow.
  • Chrome: The focused element will lose focus on navigation away from the page (with the blur event fired before pagehide), 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions