@@ -27,7 +27,7 @@ AGB Browser Automation provides a managed platform for running headless/non-head
2727
2828### Prerequisites
2929
30- - Python 3.8 or higher
30+ - Python 3.10 or higher
3131- AGB API key (set as ` AGB_API_KEY ` environment variable)
3232- Playwright installed: ` pip install playwright && python -m playwright install chromium `
3333
@@ -47,35 +47,35 @@ async def main():
4747 # Initialize AGB client
4848 api_key = os.getenv(" AGB_API_KEY" )
4949 agb = AGB(api_key = api_key)
50-
50+
5151 # Create a session with browser support
5252 params = CreateSessionParams(image_id = " agb-browser-use-1" )
5353 result = agb.create(params)
54-
54+
5555 if not result.success:
5656 raise RuntimeError (f " Failed to create session: { result.error_message} " )
57-
57+
5858 session = result.session
59-
59+
6060 # Initialize browser
6161 success = await session.browser.initialize_async(BrowserOption())
6262 if not success:
6363 raise RuntimeError (" Browser initialization failed" )
64-
64+
6565 # Get CDP endpoint and connect Playwright
6666 endpoint_url = session.browser.get_endpoint_url()
67-
67+
6868 async with async_playwright() as p:
6969 browser = await p.chromium.connect_over_cdp(endpoint_url)
7070 page = await browser.new_page()
71-
71+
7272 # Navigate and interact
7373 await page.goto(" https://example.com" )
7474 title = await page.title()
7575 print (f " Page title: { title} " )
76-
76+
7777 await browser.close()
78-
78+
7979 # Clean up
8080 agb.delete(session)
8181
@@ -91,7 +91,7 @@ The `BrowserOption` class provides comprehensive configuration for your browser
9191
9292``` python
9393from agb.modules.browser import (
94- BrowserOption, BrowserViewport, BrowserScreen,
94+ BrowserOption, BrowserViewport, BrowserScreen,
9595 BrowserFingerprint, BrowserProxy
9696)
9797
@@ -303,7 +303,7 @@ stealth_option = BrowserOption(
303303# Check browser status
304304if session.browser.is_initialized():
305305 print (" Browser is ready" )
306-
306+
307307# Get current configuration
308308current_option = session.browser.get_option()
309309if current_option:
@@ -319,14 +319,14 @@ try:
319319 success = await session.browser.initialize_async(option)
320320 if not success:
321321 raise BrowserError(" Failed to initialize browser" )
322-
322+
323323 act_result = await session.browser.agent.act_async(page, ActOptions(
324324 action = " Click the submit button"
325325 ))
326-
326+
327327 if not act_result.success:
328328 print (f " Action failed: { act_result.message} " )
329-
329+
330330except BrowserError as e:
331331 print (f " Browser error: { e} " )
332332except Exception as e:
@@ -398,10 +398,10 @@ async def retry_action(agent, page, action_options, max_retries=3):
398398 print (f " Attempt { attempt + 1 } failed: { result.message} " )
399399 except Exception as e:
400400 print (f " Attempt { attempt + 1 } error: { e} " )
401-
401+
402402 if attempt < max_retries - 1 :
403403 await asyncio.sleep(2 ) # Wait before retry
404-
404+
405405 raise BrowserError(f " Action failed after { max_retries} attempts " )
406406```
407407
@@ -473,4 +473,4 @@ logging.basicConfig(level=logging.DEBUG)
473473- Explore the [ API Reference] ( ../api-reference/modules/browser.md ) for detailed method documentation
474474- Check out [ Browser Examples] ( ../examples/browser/README.md ) for practical use cases
475475- Learn about [ Session Management] ( session-management.md ) for advanced session handling
476- - Review [ Best Practices] ( best-practices.md ) for production deployments
476+ - Review [ Best Practices] ( best-practices.md ) for production deployments
0 commit comments