Skip to content

Commit

Permalink
Fire visibilitychange events explicitly
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
noamr authored and mfreed7 committed Jun 3, 2022
1 parent e8599b2 commit 415f98c
Showing 1 changed file with 30 additions and 29 deletions.
59 changes: 30 additions & 29 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -9317,6 +9317,7 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {

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

// <a href="#Document-partial">also has obsolete members</a>
};
Expand Down Expand Up @@ -88456,13 +88457,9 @@ new PaymentRequest(&hellip;); // Allowed to use

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

<li>
<p>Run any <dfn>session history document visibility change steps</dfn> for
<var>newDocument</var> that are defined by <span>other applicable specifications</span>.</p>

<p class="note">This is specifically intended for use by <cite>Page Visibility</cite>. <ref
spec=PAGEVIS></p>
</li>
<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
initialized to true.</p></li>

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

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

<li><p>If <var>document</var>'s <span>page showing</span> flag is false, then jump to the
step labeled <i>unload event</i> below (i.e. skip firing the <code
data-x="event-pagehide">pagehide</code> event and don't rerun the <span>unloading document
visibility change steps</span>).</p></li>

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

<li><p>If the user agent does not intend to keep <var>document</var> alive
in a <span>session history entry</span> (such that it can be reused later on <span
data-x="traverse the history">history traversal</span>), set <var>document</var>'s
<i data-x="concept-document-salvageable">salvageable</i> state to false.</p></li>

<li><p><span>Fire a page transition event</span> named <code
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
object</span> with <var>document</var>'s <i data-x="concept-document-salvageable">salvageable</i>
state.</p></li>

<li>
<p>Run any <dfn>unloading document visibility change steps</dfn> for <var>document</var> that
are defined by <span>other applicable specifications</span>.</p>
<p>If <var>document</var>'s <span>page showing</span> flag is true:</p>

<p class="note">This is specifically intended for use by <cite>Page Visibility</cite>.
<ref spec=PAGEVIS></p>
</li>
<ol>
<li><p>Set <var>document</var>'s <span>page showing</span> flag to false.</p></li>

<li><p><span>Fire a page transition event</span> named <code
data-x="event-pagehide">pagehide</code> at <var>document</var>'s <span>relevant global
object</span> with <var>document</var>'s <i
data-x="concept-document-salvageable">salvageable</i> state.</p></li>

<li><p>Fire an event named <code data-x="event-visibilitychange">visibilitychange</code> at
<var>newDocument</var>, with its <code data-x="dom-Event-bubbles">bubbles</code> attribute
initialized to true.</p></li>
</ol>
</li>

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

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

<li><p>If <var>unloadTimingInfo</var> is not null, then set <var>unloadTimingInfo</var>'s
<span>unload event end time</span> to the <span>current high resolution time</span> given
Expand Down Expand Up @@ -95134,6 +95127,7 @@ typedef <span>OnBeforeUnloadEventHandlerNonNull</span>? <dfn typedef>OnBeforeUnl
<tr><th><span data-x="event handlers">Event handler</span> <th><span>Event handler event type</span>
<tbody>
<tr><td><dfn attribute for="Document"><code data-x="handler-onreadystatechange">onreadystatechange</code></dfn> <td> <code data-x="event-readystatechange">readystatechange</code>
<tr><td><dfn attribute for="Document"><code data-x="handler-onvisibilitychange">onvisibilitychange</code></dfn> <td> <code data-x="event-visibilitychange">visibilitychange</code>
</table>


Expand Down Expand Up @@ -125597,6 +125591,13 @@ INSERT INTERFACES HERE
<td> <code>Window</code>
<td> Fired at the <code>Window</code> object when the page is going away

<tr> <!-- visibilitychange -->
<td> <dfn event for="Document"><code data-x="event-visibilitychange">visibilitychange</code></dfn>
<td> <code>Event</code>
<td> <code>Document</code>
<td> Fired at the <code>Document</code> object when the page becomes visible or hidden to the
user. <ref spec=PAGEVIS>

</table>

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

0 comments on commit 415f98c

Please sign in to comment.