-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
Spinning off from #6197 (comment).
Test page: https://boom-bath.glitch.me/session-history-2.html
- Press "Set history.state to 'foo'"
- Then press any of the other three four buttons/links.
Results:
- Firefox:
location.reload()retainshistory.state. All other mechanisms clear it. - Chrome:
history.stateis always retained. - Safari: ???
Also of note: both browsers agree that overall document scroll position is retained on location.reload() and cleared otherwise. Chrome, however, clears the textbox scroll position and its value (if updated) in all cases, including location.reload(); Firefox retains those pieces of data in location.reload().
At a spec level, discussed a bit in #6197 (comment), we have several distinguishable actions:
- (X) Navigate normally to the same URL as the current URL
- (Y) Navigate with replacement (
location.replace()) to the same URL as the current URL - (Z) Navigate with reloading (
location.reload()) to the same URL as the current URL
and we have the following potential behaviors:
- (A) Keep the current session history entry. Just replace its document.
- (A') Keep the current session history entry. Replace its document and maybe reset a few other things.
- (B) Throw away the current session history entry. Create a new one with a new document, the same URL, and defaults for everything else.
- (B') Remove the current session history entry. Create a new one with a new document, the same URL, and potentially copy over some of the other stuff from the old one.
So from I can see:
- Firefox performs (A) or maybe (A') for (Z), but performs (B) for (X) and (Y).
- Chrome performs (B') for (X), (Y), and (Z), copying over at least
history.state, but not copying over most scroll positions. It does copy over the main document scroll position for case (Z).
I'm not sure what the best behavior is here. At a spec level, the simplest thing would be (B) for all cases (X), (Y), and (Z), but that matches no browsers. This is all complicated by the fact that the other pieces of a session history entry are harder to test and in some cases not totally specified.