Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I inspect html element that disappears from DOM on lost focus?

Tags:

html

dom

css

People also ask

How do you inspect dynamic HTML elements that keep disappearing in Chrome?

So to work around this in the Developer Tools inspector, right click on the element that is driving the elements to appear/disappear (kendo-dropdownlist) and select Break on | subtree modifications. Now go to the web page and click on the dropdown to show the dropdown options.


In Chrome browser, open Developer Tools and select Elements tab, then open the contextual menu of the parent node of the element you want to inspect, in the contextual menu click on Break on > Subtree modifications.

Afterwards you just need to click on the page and you'll get on the inspector without losing focus or losing the element you want to inspect.

enter image description here


You can capture the disappearing element if you pause JavaScript execution with a keyboard shortcut without moving the mouse. Here's how you do this in Chrome:

  1. Open up Developer Tools and go to Sources.

  2. Note the shortcut to pause script execution—F8.

    Pause script execution

  3. Interact with the UI to get the element to appear.

  4. Hit F8.

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

This trick works in Firefox and other modern browsers as well.


If all else fails, type this in the Console:

setTimeout(() => { debugger; }, 5000)

Then you've got 5 seconds (or change the value to anything else) to make whatever you want to debug appear.

None of the other answers worked for me - the DOM tree kept getting modified (i.e. stuff I care about disappeared) right before the script paused.


In chrome devtools settings, there is an option named Emulate a focused page. Which is disabled by default. After enabling this option, if you click anywhere on the devtool window, it wouldn't cause loss of focus on any element in the DOM.

(For Chrome version < 86)

Go to devtool settings -> preferences and under Global option, enable Emulate a focused page. After that, just click on element to focus, and then click anywhere on the devtool window. You would see that element doesn't lose the focus. So now you can easily inspect or debug.

enter image description here

UPDATE (Chrome version >= 86):

After chrome 86 update, this option has been moved to Rendering tab. It is no longer available in settings. Press Command+Shift+P (Mac) or Control+Shift+P (Windows, Linux) to open the Command Menu. Start typing Rendering in the Command Menu and select Show Rendering. There you can enable Emulate a focused page.

enter image description here


Not sure if this works in your situation but normally (and in every case worth to mention in this regard as it is a great tool) in Chrome Developer Tools you can simulate element states and one is also :focus.

To do so go to the Elements tab in the Developer Tools and make sure you are in the Styles section on the right (this should be the default location when you start the Developer Tools). Now just beneth the Styles in the top right corner you have an icon Toggle Element State. When you click it you can simulate :active, :hover, :focus and :visited for the element you selected on the left in your code view.

enter image description here