
Use Chrome's Developer Tools to Track Element Focus
When traversing a web page via the keyboard (i.e., when your tester repeatedly hits the tab key), finding and then tracking down 'phantom' elements, where the focus disappears and then reappears again, can be very time‑consuming or frustrating.
This is a problem I've come across frequently in the past where larger platforms are made up of multiple components and multiple development teams. It can be particularly problematic when it comes to accessibility: if you rely on a screen reader and the keyboard to access a page, then having random (often silent) elements interject themselves is annoying at best.
Create a Live Expression
Fortunately, in Chrome's Web Developer Tools, this is an easy thing to track down.
- Open Web Developer Tools;
- Go to the Console;
- Click on the
Create Live Expressionbutton (it's the little eye symbol next toFilter); - In the Expression field that appears, type in
document.activeElement; - Click away from the field to set the Expression.
Now, as you interact with the page the value will update to show which element is focused at that time. Hit the tab key to your heart's content and watch as each element that takes your user's focus is flashed up.
If you right‑click on this, you can also view the element that has taken focus in the DOM tree within the Elements panel by selecting Reveal in Elements panel:
You can now track down where those random phantom focus elements are and either set their focus state to make them more visible or otherwise use tabindex to define their position within the page's sequential keyboard navigation, or remove from it them altogether.
Categories:
Related Articles

10 Essential SEO Tips for Front‑End Developers. 
Closures in JavaScript: The Key to Lexical Scope. Closures in JavaScript: The Key to Lexical Scope

How to Amend Git Commits. How to Amend Git Commits

Caching Strategies in React. Caching Strategies in React

Staying Current: Automating Copyright Year Updates. Staying Current: Automating Copyright Year Updates

Semantic HTML. Semantic HTML

Why Next.js Middleware Might Be Unavailable with Pages Router. Why Next.js Middleware Might Be Unavailable with Pages Router

Understanding Event Loop and Concurrency in JavaScript. Understanding Event Loop and Concurrency in JavaScript

The LeetCode Zigzag Conversion Problem in TypeScript. The LeetCode Zigzag Conversion Problem in TypeScript

Enhancing User Experience with CSS and JavaScript Animations. Enhancing User Experience with CSS and JavaScript Animations

Browser vs. Node.js in JavaScript: Why Code Works in One and Fails in the Other. Browser vs. Node.js in JavaScript: Why Code Works in One and Fails in the Other

Solving the 'Jump Game' Problem with Greedy Algorithms. Solving the 'Jump Game' Problem with Greedy Algorithms