-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
document.open() can make a document's URL go out of sync with its history entry #3885
Comments
What do you mean with "outer document that called document.open()"? Does Safari use callee's document's URI? |
@smaug---- I meant the "entry settings object's responsible document's URL." If I have <!-- a.html -->
<iframe src=b.html></iframe>
<button onclick="reloadFrame()">Reload</button>
<script>
function reloadFrame() {
frames[0].document.open();
frames[0].document.write("New content");
frames[0].document.close();
frames[0].location.reload();
}
</script> <!-- b.html -->
Old content The frame when the Reload button is clicked will go to a.html in Safari, b.html in Chrome, and the written document elsewhere. |
I agree that ideally we'd have the document url and current history entry url match. I just did some digging around, and I agree that this is the one place where it looks like the two can diverge at least in the Firefox implementation (modulo the fact that open() creates a new history entry). That said, just mutating the URL in the history entry doesn't seem like the right thing to me. For example, consider a POST result that is then In general, what should happen to the non-URL information history entries store? At first glance in Gecko that includes pushState/popState state, saved form data, POST data (not in the spec?), scroll positions, referrer (not in the spec?), srcdoc data (but in the spec reloading re-reads this from the iframe instead?), information about the origin that initially triggered the load (not in the spec, because that part of the spec is pretty broken imo). What information like that does Safari store in history entries? What happens to it on My preference if we want a Safari-like behavior is that document.open() creates a new history entry without POST data, with the desired URI, and replaces the old history entry in the history. Basically, do more or less what There's still the issue of ending up with multiple history entries that have the same document but are not really related to each other in the way that entries corresponding to pushState or fragment navigation are... How do we want to handle those cases where the spec compares documents and assumes them matching means the entries differ by a fragment or pushState? |
@domenic and I discussed this, and the solution we came up with was that we could perhaps adopt the processing model of
where new URL in our case would be the URL of the responsible document of the entry settings object. Notably, this does not remove history entries after the current one, which makes it compatible with current Chrome and Safari behaviors. Reloading behavior would still be the same as Safari however. This should solve @bzbarsky's concern about extra data stored in the history entry like POST data. In particular, since we are reusing an existing primitive rather than introducing a new one to the platform, the question of
should resolve itself. |
The current session history handling is removed and replaced by a simpler history.replaceState-based model. This also removes the seldom implemented "replace" parameter in document.open(), and converge with Chrome and Safari by always replacing. Tests: ... Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. This PR also removes the "overridden reload" algorithm and related concepts, which were previously only implemented in Firefox and Edge, causing developer confusion evident in https://bugzilla.mozilla.org/show_bug.cgi?id=556002. Tests: web-platform-tests/wpt#12555 Tests: … (more coming soon) Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. This PR also removes the "overridden reload" algorithm and related concepts, which were previously only implemented in Firefox and Edge, causing developer confusion evident in https://bugzilla.mozilla.org/show_bug.cgi?id=556002. Tests: web-platform-tests/wpt#12555 Tests: … (more coming soon) Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix #3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes #3564. Fixes #3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
The current behavior of adding a new entry to the session history is removed, with the "replace" parameter behavior made the only option. To fix whatwg#3885, we now reuse history.replaceState()'s history model, which keeps the document's URL and the history entry URL in sync. At the same time, we restrict the history state update (including setting the document's URL) to be only run with fully active documents. Firefox already bails out for non-fully active documents (including those that are active documents), and it's not expected that there would be much usage of the URL of non-fully active documents anyway. This allows us to additionally remove the seldom implemented "replace" parameter in document.open(), whose behavior is now the default (aligning with with Chrome and Safari). The IDL is modified accordingly. Tests: web-platform-tests/wpt#12555 Tests: web-platform-tests/wpt#12634 Tests: web-platform-tests/wpt#12636 Tests: web-platform-tests/wpt#12650 Fixes whatwg#3564. Fixes whatwg#3885.
Currently, the document open steps has
However, it doesn't change the URL of its history entry.
@domenic and @rniwa agree that this is a pretty bad behavior. In particular, it breaks fragment navigation as currently spec'd, as well as some implementor expectation [1].
More visibly, this results in different behaviors when reloading a page that has been
document.open()
ed from another document:document.open()
ed document to go back to its original URL [1].location.reload()
is spec'd to do). This will cause thedocument.open()
ed document to go to the URL of outer document that calleddocument.open()
.With the constraint that we want to retain the URL-setting behavior of
document.open()
, we see two paths of going forward:In
document.open()
: set the current history entry's URL to the new URL as well. This will make a reload go to that new URL.In
document.open()
: set the current history entry's URL to the new URL as well; save the original URL in theDocument
.In
location.reload()
: use that original URL for reloading, if it's present.We prefer the first as it is significantly simpler to spec, and perhaps also to implement. Opinions?
/cc @smaug---- @bzbarsky
[1]: Chrome used to follow Safari's behavior, but during an internal refactoring
location.reload()
is made to use the history entry's URL rather than the document's URL under the assumption that they are the same. See chromium/chromium@cf62ba4.The text was updated successfully, but these errors were encountered: