Skip to content

Commit 3285b98

Browse files
authored
Fire visibilitychange events explicitly
Fire the event when unloading or traversing history, instead of relying on hooks in other specs. See w3c/page-visibility#51 and w3c/page-visibility#73.
1 parent dbdc4bd commit 3285b98

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

source

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9315,6 +9315,7 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
93159315

93169316
// special <span>event handler IDL attributes</span> that only apply to Document objects
93179317
[<span>LegacyLenientThis</span>] attribute <span>EventHandler</span> <span data-x="handler-onreadystatechange">onreadystatechange</span>;
9318+
attribute <span>EventHandler</span> <span data-x="handler-onvisibilitychange">onvisibilitychange</span>;
93189319

93199320
// <a href="#Document-partial">also has obsolete members</a>
93209321
};
@@ -88453,13 +88454,9 @@ new PaymentRequest(&hellip;); // Allowed to use
8845388454

8845488455
<li><p>Set <var>newDocument</var>'s <span>page showing</span> flag to true.</p></li>
8845588456

88456-
<li>
88457-
<p>Run any <dfn>session history document visibility change steps</dfn> for
88458-
<var>newDocument</var> that are defined by <span>other applicable specifications</span>.</p>
88459-
88460-
<p class="note">This is specifically intended for use by <cite>Page Visibility</cite>. <ref
88461-
spec=PAGEVIS></p>
88462-
</li>
88457+
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
88458+
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
88459+
initialized to true.</p></li>
8846388460

8846488461
<li><p><span>Fire a page transition event</span> named <code
8846588462
data-x="event-pageshow">pageshow</code> at <var>newDocument</var>'s <span>relevant global
@@ -88912,40 +88909,36 @@ dictionary <dfn dictionary>PageTransitionEventInit</dfn> : <span>EventInit</span
8891288909

8891388910
<li><p>Increase <var>document</var>'s <span>unload counter</span> by 1.</p></li>
8891488911

88915-
<li><p>If <var>document</var>'s <span>page showing</span> flag is false, then jump to the
88916-
step labeled <i>unload event</i> below (i.e. skip firing the <code
88917-
data-x="event-pagehide">pagehide</code> event and don't rerun the <span>unloading document
88918-
visibility change steps</span>).</p></li>
88919-
88920-
<li><p>Set <var>document</var>'s <span>page showing</span> flag to false.</p></li>
88921-
8892288912
<li><p>If the user agent does not intend to keep <var>document</var> alive
8892388913
in a <span>session history entry</span> (such that it can be reused later on <span
8892488914
data-x="traverse the history">history traversal</span>), set <var>document</var>'s
8892588915
<i data-x="concept-document-salvageable">salvageable</i> state to false.</p></li>
8892688916

88927-
<li><p><span>Fire a page transition event</span> named <code
88928-
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
88929-
object</span> with <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i>
88930-
state.</p></li>
88931-
8893288917
<li>
88933-
<p>Run any <dfn>unloading document visibility change steps</dfn> for <var>document</var> that
88934-
are defined by <span>other applicable specifications</span>.</p>
88918+
<p>If <var>document</var>'s <span>page showing</span> flag is true:</p>
8893588919

88936-
<p class="note">This is specifically intended for use by <cite>Page Visibility</cite>.
88937-
<ref spec=PAGEVIS></p>
88938-
</li>
88920+
<ol>
88921+
<li><p>Set <var>document</var>'s <span>page showing</span> flag to false.</p></li>
88922+
88923+
<li><p><span>Fire a page transition event</span> named <code
88924+
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
88925+
object</span> with <var>document</var>'s <i
88926+
data-x="concept-document-salvageable">salvageable</i> state.</p></li>
88927+
88928+
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
88929+
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
88930+
initialized to true.</p></li>
88931+
</ol>
88932+
</li>
8893988933

8894088934
<li><p>If <var>unloadTimingInfo</var> is not null, then set <var>unloadTimingInfo</var>'s
8894188935
<span>unload event start time</span> to the <span>current high resolution time</span> given
8894288936
<var>document</var>'s <span>relevant global object</span>.</p></li>
8894388937

88944-
<li><p><i>Unload event</i>: If <var>document</var>'s <i
88945-
data-x="concept-document-salvageable">salvageable</i> state is false, then <span
88946-
data-x="concept-event-fire">fire an event</span> named <code data-x="event-unload">unload</code>
88947-
at <var>document</var>'s <span>relevant global object</span>, with <var>legacy target override
88948-
flag</var> set.</p></li>
88938+
<li><p>If <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i> state is
88939+
false, then <span data-x="concept-event-fire">fire an event</span> named
88940+
<code data-x="event-unload">unload</code> at <var>document</var>'s
88941+
<span>relevant global object</span>, with <var>legacy target override flag</var> set.</p></li>
8894988942

8895088943
<li><p>If <var>unloadTimingInfo</var> is not null, then set <var>unloadTimingInfo</var>'s
8895188944
<span>unload event end time</span> to the <span>current high resolution time</span> given
@@ -95130,6 +95123,7 @@ typedef <span>OnBeforeUnloadEventHandlerNonNull</span>? <dfn typedef>OnBeforeUnl
9513095123
<tr><th><span data-x="event handlers">Event handler</span> <th><span>Event handler event type</span>
9513195124
<tbody>
9513295125
<tr><td><dfn attribute for="Document"><code data-x="handler-onreadystatechange">onreadystatechange</code></dfn> <td> <code data-x="event-readystatechange">readystatechange</code>
95126+
<tr><td><dfn attribute for="Document"><code data-x="handler-onvisibilitychange">onvisibilitychange</code></dfn> <td> <code data-x="event-visibilitychange">visibilitychange</code>
9513395127
</table>
9513495128

9513595129

@@ -125586,6 +125580,13 @@ INSERT INTERFACES HERE
125586125580
<td> <code>Window</code>
125587125581
<td> Fired at the <code>Window</code> object when the page is going away
125588125582

125583+
<tr> <!-- visibilitychange -->
125584+
<td> <dfn event for="Document"><code data-x="event-visibilitychange">visibilitychange</code></dfn>
125585+
<td> <code>Event</code>
125586+
<td> <code>Document</code>
125587+
<td> Fired at the <code>Document</code> object when the page becomes visible or hidden to the
125588+
user. <ref spec=PAGEVIS>
125589+
125589125590
</table>
125590125591

125591125592
<p class="note">See also <a href="#mediaevents">media element events</a> and <a

0 commit comments

Comments
 (0)