Skip to content

Commit 7a9e22d

Browse files
authored
Merge pull request #265 from fred913/main
feat(browser_use_tool): add 'get_text' action to browser use tool
2 parents c71ee14 + 0d0f8ab commit 7a9e22d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

app/tool/browser_use_tool.py

+13
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
- 'input_text': Input text into an element
2121
- 'screenshot': Capture a screenshot
2222
- 'get_html': Get page HTML content
23+
- 'get_text': Get text content of the page
24+
- 'read_links': Get all links on the page
2325
- 'execute_js': Execute JavaScript code
2426
- 'scroll': Scroll the page
2527
- 'switch_tab': Switch to a specific tab
@@ -43,6 +45,7 @@ class BrowserUseTool(BaseTool):
4345
"input_text",
4446
"screenshot",
4547
"get_html",
48+
"get_text",
4649
"execute_js",
4750
"scroll",
4851
"switch_tab",
@@ -180,6 +183,16 @@ async def execute(
180183
truncated = html[:2000] + "..." if len(html) > 2000 else html
181184
return ToolResult(output=truncated)
182185

186+
elif action == "get_text":
187+
text = await context.execute_javascript("document.body.innerText")
188+
return ToolResult(output=text)
189+
190+
elif action == "read_links":
191+
links = await context.execute_javascript(
192+
"document.querySelectorAll('a[href]').forEach((elem) => {if (elem.innerText) {console.log(elem.innerText, elem.href)}})"
193+
)
194+
return ToolResult(output=links)
195+
183196
elif action == "execute_js":
184197
if not script:
185198
return ToolResult(

0 commit comments

Comments
 (0)