Skip to content

Commit 472a856

Browse files
committed
Allow document.open() to desync session history and document URLs
Closes #6556. In particular, reverts document.open() to only update the document's URL, and not the session history entry's URL, like it did before ae7cf0c. Now that they can mismatch, we need to audit the cases where this might be important, which leads to the following changes: * Changes location.reload() to reload the current session history entry's URL, instead of the document's URL. This ensures that post-document.open() reload behavior is aligned with WebKit and Gecko, as tested by https://wpt.fyi/results/html/webappapis/dynamic-markup-insertion/opening-the-input-stream/reload.window.html. * Changes history.pushState()/history.replaceState() with no URL argument to default to the document's URL, instead of the current session history's URL. This ensures that post-document.open() pushState()/replaceState() behavior is aligned with all engines, as tested by web-platform-tests/wpt#28826. This also modernizes and makes a bit more precise the location.reload() method steps. The user-initiated reload steps remain vague; #6600 will tackle those.
1 parent 92bf07c commit 472a856

File tree

1 file changed

+74
-39
lines changed

1 file changed

+74
-39
lines changed

source

Lines changed: 74 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83619,7 +83619,16 @@ interface <dfn>BarProp</dfn> {
8361983619
data-x="struct item">items</span>:</p>
8362083620

8362183621
<ul>
83622-
<li><p><dfn data-x="she-url">URL</dfn>, a <span>URL</span></p></li>
83622+
<li>
83623+
<p><dfn data-x="she-url">URL</dfn>, a <span>URL</span></p>
83624+
83625+
<p class="warning">This <a href="#warning-document-open-url-mismatch">doesn't necessarily
83626+
match</a> the <span data-x="she-document">document</span>'s <span
83627+
data-x="concept-document-URL">URL</span>. In general, to find the "current URL" prefer using the
83628+
appropriate <code>Document</code>'s <span data-x="concept-document-URL">URL</span>; a
83629+
<span>session history entry</span>'s <span data-x="she-url">URL</span> is only to be used for
83630+
session history traversal and restoration.</p>
83631+
</li>
8362383632

8362483633
<li>
8362583634
<p><dfn data-x="she-document">document</dfn>, a <code>Document</code> or null</p>
@@ -84178,8 +84187,8 @@ interface <dfn>History</dfn> {
8417884187
<li><p>Let <var>serializedData</var> be
8417984188
<span>StructuredSerializeForStorage</span>(<var>data</var>). Rethrow any exceptions.</p></li>
8418084189

84181-
<li><p>Let <var>newURL</var> be the <span>session history</span>'s <span>current entry</span>'s
84182-
<span data-x="she-url">URL</span>.</p></li>
84190+
<li><p>Let <var>newURL</var> be <var>document</var>'s <span
84191+
data-x="concept-document-URL">URL</span>.</p></li>
8418384192

8418484193
<li>
8418584194
<p>If <var>url</var> is not null, then:</p>
@@ -85086,52 +85095,56 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
8508685095
<p class="note">The <code data-x="dom-location-replace">replace()</code> method intentionally has
8508785096
no security check.</p>
8508885097

85089-
<p>When the <dfn method for="Location"><code data-x="dom-location-reload">reload()</code></dfn>
85090-
method is invoked, the user agent must run the appropriate steps from the following list:</p>
85091-
85092-
<dl class="switch">
85093-
<dt>If this <code>Location</code> object's <span>relevant <code>Document</code></span> is
85094-
null</dt>
85095-
85096-
<dd><p>Return.</p></dd>
85098+
<p>The <dfn method for="Location"><code data-x="dom-location-reload">reload()</code></dfn> method
85099+
steps are:</p>
8509785100

85098-
<dt>If this <code>Location</code> object's <span>relevant <code>Document</code></span>'s <span
85099-
data-x="concept-document-origin">origin</span> is not <span>same origin-domain</span> with the
85100-
<span>entry settings object</span>'s <span
85101-
data-x="concept-settings-object-origin">origin</span></dt>
85101+
<ol>
85102+
<li><p>Let <var>document</var> be <span>this</span>'s <span>relevant
85103+
<code>Document</code></span>.</p></li>
8510285104

85103-
<dd><p>Throw a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p></dd>
85105+
<li><p>Let <var>browsingContext</var> be <var>document</var>'s <span
85106+
data-x="concept-document-bc">browsing context</span>.</p></li>
8510485107

85105-
<dt>If the currently executing <span data-x="concept-task">task</span> is the dispatch of a <code
85106-
data-x="event-resize">resize</code> event in response to the user resizing the <span>browsing
85107-
context</span></dt>
85108+
<li><p>If <var>document</var> is null, then return.</p></li>
8510885109

85109-
<dd><p>Repaint the <span>browsing context</span> and return.</p></dd> <!-- this
85110-
theoretically would have no effect but in practice can be useful to work around rendering bugs.
85111-
-->
85110+
<li><p>If <var>document</var>'s <span data-x="concept-document-origin">origin</span> is not
85111+
<span>same origin-domain</span> with the <span>entry settings object</span>'s <span
85112+
data-x="concept-settings-object-origin">origin</span>, then throw a
85113+
<span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p></li>
8511285114

85113-
<dt>If the <span>browsing context</span>'s <span>active document</span> is <span>an
85114-
<code>iframe</code> <code data-x="attr-iframe-srcdoc">srcdoc</code> document</span></dt>
85115+
<li><p>If <span>this</span>'s <span>relevant agent</span>'s <span
85116+
data-x="concept-agent-event-loop">event loop</span>'s <span>currently running task</span> is the
85117+
dispatch of a <code data-x="event-resize">resize</code> event in response to the user resizing
85118+
the <span>browsing context</span>, then repaint the <span>browsing context</span> and
85119+
return.</p></li>
85120+
<!-- this theoretically would have no effect but in practice can be useful to work around
85121+
rendering bugs. -->
8511585122

85116-
<dd><p><span data-x="process the iframe attributes">Reprocess the <code>iframe</code>
85117-
attributes</span> of the <span>browsing context</span>'s <span
85118-
data-x="bc-container">container</span>.</p></dd>
85123+
<li><p>If <var>document</var> is <span>an <code>iframe</code> <code
85124+
data-x="attr-iframe-srcdoc">srcdoc</code> document</span>, then <span data-x="process the iframe
85125+
attributes">reprocess the <code>iframe</code> attributes</span> of <var>browsingContext</var>'s
85126+
<span data-x="bc-container">container</span> and return.</p></li>
8511985127

85120-
<dt>Otherwise</dt>
85128+
<li>
85129+
<p><span>Navigate</span><!--DONAV location.reload()--> <var>browsingContext</var> to
85130+
<var>browsingContext</var>'s <span>session history</span>'s <span>current entry</span>'s <span
85131+
data-x="she-url">URL</span>, with <var><span>exceptionsEnabled</span></var> set to true, <var
85132+
data-x="navigation-hh">historyHandling</var> set to "<code data-x="hh-reload">reload</code>",
85133+
and the <span>source browsing context</span> set to <var>browsingContext</var>.</p>
8512185134

85122-
<dd><p><span>Navigate</span><!--DONAV location.reload()--> the <span>browsing context</span> to
85123-
this <code>Location</code> object's <span>relevant <code>Document</code></span>'s <span
85124-
data-x="concept-document-url">URL</span>, with <var><span>exceptionsEnabled</span></var> set to
85125-
true, <var data-x="navigation-hh">historyHandling</var> set to "<code
85126-
data-x="hh-reload">reload</code>", and the <span>source browsing context</span> set to the
85127-
<span>browsing context</span> being navigated.</p></dd>
85135+
<p class="note">This is different than navigating to <var>document</var>'s <span
85136+
data-x="concept-document-url">URL</span>, due to the potential for <a
85137+
href="#warning-document-open-url-mismatch">mismatches caused by <code
85138+
data-x="dom-document-open">document.open()</code></a>.</p>
8512885139

85129-
<!-- It appears that document.reload() always uses GET and does not, e.g., re-POST. Thus the
85130-
difference between using the document's URL here, and "the same resource as that Document" below
85131-
in the user-triggered reload section. -->
85140+
<!-- It appears that document.reload() always uses GET and does not, e.g., re-POST. Thus the
85141+
difference between using the document's URL here, and "the same resource as that Document" below
85142+
in the user-triggered reload section. -->
8513285143

85133-
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=141 defends the source browsing context claim; submit, eval document.referrer, reload, eval document.referrer. -->
85134-
</dl>
85144+
<!-- https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=141 defends the source
85145+
browsing context claim; submit, eval document.referrer, reload, eval document.referrer. -->
85146+
</li>
85147+
</ol>
8513585148

8513685149
<p>When a user requests that the <span>active document</span> of a <span>browsing context</span>
8513785150
be reloaded through a user interface element, the user agent should <span>navigate</span><!--DONAV
@@ -94075,6 +94088,28 @@ document.body.appendChild(frame)</code></pre>
9407594088
<li><p>If <var>entryDocument</var> is not <var>document</var>, then set <var>newURL</var>'s
9407694089
<span data-x="concept-url-fragment">fragment</span> to null.</p></li>
9407794090

94091+
<li>
94092+
<p>Set <var>document</var>'s <span data-x="concept-document-url">URL</span> to
94093+
<var>newURL</var>.</p>
94094+
94095+
<div class="note">
94096+
<p>The main purpose of this step is to allow code such as the following:</p>
94097+
94098+
<pre><code class="js">const w = window.open();
94099+
w.document.open();
94100+
w.document.write("&lt;img src='image.png'>");</code></pre>
94101+
94102+
<p>to resolve the <code data-x="">image.png</code> URL relative to the caller, instead of
94103+
relative to <code>about:blank</code>.</p>
94104+
</div>
94105+
94106+
<p class="warning" id="warning-document-open-url-mismatch">This can cause
94107+
<var>document</var>'s <span data-x="concept-document-url">URL</span> to mismatch its
94108+
corresponding <span>session history entry</span>'s <span data-x="she-url">URL</span>. This
94109+
mismatch is required for web compatibility; see <a
94110+
href="https://github.com/whatwg/html/issues/6556">issue #6556</a>.</p>
94111+
</li>
94112+
9407894113
<li><p>Run the <span>URL and history update steps</span> with <var>document</var> and
9407994114
<var>newURL</var>.</p></li>
9408094115
</ol>

0 commit comments

Comments
 (0)