Skip to content

Commit b3b7add

Browse files
authored
Change beforeunload, unload, and bfcache interaction
Per #5748 (comment), removes the requirement that beforeunload event listeners being fired cause a document to become unsalveagable (i.e., ineligible for bfcache). Instead, unsalveagability is left more explicitly up to the user agent. Additionally, changes navigation to no longer dispatch unload events for documents which are kept alive in the session history (bfcache). Closes #5748.
1 parent 1076db6 commit b3b7add

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

source

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85167,8 +85167,8 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8516785167
<p>Things that can cause the page to be unsalvageable include:</p>
8516885168

8516985169
<ul class="brief">
85170-
<li>Listening for <code data-x="event-beforeunload">beforeunload</code> events
85171-
<li>Listening for <code data-x="event-unload">unload</code> events
85170+
<li>The user agent decided to not keep the <code>Document</code> alive in a <span>session
85171+
history entry</span> after <span data-x="unload a document">unload</span>
8517285172
<li>Having <code>iframe</code>s that are not salvageable
8517385173
<li>Active <code>WebSocket</code> objects
8517485174
<li><span data-x="abort a document">Aborting a <code>Document</code></span>
@@ -85220,12 +85220,12 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8522085220

8522185221
<p>A <code>Document</code> has a <dfn
8522285222
data-x="concept-document-salvageable"><i>salvageable</i></dfn> state, which must initially be
85223-
true, a <dfn>fired unload</dfn> flag, which must initially be false, and a <dfn>page showing</dfn>
85224-
flag, which must initially be false. The <span>page showing</span> flag is used to ensure that
85225-
scripts receive <code data-x="event-pageshow">pageshow</code> and <code
85226-
data-x="event-pagehide">pagehide</code> events in a consistent manner (e.g. that they never
85227-
receive two <code data-x="event-pagehide">pagehide</code> events in a row without an intervening
85228-
<code data-x="event-pageshow">pageshow</code>, or vice versa).</p>
85223+
true, and a <dfn>page showing</dfn> flag, which must initially be false. The <span>page
85224+
showing</span> flag is used to ensure that scripts receive <code
85225+
data-x="event-pageshow">pageshow</code> and <code data-x="event-pagehide">pagehide</code> events
85226+
in a consistent manner (e.g. that they never receive two <code
85227+
data-x="event-pagehide">pagehide</code> events in a row without an intervening <code
85228+
data-x="event-pageshow">pageshow</code>, or vice versa).</p>
8522985229

8523085230
<p><span data-x="event loop">Event loops</span> have a <dfn>termination nesting level</dfn>
8523185231
counter, which must initially be 0.</p>
@@ -85253,10 +85253,6 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8525385253
<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
8525485254
1.</p></li>
8525585255

85256-
<li><p>If any event listeners were triggered by the earlier <i>dispatch</i> step, then set
85257-
<var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state to
85258-
false.</p></li>
85259-
8526085256
<li>
8526185257
<p>If <var>document</var>'s <span>active sandboxing flag set</span> does not have its
8526285258
<span>sandboxed modals flag</span> set, and the <code
@@ -85292,15 +85288,11 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8529285288

8529385289
<ol>
8529485290
<li><p><span>Prompt to unload</span> <var>browsingContext</var>'s <span>active
85295-
document</span> with the <var>recursiveFlag</var> set. If the user <span>refused to allow
85296-
the document to be unloaded</span>, then the user implicitly also <span data-x="refused to
85297-
allow the document to be unloaded">refused to allow <var>document</var> to be
85298-
unloaded</span>; <span>break</span>.</p></li>
85299-
85300-
<li><p>If the <i data-x="concept-document-salvageable">salvageable</i> state of
85301-
<var>browsingContext</var>'s <span>active document</span> is false, then set the <i
85302-
data-x="concept-document-salvageable">salvageable</i> state of <var>document</var> to
85303-
false.</p></li>
85291+
document</span> with the <var>recursiveFlag</var> set.</p></li>
85292+
85293+
<li><p>If the user <span>refused to allow the document to be unloaded</span>, then the user
85294+
implicitly also <span data-x="refused to allow the document to be unloaded">refused to allow
85295+
<var>document</var> to be unloaded</span>; <span>break</span>.</p></li>
8530485296
</ol>
8530585297
</li>
8530685298
</ol>
@@ -85327,6 +85319,11 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8532785319

8532885320
<li><p>Set <var>document</var>'s <span>page showing</span> flag to false.</p></li>
8532985321

85322+
<li><p>If the user agent does not intend to keep <var>document</var> alive
85323+
in a <span>session history entry</span> (such that it can be reused later on <span
85324+
data-x="traverse the history">history traversal</span>), set <var>document</var>'s
85325+
<i data-x="concept-document-salvageable">salvageable</i> state to false.</p></li>
85326+
8533085327
<li><p><span data-x="concept-event-fire">Fire an event</span> named <code
8533185328
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
8533285329
object</span>, using <code>PageTransitionEvent</code>, with the <code
@@ -85342,18 +85339,15 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8534285339
<ref spec=PAGEVIS></p>
8534385340
</li>
8534485341

85345-
<li><p><i>Unload event</i>: If <var>document</var>'s <span>fired unload</span> flag is
85346-
false, then <span data-x="concept-event-fire">fire an event</span> named <code
85347-
data-x="event-unload">unload</code> at <var>document</var>'s <span>relevant global object</span>,
85348-
with <var>legacy target override flag</var> set.</p></li>
85342+
<li><p><i>Unload event</i>: If <var>document</var>'s <i
85343+
data-x="concept-document-salvageable">salvageable</i> state is false, then <span
85344+
data-x="concept-event-fire">fire an event</span> named <code data-x="event-unload">unload</code>
85345+
at <var>document</var>'s <span>relevant global object</span>, with <var>legacy target override
85346+
flag</var> set.</p></li>
8534985347

8535085348
<li><p>Decrease the <span>event loop</span>'s <span>termination nesting level</span> by
8535185349
one.</p></li>
8535285350

85353-
<li><p>If any event listeners were triggered by the earlier <i>unload event</i> step, then set
85354-
<var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state
85355-
to false and set <var>document</var>'s <span>fired unload</span> flag to true.</p></li>
85356-
8535785351
<li><p>Run any <span>unloading document cleanup steps</span> for <var>document</var> that are
8535885352
defined by this specification and <span>other applicable specifications</span>.</p></li>
8535985353

0 commit comments

Comments
 (0)