Focus and window raise
Can move focus between elements; cannot pull the window to the front or steal focus from other apps.
In one line
Can move the cursor between boxes on its page, but can't pull its window forward
Can move focus between elements; cannot pull the window to the front or steal focus from other apps.
A page can focus its own elements, but browsers stop it from grabbing focus from the address bar, another tab or another app, which blocks keystroke capture and pop-over scams.
What it can and can't do
What the user does: Nothing. It happens as you use the page, or when it finishes loading.
It can
- Move the typing cursor to a form box on its own page
- Bring its own tab back into focus after you click on it
- Highlight a button or field after you finish a step
It cannot
- Pull its browser window above your other apps
- Steal typing from another app or another site
- Jump to the front when you are in a different tab
- Force a tab to open in front of the one you are in
Browser support
| Browser | Status | First version | Released | Note |
|---|---|---|---|---|
| Chrome | Supported | 1 | 2008-12-11 | None |
| Edge | Supported | 12 | 2015-07-29 | None |
| Firefox | Supported | 1.5 | 2005-11-29 | None |
| Safari | Supported | 3 | 2007-10-26 | None |
| Safari on iPhone | Supported | 1 | 2007-06-29 | All iOS browsers use WebKit |
| Chrome on Android | Supported | 18 | 2012-06-27 | None |
| Samsung Internet | Supported | 1.0 | 2013-04-27 | None |
How a site asks for it
| API | element.focus(); window.focus(); autofocus; Permissions-Policy focus-without-user-activation |
| Browser compat keys | api.HTMLElement.focusapi.Window.focus |
| How access is granted | none |
| What the user sees | None (no browser prompt) |
| Needs a secure context (HTTPS) | No |
| Needs a user gesture | No |
| Activation | none |
| How long it lasts | None |
| How to take it back | Nothing to revoke (no permission is stored) |
| Inside an iframe | Cross-origin iframes cannot call focus() on parent or take focus without activation (Chrome 64) |
Typical flow
- Script calls focus()
- Browser moves focus only inside the page or when the window is already active
Data you get
Shape: none
No individual data fields. The signal is the access itself.
Technical limits
- window.focus() is a no-op in modern browsers unless the person triggered it (Chrome, Safari) or dom.disable_window_flip=true (Firefox default)
- Background tabs cannot raise themselves; notification clicks can focus the client via clients.focus (needs a click)
- Cross-origin iframe focus() without user activation is blocked (Chrome 64)
- Cannot read keystrokes outside the document or in the browser UI
- autofocus on a page that is not visible does nothing
The story
What it is
A page can move the typing cursor between its own fields but cannot yank your whole window forward.
For you
A search box can be ready to type the moment a page opens. A site cannot pull itself in front of the game or document you are using in another app.
For makers
Makers use autofocus to save you a click on login and search forms. Browsers block pushing the window to the front to prevent pop under annoyances.
Where you see it
| Type | Example | Apps |
|---|---|---|
| shopping | A store's search bar is ready for typing the moment the page loads. | Amazon, Google |
| games | A browser game grabs keyboard focus on load so arrow keys work without a click. | Agar.io, Slither.io |
| messaging | A chat app puts the cursor in the message box after you open a conversation. | Slack, WhatsApp Web |
| security | Old pop under ad tricks tried to pull a window forward, which browsers now block. | None named |
| accessibility | A dialog moves focus into itself and back out so keyboard and screen reader users do not get lost. | None named |
| banking | A login page puts the cursor straight into the username field. | None named |
Risks
- Typing in the wrong box
- Fake window tricks
Good uses and abuse
Legitimate uses
- Form autofocus
- Dialog focus management
- Keyboard navigation
Known abuse
- Focus theft for keylogging-style scams
- Pop-under refocus
Scores
| Score | Value | Meaning |
|---|---|---|
| Sensitivity | 1 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 | Not rated | Rough identifying entropy, when known |
History
- 2018-01, Chrome 64: Cross-origin iframes need user activation to move focus
- 2020-01, Firefox 72: window.focus() restricted by default
Related capabilities
Related
- Open popup or new window. Can open a new tab or window, but only right after you tap or click
Sources
How well checked: Based on official documentation.