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: $$$ in the Firefox console selects elements inside the shadow DOM

Firefox
~/tips/tip-firefox-console-shadow-dom

$$$('button')

Finds elements by CSS selector in the Firefox console, including inside shadow DOM.

A selector that works in the inspector can return nothing in the console when the element sits inside a web component. Firefox has an extra helper for those cases.

The Web Console in Firefox has three selector helpers. $(selector, element) returns the first matching node, like document.querySelector(). $$(selector, element) returns an array of all matching nodes, where the docs point out that it is an array instead of a NodeList. And $$$(selector, element) works like $$ but also searches the shadow DOM.

$$$('button')

The second argument is optional and defaults to document, so you can start in a certain subtree:

$$$('input', $('my-widget'))

Because the result is a real array, you can use the usual array methods on it, such as map or filter, without converting anything first:

$$$('a').map(a => a.href)

A few neighbours are worth knowing. $0 is the element you currently inspect, and $_ stores the result of the last expression. copy(value) copies a string as it is, the outerHTML of a DOM node, or other values through JSON.stringify.

These helpers belong to the DevTools console. They are not part of the web platform, so the same code in a script on your page throws an error. Use querySelectorAll there, and reach into a shadow root through element.shadowRoot yourself.

Further reading: Firefox Source Docs: Web Console helpers

More Firefox tips view-source:https://www.mozilla.org/#line100 ^ invoice history about:processes right-click the request > Edit and Resend Windows and Linux: Ctrl+B All Firefox tips (10) All topics

Link