Websites can detect visibility and focus changes. Learn what online tests can log and why those signals cannot reveal another tab's URL or contents.
Key Takeaways
- Yes, a website can notice when its page becomes hidden or loses focus, without a browser permission prompt.
- Those signals do not identify your destination. They do not expose another tab's URL, another app's contents, or what you did there.
- Visibility and focus answer different questions. A page can remain visible on one monitor while you work in a window on another.
- An online test can record these changes if it implements logging. A focus-loss count alone cannot prove that someone searched for answers.
If you are asking whether websites can detect when you switch tabs, the useful distinction is between a page observing its own state and observing your activity elsewhere. The first is built into ordinary browser APIs. The second does not follow from a tab-switch event.
Page Visibility: Did This Page Become Hidden?
The MDN Page Visibility API guide describes document.visibilityState and the visibilitychange event. A script can read the state and listen for changes:
document.addEventListener('visibilitychange', () => {
console.log('visibility', document.visibilityState);
});
Switching to a different tab in the same window normally makes the original page hidden. Minimizing the window or turning off the device's screen can also hide it. A page reported as visible may be only partly on screen; that value is not proof you are reading it.
The example logs locally to the console. Adding a listener does not itself send anything to a server. A site would need additional code to store or transmit the observation.
Window Blur and Focus: Did Input Move Away?
MDN's Window blur event reference defines blur as loss of window focus, including when focus moves to the address bar. The corresponding focus event marks its return:
window.addEventListener('blur', () => console.log('focus lost'));
window.addEventListener('focus', () => console.log('focus returned'));
This is why a message saying you “left the page” can appear even when the page remains on screen. Clicking another window, including one on a second monitor, can move focus away. The event reports a change at the source; it does not name the destination application.
Imagine a test page beside a calculator app. Clicking the calculator can cause focus loss, but interacting with browser controls can produce the same event. Labeling that event “cheating detected” adds an inference the API does not supply. A site should distinguish the observation from that judgment.
Document.hasFocus(): What Is the State Right Now?
The MDN Document.hasFocus() reference describes a boolean check for whether the document or an element within it has focus:
console.log('focused now', document.hasFocus());
It is a snapshot, not a history. One call cannot reconstruct how many times you left or when you returned. A page would have to record observations over time to build such a log.
There is also a difference between the document's active element and actual focus. An input can remain the active element in a background window without receiving keyboard input. Looking only at that element does not establish that the user is still interacting with the document.
This distinction matters when interpreting reports: a false result describes only the sampling moment. Several consecutive false results may all belong to one period without focus; counting each as a separate tab switch would inflate the total.
Common Situations and Their Limits
The following are typical interpretations, not a compatibility guarantee for every browser and device:
| Situation | What the original page may observe | What it cannot conclude from that alone |
|---|---|---|
| Select another tab in the same window | A change to hidden, and loss of focus | Which tab you selected |
| Minimize the browser | A hidden page | Why you minimized it |
| Click a second window beside the page | Lost focus while visibility can remain visible | What you did in that window |
| Move focus to the address bar | A window blur event | That you navigated anywhere |
| Lock a phone or turn its screen off | The page may become hidden; execution may later be suspended | That every subsequent moment was recorded |
Split view and picture-in-picture deserve particular care: the document's state and the media you can still see may differ, and behavior may vary by browser. Do not turn a single desktop observation into a universal mobile rule. Test the actual environment before relying on an interpretation.
Check the Difference in Your Browser
On a test page you control, add the event listeners shown above and open the browser console. Click back into the page, then try switching tabs, selecting the address bar, and clicking a second window beside it. Return to the page between actions and compare the messages. Record the browser version and operating system with your observations.
Interacting with DevTools can itself move focus away from the page. A document.hasFocus() call entered in the console may therefore return false even while the page remains visible. Account for that when interpreting your check.
What Can an Online Test or Exam Record?
A test page could timestamp focus and visibility changes, count departures, or estimate time away. Whether it actually does so depends on its implementation. Browser capability alone does not establish that a particular school, employer, or testing service stores these events.
Ask what a “tab switch” report actually counts: hidden transitions, focus losses, or both. One action can trigger more than one event. A raw event total is not necessarily a total of separate departures, and time away is not proof of activity elsewhere. Background execution may also be throttled or suspended, so a periodic timer should not be treated as a continuous recording.
For a test you plan to take, read its instructions and use its practice or equipment-check session. If you need a calculator, assistive software, or another window, clarify the permitted setup with the organizer beforehand. This addresses the actual rule, which an API description cannot tell you.
What These Signals Cannot Reveal
Visibility and focus APIs do not return a list of open tabs, browsing history, screenshots, or text entered in another application. Ordinary tab-state observation also needs no permission prompt. Screen sharing through a browser capture request is a separate capability requiring explicit user permission and selection of a capture surface.
An installed monitoring extension, managed-device software, or a screen-sharing session changes the context; it should not be confused with a normal webpage's visibility listener. Our browser permission guide explains the separate question of what permission states can reveal.
Likewise, detecting an open DevTools panel involves other signals. A page noticing a focus change is not evidence that it knows you opened developer tools.
Why Ordinary Websites Use These Events
A video page can pause playback when hidden, and analytics can exclude hidden intervals from an estimate of active time. Neither use establishes attention: a visible page can sit unread.
Detection systems can also combine interaction signals, as described in behavioral bot detection. For the wider context, see our bot detection techniques guide and how websites flag your browser. A person switching tabs is not, by itself, a bot signal with a reliable verdict.
To explore a different set of observable browser properties, try BrowserInsight's bot detection check. Its browser consistency checks run locally and do not upload the collected values. It is not a tab-visibility log. The separate TLS panel reflects connection metadata through /api/tls; it is not an activity recorder and does not affect the bot score.
FAQ
Can a website see which tab I switched to?
Not through these APIs. A hidden-state or focus-change event concerns the original document and does not disclose the destination URL or its contents.
Does a tab-switch warning mean my screen is being recorded?
No. A warning can be generated from the page's own state changes. Screen capture is a separate capability; review any sharing session or installed monitoring software separately.
Does every site log tab switching?
No. Supporting an API and choosing to record its events are different things. A warning shows that the site reacted to something, but does not by itself establish what it stores, sends, or retains.


