CUPComputer Use Protocol
Guides

Error Handling

Error types, ActionResult handling, and recovery patterns for both SDKs.

ActionResult

Every action returns an ActionResult indicating success or failure. Actions do not throw exceptions — always check the result.

result = session.action("e14", "click")

if result.success:
    print(result.message)   # "Clicked Submit"
else:
    print(result.error)     # "Element e14 not found"
@dataclass
class ActionResult:
    success: bool       # True if the action succeeded
    message: str        # Human-readable description
    error: str | None   # Error details (None on success)
const result = await session.action("e14", "click");

if (result.success) {
  console.log(result.message);   // "Clicked Submit"
} else {
  console.error(result.error);   // "Element e14 not found"
}
interface ActionResult {
  success: boolean;    // true if the action succeeded
  message: string;     // Human-readable description
  error?: string;      // Error details (undefined on success)
}

The most common error is using a stale element ID. Element IDs are only valid for the most recent snapshot. Always call snapshot() before interacting with elements.

Error categories

Session and tree errors

These are raised as exceptions (not returned in ActionResult):

ErrorCauseFix
RuntimeError: "No tree captured. Call snapshot() first."Called page() or find() before any snapshot()Call snapshot() first
ValueError: "Element 'eX' not found in current tree."Element ID doesn't exist in the current treeRe-capture with snapshot() and use fresh IDs
ValueError: "Container 'eX' has no children to paginate."Called page() on an element with no childrenCheck that the element is a scrollable container
RuntimeError: "Container 'eX' appears to use virtual scrolling..."Called page() on a virtually-scrolled containerUse action("eX", "scroll", direction="down") + snapshot() instead
ValueError: "Invalid direction '...'"Invalid direction passed to page()Use one of: up, down, left, right

Platform errors

Raised when the platform adapter can't initialize:

ErrorPlatformFix
RuntimeError: "Unsupported platform: ..."AnyCUP supports win32, darwin, linux. Check sys.platform / process.platform
RuntimeError: "Could not find csc.exe — .NET Framework 4.x is required..."WindowsInstall .NET Framework 4.x or ensure csc.exe is in PATH
RuntimeError: "Screen Recording permission is required..."macOSGrant Screen Recording permission in System Settings > Privacy & Security
RuntimeError: "libX11 not found..."LinuxInstall libx11-dev (Debian/Ubuntu) or xorg-x11-libs (Fedora)
RuntimeError: "libXtst not found..."LinuxInstall libxtst-dev (Debian/Ubuntu) or xorg-x11-server-utils (Fedora)
RuntimeError: "Cannot open X11 display '...'..."LinuxEnsure DISPLAY is set and X server is running
RuntimeError: "AT-SPI2 accessibility bus not available..."LinuxEnable AT-SPI2: set ACCESSIBILITY_ENABLED=1 or enable in desktop settings
RuntimeError: "gdbus not found..."Linux (TS)Install glib2-tools or libglib2.0-bin

Web adapter errors

ErrorCauseFix
RuntimeError: "Cannot connect to CDP at host:port..."Chrome isn't running with remote debuggingLaunch Chrome with --remote-debugging-port=9222
RuntimeError: "CDP endpoint at host:port has no page targets..."Chrome is running but no tabs are openOpen at least one tab
RuntimeError: "No browser tabs found"CDP can't find any page targetsVerify Chrome launched with debugging flag and has tabs
RuntimeError: "CDP error {code}: {message}"Chrome DevTools Protocol returned an errorCheck the error code and message for details

Dependency errors

ErrorCauseFix
ImportError: "Screenshot support requires the 'mss' package..."screenshot() called without mss installedpip install cup[screenshot]

Action execution errors

Action failures are returned in ActionResult.error (not thrown):

Error patternCauseFix
"Could not resolve any key codes from combo: '...'"Invalid key combination in press()Check key name spelling. Use ctrl, alt, shift, enter, escape, etc.
"SendInput failed..."Windows input injection failedCheck if the target window accepts input. Some elevated windows block it
"Cannot determine element position from box model"Web element has no computable positionElement may be hidden or off-screen
"Failed to compile Swift AX helper: ..."macOS Swift helper compilation failedEnsure Xcode command-line tools are installed

Recovery patterns

Re-snapshot and retry

The most common recovery pattern — re-capture the UI and retry with fresh element IDs:

result = session.action("e14", "click")

if not result.success:
    # UI may have changed — re-capture and retry
    session.snapshot()
    results = session.find(query="Submit")
    if results:
        result = session.action(results[0]["id"], "click")
let result = await session.action("e14", "click");

if (!result.success) {
  // UI may have changed — re-capture and retry
  await session.snapshot();
  const results = await session.find({ query: "Submit" });
  if (results.length > 0) {
    result = await session.action(results[0].id, "click");
  }
}

Catching platform exceptions

Wrap session creation to handle missing dependencies or unsupported platforms:

import cup

try:
    session = cup.Session()
    screen = session.snapshot()
except RuntimeError as e:
    print(f"Platform error: {e}")
    # Handle: missing dependencies, unsupported platform, etc.
except ImportError as e:
    print(f"Missing dependency: {e}")
    # Handle: optional dependency not installed
import { Session } from "computeruseprotocol";

try {
  const session = await Session.create();
  const screen = await session.snapshot();
} catch (e) {
  console.error(`Platform error: ${e}`);
  // Handle: missing dependencies, unsupported platform, etc.
}

What's next?

On this page