Skip to the content

Page Lifecycle tracker documentation

The documentation of page-lifecycle-tracker, a TypeScript library for the Page Lifecycle API state of a web page, bfcache restores and the last telemetry.

page-lifecycle-tracker follows the state of a web page in the Page Lifecycle API: active, passive, hidden, frozen and terminated. It gets the state from the browser events focus, blur, visibilitychange, freeze, resume, pagehide and pageshow.

The library is for monitoring and telemetry code. A monitor discards the samples of a hidden page. An exporter sends the last data before the page goes away. A Web Vitals library starts a new page view after a restore from the back/forward cache (bfcache).

All libraries of a page share one tracker. In each transition, the subscribers of the observe phase start before the subscribers of the export phase. Thus the monitors record their last values before the exporter sends them, whatever the order of the scripts.

The package has no dependencies. It is an ECMAScript module with TypeScript types, and its license is MIT.

Start here

  • Getting started: install the package and subscribe to the transitions.
  • API reference: each function, class, method and type of the package.
  • Browser support: the events in Chromium, Firefox and Safari, with the sources.

Concepts

Recipes

page-lifecycle-tracker

A TypeScript library for the Page Lifecycle API, under the MIT license. It came from lag, a monitor of the lag of the main thread of the browser.

An AI model (Claude, from Anthropic) wrote most of the text and the code of this site, under the direction of the author. The tests and an STE linter examine them.