Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

Migrate browser interface into computer SDK

Dillon DuPont8f297eac3ce0
diff --git a/examples/browser_tool_example.py b/examples/browser_tool_example.py
index 11a8dead21..70055ff96e 100644
--- a/examples/browser_tool_example.py
+++ b/examples/browser_tool_example.py
@@ -39,7 +39,8 @@ async def test_browser_tool():
# Initialize the computer interface
# For local testing, use provider_type="docker"
# For provider_type="cloud", provide name and api_key
- computer = Computer(provider_type="docker")
+ computer = Computer(provider_type="docker", os_type="linux", image="cua-xfce:dev")
+ await computer.run()
# Initialize the browser tool with the computer interface
browser = BrowserTool(interface=computer)
diff --git a/libs/python/computer/computer/computer.py b/libs/python/computer/computer/computer.py
index 0b1cd50906..710b08a2a6 100644
--- a/libs/python/computer/computer/computer.py
+++ b/libs/python/computer/computer/computer.py
@@ -953,6 +953,35 @@ class Computer:
"""
return await self.interface.to_screenshot_coordinates(x, y)
+ async def playwright_exec(self, command: str, params: Optional[Dict] = None) -> Dict[str, Any]:
+ """
+ Execute a Playwright browser command.
+
+ Args:
+ command: The browser command to execute (visit_url, click, type, scroll, web_search)
+ params: Command parameters
+
+ Returns:
+ Dict containing the command result
+
+ Examples:
+ # Navigate to a URL
+ await computer.playwright_exec("visit_url", {"url": "https://example.com"})
+
+ # Click at coordinates
+ await computer.playwright_exec("click", {"x": 100, "y": 200})
+
+ # Type text
+ await computer.playwright_exec("type", {"text": "Hello, world!"})
+
+ # Scroll
+ await computer.playwright_exec("scroll", {"delta_x": 0, "delta_y": -100})
+
+ # Web search
+ await computer.playwright_exec("web_search", {"query": "computer use agent"})
+ """
+ return await self.interface.playwright_exec(command, params)
+
# Add virtual environment management functions to computer interface
async def venv_install(self, venv_name: str, requirements: list[str]):
"""Install packages in a virtual environment.