Allow inspect(element, {focus: false}) in the Console Utilities API
to select a DOM node in the Elements panel without switching
focus to the Elements panel. The node is selected for the next time the panel
is opened.
Motivated by React DevTools wanting to update the Elements panel selection without activating a new tab.
Open DevTools Console and run the commands below, or use the buttons.
This should switch you to the Elements panel and select the node.
inspect(document.querySelector('#sample-target'))
This should select the node in Elements but NOT switch panels. Open Elements panel manually afterwards to verify the node is selected.
inspect(document.querySelector('#sample-target'), {focus: false})
Same test with a different element to confirm selection updates.
// First: select outer target without focus
inspect(document.querySelector('#sample-target'), {focus: false})
// Then: select inner span without focus
inspect(document.querySelector('#inner-node'), {focus: false})
// Now open Elements panel -- #inner-node should be selected
inspect(el) -- defaultElements panel opens and the node is focused/selected. This is the existing behavior.
inspect(el, {focus: false}) -- newThe node is selected in the Elements panel tree, but DevTools does NOT switch to the Elements tab. The Console (or whichever panel is active) stays in focus. When you manually switch to Elements, the node is already selected.
Parses the second argument as an options object, extracts focus,
and sends omitFocus hint via Runtime.inspectRequested CDP event.
CL: 7575861
Extracts omitFocus from hints and passes it to
Common.Revealer.reveal(object, omitFocus).
The DOMNodeRevealer then calls
revealAndSelectNode with {showPanel: true, focusNode: !omitFocus}.
CL: 7575526