Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Chrome devtools track element with focus?

Tags:

I'm testing my HTML on accessibility. While navigating the HTML with the TAB key, the focus ring sometimes disappears because the element that has focus is hidden. At that point i can't tell which DOM element has focus. Is there a way i can track in Chrome DEVtools which element has focus while TABbing through the page?

like image 703
Lefthandmedia Avatar asked Jul 17 '18 15:07

Lefthandmedia


People also ask

How do you inspect element in focus?

Hit F8 . Now you can move your mouse around, inspect the DOM, whatever. The element will stay there.

How do I focus an element in Chrome?

Just use the focus method in JavaScript: document. getElementById('myButton') . focus();

How do I inspect hidden elements in Chrome?

VIEW HIDDEN ELEMENTS: The extension makes visible those elements hidden by the "display:none", "type=hidden", and "visibility=hidden" attributes / styles. To do this hit LazySec's "Show Hidden Elements" button.


1 Answers

Update

Official documentation

As of Chrome 70, which released in August 2018, Live Expressions provide an easier way to track which element has focus.

  1. Open the Console.
  2. Click Create Live Expression Create Live Expression.

    Live Expression UI

  3. Type document.activeElement.

  4. Click outside of the Live Expression UI to save.

As of Chrome 71, which was released in October 2018, when you hover over a Live Expression result that evaluates to a node (as is the case with document.activeElement), DevTools highlights the node in the viewport.

Hovering over the Live Expression result

Original Answer

Thanks for posting. Seems like a common and useful workflow, yet I've never thought about it.

  1. While focused on the hidden element, evaluate document.activeElement in the Console.

    Running document.activeElement in the Console.

  2. Right-click > Reveal in Elements panel.

    Hovering over "Reveal in Elements panel".

The DOM Tree is highlighting the hidden element.

The hidden element is highlighted in the Elements panel.

Here is the demo, if you'd like to try it yourself.

P.S. I tweeted out this workflow from the DevTools account.

like image 106
Kayce Basques Avatar answered Sep 25 '22 00:09

Kayce Basques