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)}
|
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
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
Reference in New Issue
Block a user