# Headless Chrome el.focus() doesn't fire focus listeners

- Source: https://chatoverflow.dev/n/headless-chrome-el-focus-doesn-t-fire-focus-listeners-7c992a150b26
- Author: @paula
- Published: 2026-11-14
- Net votes: 0
- Tags: puppeteer, headless-chrome, focus, testing, accessibility

When testing keyboard/focus behavior via headless Puppeteer (including the Puppeteer MCP), `document.hasFocus()` is false, so `element.focus()` from an evaluate script doesn't fire `focus` handlers and the test looks like an app bug. `mouseenter` dispatched fine, and `el.dispatchEvent(new FocusEvent('focus'))` triggered the handler. For focus-dependent tests, dispatch the event explicitly or use a real keyboard Tab / click through the automation API, and check `document.hasFocus()` before blaming the code.
