Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

fixed cubic issues

Saurav Panda087bea7d7342
diff --git a/examples/cloud/02_fast_mode_gemini.py b/examples/cloud/02_fast_mode_gemini.py
index 5bbf65fe1..ad1160a6c 100644
--- a/examples/cloud/02_fast_mode_gemini.py
+++ b/examples/cloud/02_fast_mode_gemini.py
@@ -196,7 +196,10 @@ def run_speed_comparison():
print(f'\n⚡ Total time: {total_time:.1f}s')
print(f'🔥 Average per task: {total_time / len(results):.1f}s')
- print(f'💨 Average per step: {total_time / total_steps:.1f}s')
+ if total_steps > 0:
+ print(f'💨 Average per step: {total_time / total_steps:.1f}s')
+ else:
+ print('💨 Average per step: N/A (no steps recorded)')
def main():
diff --git a/examples/cloud/03_structured_output.py b/examples/cloud/03_structured_output.py
index c9b95b58f..a05e12678 100644
--- a/examples/cloud/03_structured_output.py
+++ b/examples/cloud/03_structured_output.py
@@ -126,9 +126,9 @@ def create_structured_task(instructions: str, schema_model: type[BaseModel], **k
return task_id
-def wait_for_structured_completion(task_id: str) -> dict[str, Any]:
+def wait_for_structured_completion(task_id: str, max_wait_time: int = 300) -> dict[str, Any]:
"""Wait for task completion and return the result."""
- print('⏳ Waiting for structured output...')
+ print(f'⏳ Waiting for structured output (max {max_wait_time}s)...')
start_time = time.time()
@@ -137,6 +137,14 @@ def wait_for_structured_completion(task_id: str) -> dict[str, Any]:
status = response.json()
elapsed = time.time() - start_time
+ # Check for timeout
+ if elapsed > max_wait_time:
+ print(f'\r⏰ Task timeout after {max_wait_time}s - stopping wait' + ' ' * 30)
+ # Get final details before timeout
+ details_response = _request_with_retry('get', f'{BASE_URL}/task/{task_id}', headers=HEADERS)
+ details = details_response.json()
+ return details
+
# Get step count from full details for better progress tracking
details_response = _request_with_retry('get', f'{BASE_URL}/task/{task_id}', headers=HEADERS)
details = details_response.json()
diff --git a/examples/cloud/05_search_api.py b/examples/cloud/05_search_api.py
index 02e1934e5..eab7d71ff 100644
--- a/examples/cloud/05_search_api.py
+++ b/examples/cloud/05_search_api.py
@@ -13,6 +13,7 @@ Perfect for: Content extraction, research, competitive analysis
import argparse
import asyncio
+import json
import os
import time
from typing import Any
@@ -60,9 +61,14 @@ async def simple_search(query: str, max_websites: int = 5, depth: int = 2) -> di
async with session.post(f'{BASE_URL}/simple-search', json=payload, headers=HEADERS) as response:
elapsed = time.time() - start_time
if response.status == 200:
- result = await response.json()
- print(f'✅ Found results from {len(result.get("results", []))} websites in {elapsed:.1f}s')
- return result
+ try:
+ result = await response.json()
+ print(f'✅ Found results from {len(result.get("results", []))} websites in {elapsed:.1f}s')
+ return result
+ except (aiohttp.ContentTypeError, json.JSONDecodeError) as e:
+ error_text = await response.text()
+ print(f'❌ Invalid JSON response: {e} (after {elapsed:.1f}s)')
+ return {'error': 'Invalid JSON', 'details': error_text}
else:
error_text = await response.text()
print(f'❌ Search failed: {response.status} - {error_text} (after {elapsed:.1f}s)')
@@ -100,9 +106,14 @@ async def search_url(url: str, query: str, depth: int = 2) -> dict[str, Any]:
async with session.post(f'{BASE_URL}/search-url', json=payload, headers=HEADERS) as response:
elapsed = time.time() - start_time
if response.status == 200:
- result = await response.json()
- print(f'✅ Extracted content from {result.get("url", "website")} in {elapsed:.1f}s')
- return result
+ try:
+ result = await response.json()
+ print(f'✅ Extracted content from {result.get("url", "website")} in {elapsed:.1f}s')
+ return result
+ except (aiohttp.ContentTypeError, json.JSONDecodeError) as e:
+ error_text = await response.text()
+ print(f'❌ Invalid JSON response: {e} (after {elapsed:.1f}s)')
+ return {'error': 'Invalid JSON', 'details': error_text}
else:
error_text = await response.text()
print(f'❌ URL search failed: {response.status} - {error_text} (after {elapsed:.1f}s)')