Riff / Built on the open web / Platform

pagehide

Captures the exact position when the listener leaves the page.

A post with its tracks listed, and the player bar along the bottom of the screen
Leaving this page stores the exact position, which the next page picks up.

How Riff uses it

The save function that writes the queue and position to sessionStorage is bound to pagehide. So the last currentTime is captured when the listener follows a link, closes the tab, or the page enters the back-forward cache.

Why

Without it the restored position could be up to five seconds stale. pagehide fires reliably where unload does not, including on mobile.

Where

Links open the source at the commit this page was published from.

Reference: pagehide on MDN.