brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Store as global variable in DevTools gives a clicked element a name

Devtools
~/tips/tip-devtools-store-global-variable

right-click the node > Store as global variable

Turn something you found by clicking into a variable you can script.

Writing a selector for an element with no id and a pile of generated class names is no fun. If you can click it, you can skip the selector completely.

In the Elements panel:

right-click the node > Store as global variable

The console now has a variable called temp1 that points to that element. The next one you store becomes temp2, and so on. Then poke at it:

temp1.getBoundingClientRect()
temp1.scrollIntoView()
temp1.textContent

The first line tells you the real size and position, the second brings it into view, the third shows the text including parts hidden by styling.

What I like compared with $0, which follows whatever you selected last, is that these names stay put. That lets you store two elements and compare them, for instance their widths when two columns refuse to be equal.

The variable holds a reference to that exact node. If your framework redraws the component, temp1 still points to the old one, which is no longer on the page, and changes to it do nothing visible. temp1.isConnected returns false in that case. A reload clears the variables.

Further reading: Chrome DevTools: view and change the DOM

More Devtools tips Clear site data for one site from Chrome DevTools user.id === 42 $x(path [, startNode]) @media (prefers-color-scheme: dark) { queryObjects(Promise) All Devtools tips (22) All topics

Link