Merge pull request #265 from fred913/main

feat(browser_use_tool): add 'get_text' action to browser use tool
This commit is contained in:
mannaandpoem 2025-03-09 11:40:20 +08:00 committed by GitHub
commit 7a9e22d093
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,8 @@ content extraction, and tab management. Supported actions include:
- 'input_text': Input text into an element - 'input_text': Input text into an element
- '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
- '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
@ -43,6 +45,7 @@ class BrowserUseTool(BaseTool):
"input_text", "input_text",
"screenshot", "screenshot",
"get_html", "get_html",
"get_text",
"execute_js", "execute_js",
"scroll", "scroll",
"switch_tab", "switch_tab",
@ -180,6 +183,16 @@ class BrowserUseTool(BaseTool):
truncated = html[:2000] + "..." if len(html) > 2000 else html truncated = html[:2000] + "..." if len(html) > 2000 else html
return ToolResult(output=truncated) return ToolResult(output=truncated)
elif action == "get_text":
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": elif action == "execute_js":
if not script: if not script:
return ToolResult( return ToolResult(