Include whitespace-only text nodes in child nodes

91 views
Skip to first unread message

Pascal Bihler

unread,
May 28, 2021, 4:05:53 AM5/28/21
to chrome-debugging-protocol
Hi,

if I receive child nodes using DOM.getDocument or DOM.requestChildNodes, some nodes are omitted (ignored) and not reported in the result, if they only contain whitespace text (but some are listed anyway).

So in this example, body has only one child - the "P"-node:
<body>
    <p>
</body>

On the other side, document.body.childNodes[0] is the first text element, and document.body.childNodes[1] is the P-element, so there is a discrepancy between the nodes reported by CDP and by JavaScript.

Is there any option to include the ignored nodes in the Node child hierarchy? If I call DOM.describeNode on the objectId returned from a Runtime.evaluate("document.body.childNodes[0]"), I receive a backendNodeId, but nodeId is always "0" (event when "requesting" the node), and thus no event is triggered when the node is removed from its parent, and the node is ignored as previous node when another child is inserted afterwards...

This makes it very difficult to manage a proper view on the DOM nodes of the page via CDP.

Regards,
Pascal

Pascal Bihler

unread,
Jun 4, 2021, 4:25:05 AM6/4/21
to chrome-debugging-protocol
Hi again.

Has anyone any idea? Ignoring the "invisible" whitespace nodes is problematic when you want to check for the text visible to the user:

<div>
<span>label</span>
<input value="abc"/>
</div>

renders "label abc" whereas

<div>
<span>label</span><input value="abc"/>
</div>

renders "labelabc", but CDP emits equal child nodes for the DIV and I cannot determine where to add the space in between the child nodes and where not (and the "innerText" of Javascript does not contain the visible text from the textfield).

Any help with that challenge is welcome.

Regards,
Pascal
Reply all
Reply to author
Forward
0 new messages