oddworks blog

Can websites see when you switch tabs? What they detect and how

On this page
  1. What a website can detect
  2. What a website can't see
  3. Who uses tab detection, and why
  4. See what a site sees about you
  5. How to stop websites from knowing you switched tabs
  6. FAQ

Yes. Every website can tell when its own tab goes into the background, when you minimize the window, and when you click into another app, because the browser announces all three to the page. What a site cannot see is where you went: it doesn't learn which tab you opened, what's in it, or what you do in other programs.

The rest of this post covers exactly which signals a page gets, who uses them and why, and the free and paid ways to keep a page from noticing.

What a website can detect

A page learns about you leaving through a handful of standard browser features. None of them need permission, and none show a prompt.

The Page Visibility API

document.visibilityState is "visible" or "hidden", and document.hidden is the same thing as a true/false value. When either changes, the browser fires a visibilitychange event at the page. According to MDN, it fires when you switch tabs, navigate away, minimize or close the browser, or switch apps on mobile. MDN's Page Visibility API page adds that a window entirely covered by another window can count as hidden too.

document.addEventListener('visibilitychange', () => {
  console.log(document.visibilityState, new Date().toLocaleTimeString());
});

That's all it takes. The timestamps of the "hidden" and "visible" events give the site how long you were away, to the millisecond. Our Page Visibility API explainer goes into hidden versus visibilityState in detail.

Window focus and blur

Visibility only changes when the page is actually out of sight. If you keep the browser on one half of the screen and click into a notes app on the other, the tab is still visible. The page can still tell, though: the window fires a blur event, and document.hasFocus() returns false until you click back in. A mouseleave event on the document also tells the page your pointer left its area.

Indirect signals

Some signals aren't events at all, just side effects of how browsers save power:

  • Animation frames stop. Browsers stop calling requestAnimationFrame() in background tabs (MDN). A page that counts frames sees a gap.
  • Timers slow down. Chrome throttles setTimeout and setInterval in hidden tabs, so a timer that should tick every 100 ms suddenly ticks once a second or less.
  • pagehide fires when you navigate away or close the tab.
  • The server notices silence. If a page normally reports in every few seconds and stops, the server knows something changed, whatever the page itself was told.

What a website can't see

  • Which tab you switched to, or its address. Pages can't read other tabs.
  • What you do in other apps.
  • Your screen, unless you start a screen share and pick it.
  • Whether you're looking at the page. A visible tab with you across the room looks the same as one you're reading, unless you've granted camera access.

Who uses tab detection, and why

Most of it is mundane. Here's where you run into it.

Video players

Many players pause, drop quality or stop loading when the tab is hidden. It saves bandwidth for you and serving costs for them, and MDN's own example of the API is a player that pauses audio when the page hides. If you just want the video to keep going, see why videos pause when you switch tabs.

Ad viewability

Advertisers pay for ads that could actually be seen. The industry standard, as Google's Active View methodology describes it, counts a display ad as viewable when at least 50% of its pixels are on screen for one continuous second, and an in-stream video ad at 50% for two continuous seconds. Google says its measurement code watches scrolling, resizing and tab switches, and that "ads playing while a tab is inactive or in picture-in-picture are reported as occluded." So an ad in a background tab usually doesn't count.

Analytics

Google Analytics 4 defines engagement time as "the amount of time someone spends with your web page in focus" and sends it when "the user focuses away from your web page" (Google Analytics Help). MDN also recommends sending end-of-session analytics when a page turns hidden, since that's the last moment a page can reliably act. Leaving a tab open in the background mostly stops counting as time on the site.

Chat and collaboration "away" status

Chat and team apps show whether you're around. Some take the hidden state or loss of focus as a hint, often alongside an inactivity timer and the server's own record of when your client last checked in. That's why your status can flip to away while the tab is still open.

Browser games

Games often pause on blur or visibilitychange so you don't lose a round while you're gone. Even without that, a game loop driven by requestAnimationFrame freezes in a background tab because the browser stops sending frames.

See what a site sees about you

Open our live tab-switch detection test, then switch to another tab for a few seconds and come back. The event log shows each blur, focus and visibilitychange the page caught, with timestamps, and tiles show the current visibilityState, document.hidden and document.hasFocus(). The walkthrough of the test page explains every entry.

How to stop websites from knowing you switched tabs

Start with the free, built-in options. They don't hide anything from the page, but they often make the problem go away.

Keep the tab visible

A page in a visible window doesn't fire visibilitychange. Drag the tab into its own window and put it beside your work, or on a second monitor. The page will still see blur when you click elsewhere, so this works for players that only check visibility.

Use picture-in-picture for video

In Chrome, play the video, click Media control at the top right, then Enter picture-in-picture (Chrome Help). The video floats over everything. The page still knows its tab is hidden, but many players keep playing in picture-in-picture anyway.

Override the signals with an extension

Chrome has no setting to turn the Page Visibility API off. To hide it, code has to run inside the page before the site's scripts and replace the values the site reads. You can do that with a userscript, a uBlock Origin filter on Firefox, or an extension. We cover each in how to disable the Page Visibility API.

Focus Spoofer (which we make) is a free, open-source extension for Chrome, Edge and Brave that does this on the tabs you turn it on for, or on sites you mark "Always protect". On a protected tab, document.hidden stays false, visibilityState stays "visible", visibilitychange, pagehide and window-level blur and mouseleave never reach the page, document.hasFocus() stays true, and requestAnimationFrame and requestVideoFrameCallback keep firing while the tab is hidden. It needs no account and your browsing data never leaves the browser. You can get it from the Chrome Web Store or read more at focus.oddworks.us.

What no extension can hide

An extension only changes what the page's own scripts see. It can't change what the server works out from its own records, such as when your client stopped sending requests. It also can't stop Chrome's Memory Saver or Edge's sleeping tabs from unloading a tab, can't run on chrome:// pages, the Chrome Web Store or the built-in PDF viewer, and Focus Spoofer doesn't work on mobile, Firefox or Safari.

FAQ

Can a website see what other tabs I have open?

No. A page can learn that its own tab was hidden or lost focus, but it can't read the address, title or content of any other tab.

Can a website tell if I click into another app without switching tabs?

Yes. The tab stays visible, but the window fires a blur event and document.hasFocus() returns false until you click back into the page.

Does incognito mode stop tab-switch detection?

No. Incognito changes what's stored after you close the window. The Page Visibility API and focus events work the same way in it.

Can websites detect that I use an extension to hide tab switching?

Sometimes. Any script that replaces browser values can, in principle, be noticed by a page that looks hard enough, and server-side timing can contradict what the page reports. For video players, ads and analytics this rarely matters.

How do I check whether a site can see me switch tabs?

Open focus.oddworks.us/test, switch away for a few seconds and come back. Any entries in the event log are things a site could have seen.

Keep reading

Start with the overview: Page Visibility API explained: document.hidden vs visibilityState