Page Visibility, focus and blur
Tells a page when its tab is hidden, backgrounded or unfocused.
In one line
Can tell when you switch tabs, minimise the browser or lock the screen
Tells a page when its tab is hidden, backgrounded or unfocused.
Sites learn when the person switches tabs, minimizes or locks the screen. Used for attention tracking, exam proctoring and ad viewability, and by bot detectors that expect focus events.
What it can and can't do
What the user does: You switch tabs, minimise the window or lock the screen
It can
- Learn when the tab is shown or hidden
- Learn when the window loses focus
- Time how long you look at an ad or a page
- Check that you are really there, as exam tools and bot checks do
It cannot
- See what you do in other tabs or apps
- Ask permission first
- Know why you left
- Stop you from switching away
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 33 | 2014-02-20 | None |
| Edge | Supported | 12 | 2015-07-29 | None |
| Firefox | Supported | 18 | 2013-01-08 | None |
| Safari | Supported | 7 | 2013-10-22 | None |
| Safari on iPhone | Supported | 7 | 2013-09-18 | None |
| Chrome on Android | Supported | 33 | 2014-02-26 | None |
| Samsung Internet | Supported | 2.0 | 2014-10-17 | None |
How a site asks for it
| API | document.visibilityState; visibilitychange; window focus/blur; document.hasFocus() |
| Browser compat keys | api.Document.visibilityState |
| How access is granted | none |
| What the user sees | Not listed |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| How long it lasts | Not listed |
| How to take it back | Not listed |
| Inside an iframe | Not listed |
Typical flow
- Listen to visibilitychange and focus
- Log timestamps
- Compute attention time
Data you get
What comes back: State transitions
Shape: event
| Field | Type | Unit | Range | Precision |
|---|---|---|---|---|
visibilityState | string | None | visible, hidden | exact |
Technical limits
- Cannot see which other tab or app
- Background timers throttled to 1 per second then 1 per minute
The story
What it is
A page can tell when its tab is hidden, in the background or when you click away from it.
For you
You never see a prompt. A video may pause when you switch tabs, a game may stop, and a site may notice you went away. It is how pages save battery, and how some sites know you looked elsewhere.
For makers
Makers use it to pause video, stop animations and save power. It also powers ad viewability, which only counts an ad when the tab is visible, and some exam and training sites flag tab switches.
Where you see it
| Type | Example | Apps |
|---|---|---|
| video | A video site pauses when you switch tabs, then resumes when you return. | YouTube, Netflix |
| games | A browser game pauses the match when you switch away, so you do not lose while away. | None named |
| ads | An ad measurement script only counts an ad as seen when the tab is visible and in view. | DoubleVerify, Integral Ad Science |
| education | An online exam tool records each time a student leaves the test tab. | Proctorio, ExamSoft |
| messaging | A web chat app only sends a read receipt when the tab is visible, and sends a notification when it is hidden. | Slack, WhatsApp Web |
| live | A live stream stops loading video chunks in a hidden tab to save data and power. | Twitch |
| analytics | A site measures true time on page by pausing the timer when the tab is hidden. | Google Analytics |
Risks
- Can feel like monitoring
- Exams may flag honest tab switches
What the platform says
- MDN: Page Visibility API. Lets a page know when it is visible or hidden, so it can pause work and save power.
Good uses and abuse
Legitimate uses
- Pausing media, saving battery
Known abuse
- Attention and engagement tracking, proctoring
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 2 of 5 | How revealing the data is |
| Utility | 2 of 5 | How useful it is to honest apps |
| Friction | 0 of 5 | How much the user has to do |
| Fingerprint bits | 2 | Rough identifying entropy, when known |
Related capabilities
Related
- User activation and idle inference. Can see if you recently clicked or typed, and in Chromium if you are idle
- Battery Status API and drain inference. Can see your battery level and charging state in Chromium browsers
Sources
How well checked: Based on official documentation.