mirror of
https://github.com/browser-use/browser-use
synced 2026-04-22 17:45:09 +02:00
Implements a fast, persistent browser automation CLI per CLI_SPEC.md: - Fast CLI layer using stdlib only (<50ms startup) - Session server with Unix socket IPC (TCP on Windows) - Browser modes: chromium, real, remote - Commands: open, click, type, input, scroll, back, screenshot, state, switch, close-tab, keys, select, eval, extract - Python execution with persistent namespace (Jupyter-like REPL) - Agent task execution (requires API key) - JSON output mode The CLI maintains browser sessions across commands, enabling complex multi-step workflows. Includes Claude skill description for AI-assisted browser automation. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
55 lines
1.0 KiB
Python
55 lines
1.0 KiB
Python
"""Wire protocol for CLI↔Server communication.
|
|
|
|
Uses JSON over Unix sockets (or TCP on Windows) with newline-delimited messages.
|
|
"""
|
|
|
|
import json
|
|
from dataclasses import asdict, dataclass, field
|
|
from typing import Any
|
|
|
|
|
|
@dataclass
|
|
class Request:
|
|
"""Command request from CLI to server."""
|
|
|
|
id: str
|
|
action: str
|
|
session: str
|
|
params: dict[str, Any] = field(default_factory=dict)
|
|
|
|
def to_json(self) -> str:
|
|
return json.dumps(asdict(self))
|
|
|
|
@classmethod
|
|
def from_json(cls, data: str) -> 'Request':
|
|
d = json.loads(data)
|
|
return cls(
|
|
id=d['id'],
|
|
action=d['action'],
|
|
session=d['session'],
|
|
params=d.get('params', {}),
|
|
)
|
|
|
|
|
|
@dataclass
|
|
class Response:
|
|
"""Response from server to CLI."""
|
|
|
|
id: str
|
|
success: bool
|
|
data: Any = None
|
|
error: str | None = None
|
|
|
|
def to_json(self) -> str:
|
|
return json.dumps(asdict(self))
|
|
|
|
@classmethod
|
|
def from_json(cls, data: str) -> 'Response':
|
|
d = json.loads(data)
|
|
return cls(
|
|
id=d['id'],
|
|
success=d['success'],
|
|
data=d.get('data'),
|
|
error=d.get('error'),
|
|
)
|