This repository was archived by the owner on Jul 23, 2024. It is now read-only.
File tree Expand file tree Collapse file tree
extension/experiments/inspectedNode Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ this.inspectedNode = class extends ExtensionAPI {
55 const { Services } = Cu . import ( "resource://gre/modules/Services.jsm" ) ;
66 const { require } = Cu . import ( "resource://devtools/shared/Loader.jsm" ) ;
77 const { gDevTools } = require ( "devtools/client/framework/devtools" ) ;
8+ const { ELEMENT_NODE } = require ( "devtools/shared/dom-node-constants" ) ;
89
910 const _clients = new Map ( ) ;
1011
@@ -50,9 +51,25 @@ this.inspectedNode = class extends ExtensionAPI {
5051 } ;
5152
5253 const _getSubtreeNodes = async ( node ) => {
54+ if ( ! node . hasChildren ) {
55+ return [ ] ;
56+ }
57+
5358 const nodes = [ ] ;
5459
55- for ( const child of await node . treeChildren ( ) ) {
60+ // At first, get the children cache in nodeFront.
61+ let children = await node . treeChildren ( ) ;
62+
63+ if ( children . length === 0 ) {
64+ // Otherwise, get via the walker.
65+ await node . walkerFront . children ( node ) ;
66+ children = await node . treeChildren ( ) ;
67+ }
68+
69+ // We see element type only
70+ children = children . filter ( node => node . nodeType === ELEMENT_NODE ) ;
71+
72+ for ( const child of children ) {
5673 nodes . push ( child ) ;
5774 nodes . push ( ...( await _getSubtreeNodes ( child ) ) ) ;
5875 }
You can’t perform that action at this time.
0 commit comments