Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Split _build_dom_tree into 2 functions

Magnus Müller9b3331be8857
diff --git a/browser_use/dom/service.py b/browser_use/dom/service.py
index bad5248fa..305d02ec3 100644
--- a/browser_use/dom/service.py
+++ b/browser_use/dom/service.py
@@ -61,7 +61,13 @@ class DomService:
}
eval_page = await self.page.evaluate(self.js_code, args)
+ return await self._construct_dom_tree(eval_page)
+ @time_execution_async('--construct_dom_tree')
+ async def _construct_dom_tree(
+ self,
+ eval_page: dict,
+ ) -> tuple[DOMElementNode, SelectorMap]:
js_node_map = eval_page['map']
js_root_id = eval_page['rootId']