Skip to content

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

update error message for scroll

Magnus Müller97f321bceaa4
diff --git a/browser_use/tools/service.py b/browser_use/tools/service.py
index cf4109dae..5d898bc30 100644
--- a/browser_use/tools/service.py
+++ b/browser_use/tools/service.py
@@ -669,7 +669,9 @@ You will be given a query and the markdown of a webpage that has been filtered t
raise RuntimeError(str(e))
@self.registry.action(
- """Scroll the page by specified number of pages (set down=True to scroll down, down=False to scroll up, num_pages=number of pages to scroll like 0.5 for half page, 10.0 for ten pages, etc.). Optional index parameter to scroll within a specific element or its scroll container (works well for dropdowns and custom UI components). If you want to scroll the entire page, don't use index.
+ """Scroll the page by specified number of pages (set down=True to scroll down, down=False to scroll up, num_pages=number of pages to scroll like 0.5 for half page, 10.0 for ten pages, etc.).
+ Default behavior is to scroll the entire page. This is enough for most cases.
+ Optional if there are multiple scroll containers, use frame_element_index parameter with an element inside the container you want to scroll in. For that you must use indices that exist in your browser_state (works well for dropdowns and custom UI components).
Instead of scrolling step after step, use a high number of pages at once like 10 to get to the bottom of the page.
If you know where you want to scroll to, use scroll_to_text instead of this tool.
""",
@@ -681,18 +683,15 @@ You will be given a query and the markdown of a webpage that has been filtered t
# Special case: index 0 means scroll the whole page (root/body element)
node = None
if params.frame_element_index is not None and params.frame_element_index != 0:
- try:
- node = await browser_session.get_element_by_index(params.frame_element_index)
- if node is None:
- # Element not found - return error
- raise ValueError(f'Element index {params.frame_element_index} not found in DOM')
- except Exception as e:
- # Error getting element - return error
- raise ValueError(f'Failed to get element {params.frame_element_index}: {e}') from e
+ node = await browser_session.get_element_by_index(params.frame_element_index)
+ if node is None:
+ # Element does not exist
+ msg = f'Element index {params.frame_element_index} not found in DOM'
+ return ActionResult(error=msg)
# Dispatch scroll event with node - the complex logic is handled in the event handler
- # Convert pages to pixels (assuming 800px per page as standard viewport height)
- pixels = int(params.num_pages * 800)
+ # Convert pages to pixels (assuming 1000px per page as standard viewport height)
+ pixels = int(params.num_pages * 1000)
event = browser_session.event_bus.dispatch(
ScrollEvent(direction='down' if params.down else 'up', amount=pixels, node=node)
)
diff --git a/docs/docs.json b/docs/docs.json
index e5d314844..6dfdb1d4f 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -236,4 +236,4 @@
"linkedin": "https://linkedin.com/company/browser-use"
}
}
-}
\ No newline at end of file
+}