-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
All browser synchronously initialize a new child navigable's window's history.length to whatever the parent's is, but the spec doesn't appear to do this anywhere in the https://html.spec.whatwg.org/multipage/document-sequences.html#create-a-new-child-navigable flow, so I think history.length
would incorrectly always return 0
there. As @domenic suggested elsewhere, we should consider running https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-document-for-history-step-application somewhere during new browsing context creation.
The trick is figuring out what to do for top-level ones. If you run the following code in DevTools:
const win = window.open();
console.log(win.history.length);
You'll get 0
in Chrome and Firefox, and 1
in Safari. Safari's behavior seems the most sane here, because if you just open a normal new tab in Chrome and Firefox you get 1
, so 0
feels like an anomaly here. After all, history.length's documentation is:
Returns the number of overall session history entries for the current traversable navigable.
So I feel like we should never observe 0
, in which case the idea of running https://html.spec.whatwg.org/multipage/browsing-the-web.html#update-document-for-history-step-application for all new BCs (after getting the proper values elsewhere) makes sense.