pagehide, visibilitychange and unload
Events that tell a page it is being hidden, left or closed so it can save state or send a last report.
In one line
Can tell a page when you hide or leave it, so it can send a report
Events that tell a page it is being hidden, left or closed so it can save state or send a last report.
visibilitychange and pagehide are the reliable last chance for a final send. unload is being retired: Chrome is deprecating it with a Permissions-Policy and completing the change in late 2026. beforeunload is unreliable on mobile.
What it can and can't do
What the user does: You switch tabs, close the tab or leave the page
It can
- Know when you hide or leave a page
- Save your progress or settings
- Send a final report, such as time spent, through other tools
It cannot
- Always run, since phones and Chrome may skip the unload event
- Stop you from leaving
- Keep the page running after it closes
- See what you do on the next page
How it differs between platforms: Chrome and Edge limit the unload event. Safari and Firefox run it more often.
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Partial | 3 | 2009-09-15 | unload is being phased out in Chrome 154 to 155 |
| Edge | Partial | 12 | 2015-07-29 | None |
| Firefox | Supported | 6 | 2011-08-16 | None |
| Safari | Supported | 5 | 2010-06-07 | None |
| Safari on iPhone | Supported | 4.2 | 2010-11-22 | None |
| Chrome on Android | Partial | 18 | 2012-06-27 | None |
| Samsung Internet | Supported | 1.0 | 2013-04-27 | None |
How a site asks for it
| API | document.visibilitychange, window.pagehide, beforeunload, unload |
| Permissions policy | unload |
| Browser compat keys | api.Window.pagehide_eventapi.Document.visibilitychange_eventapi.Window.unload_event |
| How access is granted | none |
| What the user sees | None |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| How long it lasts | Fires once at exit or tab hide |
| How to take it back | Clear site data, browser privacy settings |
| Inside an iframe | Not listed |
Data you get
What comes back: Lifecycle events
Shape: event
How often: once at exit
No individual data fields. The signal is the access itself.
Technical limits
- unload does not fire reliably on mobile or in bfcache
- beforeunload prompt requires a user gesture on the page
- Chrome deprecation of unload completes about Chrome 154 to 155 (Sep to Oct 2026)
- Only about 100s of ms of work is safe
The story
What it is
Events that tell a page it is being hidden or closed, so it can save and send a last report.
For you
You never see it. When you switch tabs or close the page, the page gets a short warning. It uses that moment to save your work or send a last report. Old unload events are being retired.
For makers
Pages die with little notice, especially on phones. Hidden and pagehide are the reliable last chance to send data. Games and editors use them to save progress, and analytics use them to finish counting time on page.
Where you see it
| Type | Example | Apps |
|---|---|---|
| productivity | An online editor saves your draft the moment you switch tabs, so nothing is lost if the browser crashes. | Google Docs, Notion |
| games | A browser game pauses and saves your state when you switch tabs, and sends progress to the server. | Slither.io, Krunker |
| video | A video site sends your watch position when you leave, so you can resume later. | YouTube, Netflix |
| analytics | An analytics script sends your time on page when the tab becomes hidden. | Google Analytics |
| live | A live stream pauses the video feed to save data when you hide the tab, and resumes when you return. | Twitch |
| ads | An ad tag stops counting visible time when the page goes into the background. | Google Ad Manager |
Risks
- Sends data at a moment you cannot stop
- Old unload events are fading
What the platform says
- Google Chrome: Page Lifecycle API. Chrome documents events like visibilitychange that tell pages when to save state or send last data.
Good uses and abuse
Legitimate uses
- Saving drafts, session end events
Known abuse
- Last gasp tracking
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 2 of 5 | How revealing the data is |
| Utility | 4 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | Not rated | Rough identifying entropy, when known |
History
- 2023-07, Chrome 115: Permissions-Policy: unload introduced
- 2024-01, Chrome 117: Gradual unload deprecation rollout began
- 2026-09, Chrome 154: Deprecation completes by default (Sep to Oct 2026 per Chrome plan)
Related capabilities
Related
- navigator.sendBeacon. Can send a small report that the browser delivers even as you leave the page
- Back forward cache. Can freeze this page when you leave and bring it back instantly on Back
Sources
How well checked: Checked against real behavior.