From 7090490f75f9671fade64585ce3bb7b954e1c104 Mon Sep 17 00:00:00 2001 From: Sheng Fan Date: Sat, 8 Mar 2025 18:23:40 +0800 Subject: [PATCH] feat(browser_use_tool): add 'read_links' action --- app/tool/browser_use_tool.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/tool/browser_use_tool.py b/app/tool/browser_use_tool.py index bd4afcc..981ef1c 100644 --- a/app/tool/browser_use_tool.py +++ b/app/tool/browser_use_tool.py @@ -20,6 +20,7 @@ content extraction, and tab management. Supported actions include: - 'screenshot': Capture a screenshot - 'get_html': Get page HTML content - 'get_text': Get text content of the page +- 'read_links': Get all links on the page - 'execute_js': Execute JavaScript code - 'scroll': Scroll the page - 'switch_tab': Switch to a specific tab @@ -187,6 +188,10 @@ class BrowserUseTool(BaseTool): text = await context.execute_javascript('document.body.innerText') return ToolResult(output=text) + elif action == "read_links": + links = await context.execute_javascript("document.querySelectorAll('a[href]').forEach((elem) => {if (elem.innerText) {console.log(elem.innerText, elem.href)}})") + return ToolResult(output=links) + elif action == "execute_js": if not script: return ToolResult(