feat(browser_use_tool): add 'read_links' action

This commit is contained in:
Sheng Fan 2025-03-08 18:23:40 +08:00
parent cf3603dfcc
commit 7090490f75

View File

@ -20,6 +20,7 @@ content extraction, and tab management. Supported actions include:
- 'screenshot': Capture a screenshot - 'screenshot': Capture a screenshot
- 'get_html': Get page HTML content - 'get_html': Get page HTML content
- 'get_text': Get text content of the page - 'get_text': Get text content of the page
- 'read_links': Get all links on the page
- 'execute_js': Execute JavaScript code - 'execute_js': Execute JavaScript code
- 'scroll': Scroll the page - 'scroll': Scroll the page
- 'switch_tab': Switch to a specific tab - 'switch_tab': Switch to a specific tab
@ -187,6 +188,10 @@ class BrowserUseTool(BaseTool):
text = await context.execute_javascript('document.body.innerText') text = await context.execute_javascript('document.body.innerText')
return ToolResult(output=text) 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": elif action == "execute_js":
if not script: if not script:
return ToolResult( return ToolResult(