Skip to content

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

detect if page.evaluate() works properly

Pierre Gronlier9dc3be58a6a5
diff --git a/browser_use/dom/service.py b/browser_use/dom/service.py
index e60c16923..b6924778d 100644
--- a/browser_use/dom/service.py
+++ b/browser_use/dom/service.py
@@ -41,6 +41,9 @@ class DomService:
focus_element: int,
viewport_expansion: int,
) -> DOMElementNode:
+ if await page.evaluate("1+1") != 2:
+ raise ValueError('The page cannot evaluate javascript code properly')
+
js_code = resources.read_text('browser_use.dom', 'buildDomTree.js')
args = {