mirror of
https://github.com/browser-use/browser-use
synced 2026-04-22 17:45:09 +02:00
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:
@@ -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)}
|
||||
|
||||
elif action == 'state':
|
||||
state = await bs.get_browser_state_summary(include_screenshot=False)
|
||||
if state:
|
||||
# Build element list with indices from DOM state
|
||||
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': []}
|
||||
# Return the same LLM representation that browser-use agents see
|
||||
state_text = await bs.get_state_as_text()
|
||||
return {'_raw_text': state_text}
|
||||
|
||||
elif action == 'switch':
|
||||
from browser_use.browser.events import SwitchTabEvent
|
||||
|
||||
@@ -390,11 +390,15 @@ def main() -> int:
|
||||
data = response.get('data')
|
||||
if data is not None:
|
||||
if isinstance(data, dict):
|
||||
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}')
|
||||
# Special case: raw text output (e.g., state command)
|
||||
if '_raw_text' in data:
|
||||
print(data['_raw_text'])
|
||||
else:
|
||||
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):
|
||||
print(data)
|
||||
else:
|
||||
|
||||
@@ -93,6 +93,8 @@ Repository = "https://github.com/browser-use/browser-use"
|
||||
|
||||
[project.scripts]
|
||||
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
|
||||
|
||||
[build-system]
|
||||
|
||||
Reference in New Issue
Block a user