fix: State command now outputs LLM representation, add CLI aliases

- State command outputs same format that browser-use agents see
- Added aliases: bu, browser (all work the same)
- Headed mode now correctly shows browser window
This commit is contained in:
Gregor Žunič
2026-01-19 09:32:26 -08:00
parent 0f9e955276
commit 4716ae50ce
3 changed files with 14 additions and 27 deletions

View File

@@ -119,28 +119,9 @@ async def handle(action: str, session: SessionInfo, params: dict[str, Any]) -> A
return {'screenshot': base64.b64encode(data).decode(), 'size': len(data)} return {'screenshot': base64.b64encode(data).decode(), 'size': len(data)}
elif action == 'state': elif action == 'state':
state = await bs.get_browser_state_summary(include_screenshot=False) # Return the same LLM representation that browser-use agents see
if state: state_text = await bs.get_state_as_text()
# Build element list with indices from DOM state return {'_raw_text': state_text}
elements = []
if state.dom_state and state.dom_state.selector_map:
for idx, elem in state.dom_state.selector_map.items():
elements.append(
{
'index': idx,
'tag': getattr(elem, 'tag_name', ''),
'text': (getattr(elem, 'text', '') or '')[:50],
'role': getattr(elem, 'role', ''),
}
)
return {
'url': state.url,
'title': state.title,
'element_count': len(elements),
'elements': elements[:20], # Return first 20 elements
}
return {'url': '', 'title': '', 'elements': []}
elif action == 'switch': elif action == 'switch':
from browser_use.browser.events import SwitchTabEvent from browser_use.browser.events import SwitchTabEvent

View File

@@ -390,11 +390,15 @@ def main() -> int:
data = response.get('data') data = response.get('data')
if data is not None: if data is not None:
if isinstance(data, dict): if isinstance(data, dict):
for key, value in data.items(): # Special case: raw text output (e.g., state command)
if key == 'screenshot' and len(str(value)) > 100: if '_raw_text' in data:
print(f'{key}: <{len(value)} bytes>') print(data['_raw_text'])
else: else:
print(f'{key}: {value}') for key, value in data.items():
if key == 'screenshot' and len(str(value)) > 100:
print(f'{key}: <{len(value)} bytes>')
else:
print(f'{key}: {value}')
elif isinstance(data, str): elif isinstance(data, str):
print(data) print(data)
else: else:

View File

@@ -93,6 +93,8 @@ Repository = "https://github.com/browser-use/browser-use"
[project.scripts] [project.scripts]
browser-use = "browser_use.skill_cli.main:main" # Fast CLI for browser automation browser-use = "browser_use.skill_cli.main:main" # Fast CLI for browser automation
bu = "browser_use.skill_cli.main:main" # Alias for browser-use
browser = "browser_use.skill_cli.main:main" # Alias for browser-use
browser-use-tui = "browser_use.cli:main" # Legacy TUI interface browser-use-tui = "browser_use.cli:main" # Legacy TUI interface
[build-system] [build-system]