MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / findAncestorNode

Method findAncestorNode

src/TextSnapshot.ts:201–231  ·  view source on GitHub ↗
(
      handle: ElementHandle,
    )

Source from the content-addressed store, hash-verified

199 };
200
201 const findAncestorNode = async (
202 handle: ElementHandle,
203 ): Promise<TextSnapshotNode | null> => {
204 let ancestorHandle = await handle.evaluateHandle(el => el.parentElement);
205
206 while (ancestorHandle) {
207 const ancestorElement = ancestorHandle.asElement();
208 if (!ancestorElement) {
209 await ancestorHandle.dispose();
210 return null;
211 }
212
213 const ancestorBackendId = await ancestorElement.backendNodeId();
214 if (ancestorBackendId) {
215 const ancestorNode = idToNode
216 .values()
217 .find(node => node.backendNodeId === ancestorBackendId);
218 if (ancestorNode) {
219 await ancestorHandle.dispose();
220 return ancestorNode;
221 }
222 }
223
224 const nextHandle = await ancestorElement.evaluateHandle(
225 el => el.parentElement,
226 );
227 await ancestorHandle.dispose();
228 ancestorHandle = nextHandle;
229 }
230 return null;
231 };
232
233 const findDescendantNodes = async (
234 backendNodeId?: number,

Callers

nothing calls this directly

Calls 2

disposeMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected