Skip to content

API Reference parrot_tools.computer.backend

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.computer.backend

View source

AsyncComputerBackend — async Playwright wrapper for computer-use actions.

Translates coordinate-based computer-use model actions into Playwright API calls. Every action returns an EnvState with a screenshot and current URL.

Class AsyncComputerBackend

Async Playwright wrapper implementing the computer-use action interface.

Manages browser lifecycle (start/stop), translates pixel-coordinate actions into Playwright mouse/keyboard calls, and returns EnvState (screenshot + URL) after each action.

Coordinate parameters accepted by action methods are ALREADY in pixel units — the toolkit layer is responsible for denormalization.

Parameter Type Default Description
viewport tuple[int, int] (1280, 720) Browser viewport as (width, height) in pixels.
headless bool True Whether to run the browser in headless mode.
browser_type str 'chromium' Playwright browser engine — "chromium", "firefox" or "webkit".
initial_url str 'https://www.google.com' URL to navigate to when the browser first opens.
search_engine_url str 'https://www.google.com' URL used by the search() action.

Attributes:

Attribute Type Description
current_url str Return the current page URL, or empty string if browser not started.
MAX_WAIT_SECONDS int

Method AsyncComputerBackend.start

Launch the browser and navigate to the initial URL.

Creates a new Playwright context with the configured viewport and hooks new-tab events to redirect them to the current page (single-tab model).

start() -> None

Raises:

  • RuntimeError — If the browser is already running.

Method AsyncComputerBackend.stop

Close the browser and release all Playwright resources.

stop() -> None

Method AsyncComputerBackend.screen_size

Return the current viewport dimensions.

screen_size() -> tuple[int, int]

Returns: tuple[int, int] — (width, height) tuple in pixels.

Method AsyncComputerBackend.current_state

Capture the current page state (screenshot + URL).

Waits for the page to finish loading before capturing.

current_state() -> EnvState

Returns: EnvState — EnvState with PNG bytes and the current URL.

Raises:

  • RuntimeError — If the browser has not been started.

Method AsyncComputerBackend.screenshot

Capture a standalone screenshot without triggering state updates.

screenshot(full_page: bool = False) -> bytes

Parameter Type Default Description
full_page bool False If True, captures the entire scrollable page.

Returns: bytes — PNG-encoded screenshot bytes.

Method AsyncComputerBackend.click_at

Click at pixel coordinates (x, y).

click_at(x: int, y: int) -> EnvState

Parameter Type Default Description
x int Horizontal pixel coordinate.
y int Vertical pixel coordinate.

Returns: EnvState — EnvState after the click.

Method AsyncComputerBackend.hover_at

Hover the mouse at pixel coordinates (x, y).

hover_at(x: int, y: int) -> EnvState

Parameter Type Default Description
x int Horizontal pixel coordinate.
y int Vertical pixel coordinate.

Returns: EnvState — EnvState after the hover.

Method AsyncComputerBackend.type_text

Type text into the currently focused element (no click, no clearing).

type_text(text: str, press_enter: bool = False) -> EnvState

Parameter Type Default Description
text str
press_enter bool False

Returns: EnvState

Method AsyncComputerBackend.type_text_at

Click at (x, y) and type text into the element.

type_text_at(x: int, y: int, text: str, press_enter: bool = False, clear_before_typing: bool = True) -> EnvState

Parameter Type Default Description
x int Horizontal pixel coordinate.
y int Vertical pixel coordinate.
text str Text to type.
press_enter bool False If True, presses Enter after typing.
clear_before_typing bool True If True, selects all existing content and replaces it with the new text.

Returns: EnvState — EnvState after typing.

Method AsyncComputerBackend.scroll_document

Scroll the entire document up or down.

scroll_document(direction: str) -> EnvState

Parameter Type Default Description
direction str "up" or "down".

Returns: EnvState — EnvState after scrolling.

Method AsyncComputerBackend.scroll_at

Scroll at a specific pixel position.

scroll_at(x: int, y: int, direction: str, magnitude: int = 800) -> EnvState

Parameter Type Default Description
x int Horizontal pixel coordinate.
y int Vertical pixel coordinate.
direction str "up" or "down".
magnitude int 800 Scroll distance in pixels.

Returns: EnvState — EnvState after scrolling.

Method AsyncComputerBackend.wait_seconds

Wait for the specified number of seconds (capped at 60).

wait_seconds(seconds: int = 5) -> EnvState

Parameter Type Default Description
seconds int 5 Number of seconds to wait (clamped to 0–60).

Returns: EnvState — EnvState after waiting.

Method AsyncComputerBackend.go_back

Navigate to the previous page in history.

go_back() -> EnvState

Returns: EnvState — EnvState after going back.

Method AsyncComputerBackend.go_forward

Navigate to the next page in history.

go_forward() -> EnvState

Returns: EnvState — EnvState after going forward.

Method AsyncComputerBackend.search

Navigate to the configured search engine URL.

search() -> EnvState

Returns: EnvState — EnvState after navigating to the search engine.

Method AsyncComputerBackend.navigate

Navigate to an absolute URL.

navigate(url: str) -> EnvState

Parameter Type Default Description
url str Fully qualified URL to navigate to.

Returns: EnvState — EnvState after navigation.

Method AsyncComputerBackend.key_combination

Press a key combination (e.g. Ctrl+C).

key_combination(keys: list[str]) -> EnvState

Parameter Type Default Description
keys list[str] List of key names to press simultaneously, in order (e.g. ["control", "c"]). Keys are normalized via the internal key map.

Returns: EnvState — EnvState after the key combination.

Method AsyncComputerBackend.drag_and_drop

Drag from (x, y) to (dest_x, dest_y).

drag_and_drop(x: int, y: int, dest_x: int, dest_y: int) -> EnvState

Parameter Type Default Description
x int Source horizontal pixel coordinate.
y int Source vertical pixel coordinate.
dest_x int Destination horizontal pixel coordinate.
dest_y int Destination vertical pixel coordinate.

Returns: EnvState — EnvState after the drag.

Method AsyncComputerBackend.open_web_browser

Open (or navigate to) the initial URL.

open_web_browser() -> EnvState

Returns: EnvState — EnvState after navigating to the initial URL.

Method AsyncComputerBackend.screenshot_element

Capture a screenshot of a specific element.

screenshot_element(selector: str) -> bytes

Parameter Type Default Description
selector str CSS selector identifying the element.

Returns: bytes — PNG-encoded screenshot bytes.

Method AsyncComputerBackend.start_recording

Start video recording.

Restarts the browser context with video recording enabled.

start_recording(output_dir: str = './recordings') -> None

Parameter Type Default Description
output_dir str './recordings' Directory where the recorded video will be saved.

Method AsyncComputerBackend.stop_recording

Stop video recording and return the video file path.

stop_recording() -> Optional[str]

Returns: Optional[str] — Path to the recorded video file, or None if no video was recorded.

Method AsyncComputerBackend.start_tracing

Start Playwright tracing.

start_tracing(screenshots: bool = True, snapshots: bool = True) -> None

Parameter Type Default Description
screenshots bool True Include screenshots in the trace.
snapshots bool True Include DOM snapshots in the trace.

Method AsyncComputerBackend.stop_tracing

Stop tracing and save the trace to the given path.

stop_tracing(output_path: str) -> None

Parameter Type Default Description
output_path str File path where the trace archive (.zip) is saved.

Method AsyncComputerBackend.record_har

Start recording network traffic to a HAR file.

Recreates the browser context with HAR recording enabled via record_har_path. The previous context is closed and a new one is opened, then the browser navigates back to the current URL.

record_har(output_path: str) -> None

Parameter Type Default Description
output_path str Path where the HAR file will be written.

Method AsyncComputerBackend.save_pdf

Export the current page as a PDF.

save_pdf(output_path: str) -> bytes

Parameter Type Default Description
output_path str File path where the PDF will be saved.

Returns: bytes — PDF bytes.

Alias EnvState

Re-exported from parrot_tools.computer.models.EnvState.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally