Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Back-forward cache: Restoring focus #5878

Closed
rakina opened this issue Aug 31, 2020 · 9 comments · Fixed by #6696
Closed

Back-forward cache: Restoring focus #5878

rakina opened this issue Aug 31, 2020 · 9 comments · Fixed by #6696

Comments

@rakina
Copy link
Member

rakina commented Aug 31, 2020

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.

@annevk
Copy link
Member

annevk commented Aug 31, 2020

cc @cdumez @smaug----

@domenic
Copy link
Member

domenic commented Aug 31, 2020

I don't have much of substance to add, but I will say that this seems like a nice and small interop bug we could fix, compared to all the other scary bfcache business :). I hope we can get implementers to chime in.

I'm ambivalent myself between "focus is kept all the time" vs. "focus was lost, but it's back again". Maybe there are other similar features affected by bfcache which we could compare with?

@domenic
Copy link
Member

domenic commented Nov 22, 2020

Slightly related: WICG/portals#257

@domenic domenic added the agenda+ To be discussed at a triage meeting label Feb 25, 2021
@domenic
Copy link
Member

domenic commented Mar 4, 2021

Various folks discussed this today in the triage meeting (#6371). The Mozilla and Google representatives present thought that between the Firefox and Safari behavior, the Safari was probably best. Although nobody felt too strongly, the idea of firing less events (and thus running less script) during page unload and load pushed us in that direction.

This might be what the spec already says; in particular I can't find anything that changes the focused area of the document, or runs focusing or unfocusing steps, on navigation (including bfcache navigation). However, it's possible the focus fixup rule applies upon navigations, if elements in navigated-away-from-documents are not "being rendered"... but I'm unsure. That might be worth investigating.

So, I think the action items here are:

  1. Investigate "being rendered" for bfcached pages.
  2. If elements in bfcache pages are "being rendered", i.e. if other parts of the spec ecosystem expect such elements to have CSS boxes etc., then:
    1. Add a clarifying non-normative note to the definition of "being rendered" explaining that even inactive documents can have being-rendered elements.
  3. If elements in bfcache pages are not "being rendered", then:
    1. Add a clarifying non-normative note to the definition of "being rendered" explaining this.
    2. Update the normative text of focus fixup rule to not run for when documents become inactive? Or some other normative fix, like changing the "being rendered" clause in the definition of focusable area.
  4. Add a clarifying non-normative note to "focused area of the document" explaining that this does not change when a document becomes inactive or becomes active again.
  5. Write web platform tests.
  6. File browser bugs on Firefox and Chrome.
  7. Fix browser bugs :)

@domenic domenic removed the agenda+ To be discussed at a triage meeting label Apr 1, 2021
rakina added a commit to rakina/html that referenced this issue May 19, 2021
Fixes whatwg#5878. Clarifies that the focused element stays the same/not reset when a document's "full active" state changed, and no events (focus/blur) are fired
@rakina
Copy link
Member Author

rakina commented May 19, 2021

Thanks @domenic! I looked into "being rendered" & "fully active" a while back, and found that "being rendered" is still true for non-fully active documents. I've sent a PR at #6696 to add notes as you suggested, and @hiroshige-g will upload a WPT PR soon!

@rniwa
Copy link

rniwa commented May 21, 2021

yeah, we generally don't want to fire events during moving pages in & out of the back-forward cache so sticking to Safari/WebKit's behavior is desirable here unless there are some web compatibility issues or use cases that can't be addressed with that approach.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 13, 2021
Bug: 1107415, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 13, 2021
Bug: 1107415, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
@hiroshige-g
Copy link
Contributor

hiroshige-g commented Oct 13, 2021

Uploaded WPT web-platform-tests/wpt#31084, confirming the behavior described at #5878 (comment) (passing on Safari, failing on Chromium/Firefox).

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 13, 2021
Bug: 1107415, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
domenic pushed a commit that referenced this issue Oct 14, 2021
Fixes #5878. Clarifies that the focused element stays the same and is not reset when a document's fully active state is changed, and no events (focus/blur) are fired. Also clarifies that fully active does not impact "being rendered" or viewport intersection.
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 19, 2021
Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Oct 25, 2021
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
@WestonThayer
Copy link

Are there any issues tracking restoring focus for back/forward navigations to in-document fragments? Related: https://bugs.chromium.org/p/chromium/issues/detail?id=1275230

dandclark pushed a commit to dandclark/html that referenced this issue Dec 4, 2021
Fixes whatwg#5878. Clarifies that the focused element stays the same and is not reset when a document's fully active state is changed, and no events (focus/blur) are fired. Also clarifies that fully active does not impact "being rendered" or viewport intersection.
@WestonThayer
Copy link

I opened #7397 to track my previous question.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jan 16, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 8, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 8, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 9, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 9, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
aarongable pushed a commit to chromium/chromium that referenced this issue Feb 9, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Feb 9, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
mattwoodrow pushed a commit to mattwoodrow/wpt that referenced this issue Feb 15, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Feb 26, 2022
…nd BFCache, a=testonly

Automatic update from web-platform-tests
[WPT] BFCache: focus should be kept around BFCache

This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}

--

wpt-commits: a1e49a05bf46345316fd04bb4b22e5e7e8d9bc70
wpt-pr: 31084
DanielRyanSmith pushed a commit to DanielRyanSmith/wpt that referenced this issue Feb 28, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Mar 1, 2022
…nd BFCache, a=testonly

Automatic update from web-platform-tests
[WPT] BFCache: focus should be kept around BFCache

This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}

--

wpt-commits: a1e49a05bf46345316fd04bb4b22e5e7e8d9bc70
wpt-pr: 31084
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Mar 8, 2022
…nd BFCache, a=testonly

Automatic update from web-platform-tests
[WPT] BFCache: focus should be kept around BFCache

This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}

--

wpt-commits: a1e49a05bf46345316fd04bb4b22e5e7e8d9bc70
wpt-pr: 31084
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Mar 8, 2022
…nd BFCache, a=testonly

Automatic update from web-platform-tests
[WPT] BFCache: focus should be kept around BFCache

This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}

--

wpt-commits: a1e49a05bf46345316fd04bb4b22e5e7e8d9bc70
wpt-pr: 31084
mfreed7 pushed a commit to mfreed7/html that referenced this issue Jun 3, 2022
Fixes whatwg#5878. Clarifies that the focused element stays the same and is not reset when a document's fully active state is changed, and no events (focus/blur) are fired. Also clarifies that fully active does not impact "being rendered" or viewport intersection.
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
This CL adds a test to confirm that,
when page gets into and out of BFCache,

- Focus should be kept and
- blur/focus events are not fired.

The current results are

Safari: Pass
Firefox: Focus remains the same but blur/focus events are fired.
Chrome: Focus is lost.

See whatwg/html#6696
for other status and implementation bug links etc.

Bug: 1107415, 1253728, whatwg/html#5878
Change-Id: I2bb9a420de19f24d7010917f7e6ce54cba8212fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3198456
Reviewed-by: Rakina Zata Amni <rakina@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#968703}
NOKEYCHECK=True
GitOrigin-RevId: 60349a6da0ccfa946936e76665ccff67fc9eac22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

6 participants