Window: pagereveal event

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The pagereveal event is fired when a document is first rendered, either when loading a fresh document from the network or activating a document (either from back/forward cache (bfcache) or prerender).

This is useful in the case of cross-document (MPA) view transitions for manipulating an active transition from the inbound page of a navigation. For example, you might wish to skip the transition, or customize the inbound transition animation via JavaScript.

Syntax

Use the event name in methods like addEventListener(), or set an event handler property.

js
addEventListener("pagereveal", (event) => { })

onpagereveal = (event) => { }

Event type

A PageRevealEvent. Inherits from Event.

Event PageRevealEvent

Event properties

PageRevealEvent.viewTransition Read only

Returns the ViewTransition object representing the inbound cross-document view transition, if one is active when the event is fired. If this is not the case, it returns null.

Examples

js
window.addEventListener("pagereveal", async (e) => {
  // If the "from" history entry does not exist, return
  if (!navigation.activation.from) return;

  // Only run this if an active view transition exists
  if (e.viewTransition) {
    const fromUrl = new URL(navigation.activation.from.url);
    const currentUrl = new URL(navigation.activation.entry.url);

    // Went from profile page to homepage
    // ~> Set VT names on the relevant list item
    if (isProfilePage(fromUrl) && isHomePage(currentUrl)) {
      const profile = extractProfileNameFromUrl(fromUrl);

      // Set view-transition-name values on the elements to animate
      document.querySelector(`#${profile} span`).style.viewTransitionName =
        "name";
      document.querySelector(`#${profile} img`).style.viewTransitionName =
        "avatar";

      // Remove names after snapshots have been taken
      // so that we're ready for the next navigation
      await e.viewTransition.ready;
      document.querySelector(`#${profile} span`).style.viewTransitionName =
        "none";
      document.querySelector(`#${profile} img`).style.viewTransitionName =
        "none";
    }

    // Went to profile page
    // ~> Set VT names on the main title and image
    if (isProfilePage(currentUrl)) {
      // Set view-transition-name values on the elements to animate
      document.querySelector(`#detail main h1`).style.viewTransitionName =
        "name";
      document.querySelector(`#detail main img`).style.viewTransitionName =
        "avatar";

      // Remove names after snapshots have been taken
      // so that we're ready for the next navigation
      await e.viewTransition.ready;
      document.querySelector(`#detail main h1`).style.viewTransitionName =
        "none";
      document.querySelector(`#detail main img`).style.viewTransitionName =
        "none";
    }
  }
});

Note: See List of Chrome DevRel team members for the live demo this code is taken from.

Specifications

Specification
HTML
# event-pagereveal

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
pagereveal event
Chrome – Full support
Chrome 123 (Release date: 2024-03-19)
footnote Full support
Edge – Full support
Edge 123 (Release date: 2024-03-22)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1860854
Opera – Full support
Opera 109 (Release date: 2024-03-27)
footnote Full support
Safari – Full support
Safari 18.2 (Release date: 2024-12-11)
footnote Full support
Chrome Android – Full support
Chrome Android 123 (Release date: 2024-03-19)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1860854
Opera Android – Full support
Opera Android 82 (Release date: 2024-05-02)
footnote Full support
Safari on iOS – Full support
Safari on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Samsung Internet – Full support
Samsung Internet 27 (Release date: 2024-11-06)
footnote Full support
WebView Android – Full support
WebView Android 123 (Release date: 2024-03-19)
footnote Full support
WebView on iOS – Full support
WebView on iOS 18.2 (Release date: 2024-12-11)
footnote Full support
Deno – No support
Deno
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

See also