The TessaClient class provides complete control over browser automation jobs with advanced features like job monitoring, status tracking, and resource management.
Copy
from tessa_sdk import TessaClient, BrowserConfigwith TessaClient("YOUR_API_KEY") as client: job = client.run_browser_agent("Your task here") print(f"Watch live: {job.live_url}") result = job.wait_for_completion()
from tessa_sdk import TessaClient, BrowserConfigclient = TessaClient("YOUR_API_KEY")# Simple usagejob = client.run_browser_agent("Extract data from example.com")# With browser configurationconfig = BrowserConfig( width=1920, height=1080, residential_ip=True, max_duration_minutes=15)job = client.run_browser_agent( directive="Navigate and extract product data", initial_url="https://shop.example.com", action_selection_model="gpt-4o", browser_config=config)# For sites with complex shadow DOM elements, use beta functionalityjob_with_shadow_dom = client.run_browser_agent( directive="Extract data from shadow DOM components", initial_url="https://complex-spa.example.com", shadow_dom_beta=True, # Enable enhanced shadow DOM support browser_config=config)# Monitor the jobprint(f"Job ID: {job.job_id}")print(f"Live URL: {job.live_url}")print(f"History URL: {job.history_url}")
client = TessaClient("YOUR_API_KEY")try: # Use the client job = client.run_browser_agent("Your task") result = job.wait_for_completion()finally: # Always close when done client.close()
job.job_id # Unique job identifierjob.live_url # URL to watch live executionjob.cdp_url # Chrome DevTools Protocol URLjob.history_url # URL to view job historyjob.polling_url # API endpoint for status updates
# ✅ Automatic cleanupwith TessaClient("YOUR_API_KEY") as client: job = client.run_browser_agent("Task") result = job.wait_for_completion()# ❌ Manual cleanup requiredclient = TessaClient("YOUR_API_KEY")job = client.run_browser_agent("Task")# Don't forget to close!client.close()
Configure Appropriate Timeouts
Copy
# Short timeout for simple tasksresult = client.run_and_wait( "Extract page title", timeout=30)# Long timeout for complex workflowsresult = client.run_and_wait( "Complete multi-step process", timeout=600 # 10 minutes)# No timeout for batch processingjob = client.run_browser_agent("Process entire catalog")result = job.wait_for_completion() # No timeout
Monitor Long-Running Jobs
Copy
job = client.run_browser_agent("Long task")# Provide live URL to userprint(f"Watch progress: {job.live_url}")# Check status periodicallywhile True: status = job.get_status() print(f"Status: {status.status}") if status.status in ["completed", "failed"]: break time.sleep(10)
Handle Errors Gracefully
Copy
from tessa.exceptions import *try: result = client.run_and_wait("Task", timeout=60)except AuthenticationError: # Handle auth issues passexcept RateLimitError as e: # Wait and retry time.sleep(e.retry_after)except TimeoutError: # Task took too long passexcept JobFailedError as e: # Job failed print(f"Job failed: {e.error_message}")