browser_focus

Browser Focus

Set focus to an element without clicking it. The element receives keyboard events and becomes the active element. Useful for preparing to type or when click would trigger unwanted actions.

Usage Example

Python SDK

import asyncio
from owl_browser import OwlBrowser, RemoteConfig

# Async usage
async with OwlBrowser(config) as browser:
    context = await browser.create_context()
    context_id = context["context_id"]
    await browser.focus(
        context_id=context_id,
        selector="#element-id"
    )

Node.js SDK

import { OwlBrowser } from '@olib-ai/owl-browser-sdk';
// Async usage
const ctx = await browser.createContext();
const contextId = ctx.context_id;
await browser.focus({
    context_id: contextId,
    selector: '#element-id'
});

CURL

curl -X POST \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
-d '{
    "context_id": "ctx_000001",
    "selector": "#element-id"
}' \
http://localhost:8080/api/execute/browser_focus

Parameters

Required

  • context_id string required
    • The unique identifier of the browser context (e.g., 'ctx_000001')
  • selector string required
    • CSS selector or natural language description of the element to focus

Optional

  • index string
    • When multiple elements match the selector, target the Nth element (0-based). Default: -1 (first match)

Response

Returns a JSON object with the operation result.

{
  "success": true,
  "result": <value>
}