Skip to Content
Platform.Ontology

Focus and window raise

Can move focus between elements; cannot pull the window to the front or steal focus from other apps.

Does something on your deviceThings a page can doWindows and navigationWeb browsersWhile you use it

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

BrowserStatusFirst versionReleasedNote
ChromeSupported12008-12-11None
EdgeSupported122015-07-29None
FirefoxSupported1.52005-11-29None
SafariSupported32007-10-26None
Safari on iPhoneSupported12007-06-29All iOS browsers use WebKit
Chrome on AndroidSupported182012-06-27None
Samsung InternetSupported1.02013-04-27None

How a site asks for it

APIelement.focus(); window.focus(); autofocus; Permissions-Policy focus-without-user-activation
Browser compat keysapi.HTMLElement.focus
api.Window.focus
How access is grantednone
What the user seesNone (no browser prompt)
Needs a secure context (HTTPS)No
Needs a user gestureNo
Activationnone
How long it lastsNone
How to take it backNothing to revoke (no permission is stored)
Inside an iframeCross-origin iframes cannot call focus() on parent or take focus without activation (Chrome 64)

Typical flow

  1. Script calls focus()
  2. 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

TypeExampleApps
shoppingA store's search bar is ready for typing the moment the page loads.Amazon, Google
gamesA browser game grabs keyboard focus on load so arrow keys work without a click.Agar.io, Slither.io
messagingA chat app puts the cursor in the message box after you open a conversation.Slack, WhatsApp Web
securityOld pop under ad tricks tried to pull a window forward, which browsers now block.None named
accessibilityA dialog moves focus into itself and back out so keyboard and screen reader users do not get lost.None named
bankingA 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

ScoreValueMeaning
Sensitivity1 of 5How revealing the data is
Utility2 of 5How useful it is to honest apps
Friction0 of 5How much the user has to do
Fingerprint bitsNot ratedRough 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

Sources

How well checked: Based on official documentation.

On this page