From 415f98c6204877eabc974caeee72dba80440fb42 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 15 Oct 2021 20:47:58 +0300 Subject: [PATCH] Fire visibilitychange events explicitly Fire the event when unloading or traversing history, instead of relying on hooks in other specs. See https://github.com/w3c/page-visibility/issues/51 and https://github.com/w3c/page-visibility/pull/73. --- source | 59 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/source b/source index ded3ed47af2..b3f95d56b71 100644 --- a/source +++ b/source @@ -9317,6 +9317,7 @@ partial interface Document { // special event handler IDL attributes that only apply to Document objects [LegacyLenientThis] attribute EventHandler onreadystatechange; + attribute EventHandler onvisibilitychange; // also has obsolete members }; @@ -88456,13 +88457,9 @@ new PaymentRequest(…); // Allowed to use
  • Set newDocument's page showing flag to true.

  • -
  • -

    Run any session history document visibility change steps for - newDocument that are defined by other applicable specifications.

    - -

    This is specifically intended for use by Page Visibility.

    -
  • +
  • Fire an event named visibilitychange at + newDocument, with its bubbles attribute + initialized to true.

  • Fire a page transition event named pageshow at newDocument's relevant global @@ -88915,40 +88912,36 @@ dictionary PageTransitionEventInit : EventInit

    Increase document's unload counter by 1.

  • -
  • If document's page showing flag is false, then jump to the - step labeled unload event below (i.e. skip firing the pagehide event and don't rerun the unloading document - visibility change steps).

  • - -
  • Set document's page showing flag to false.

  • -
  • If the user agent does not intend to keep document alive in a session history entry (such that it can be reused later on history traversal), set document's salvageable state to false.

  • -
  • Fire a page transition event named pagehide at document's relevant global - object with document's salvageable - state.

  • -
  • -

    Run any unloading document visibility change steps for document that - are defined by other applicable specifications.

    +

    If document's page showing flag is true:

    -

    This is specifically intended for use by Page Visibility. -

    -
  • +
      +
    1. Set document's page showing flag to false.

    2. + +
    3. Fire a page transition event named pagehide at document's relevant global + object with document's salvageable state.

    4. + +
    5. Fire an event named visibilitychange at + newDocument, with its bubbles attribute + initialized to true.

    6. +
    +
  • If unloadTimingInfo is not null, then set unloadTimingInfo's unload event start time to the current high resolution time given document's relevant global object.

  • -
  • Unload event: If document's salvageable state is false, then fire an event named unload - at document's relevant global object, with legacy target override - flag set.

  • +
  • If document's salvageable state is + false, then fire an event named + unload at document's + relevant global object, with legacy target override flag set.

  • If unloadTimingInfo is not null, then set unloadTimingInfo's unload event end time to the current high resolution time given @@ -95134,6 +95127,7 @@ typedef OnBeforeUnloadEventHandlerNonNull? OnBeforeUnl Event handler Event handler event type onreadystatechange readystatechange + onvisibilitychange visibilitychange @@ -125597,6 +125591,13 @@ INSERT INTERFACES HERE Window Fired at the Window object when the page is going away + + visibilitychange + Event + Document + Fired at the Document object when the page becomes visible or hidden to the + user. +

    See also media element events and