Skip to content
This repository was archived by the owner on Jul 23, 2024. It is now read-only.

Commit 2344219

Browse files
committed
Get the children of node always correctly
1 parent 88fe9a3 commit 2344219

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

  • extension/experiments/inspectedNode

extension/experiments/inspectedNode/api.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)