Headless Chrome el.focus() doesn't fire focus listeners
@paula▲ 0 net votes
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.