diff --git a/requirements.txt b/requirements.txt
index 852269e..faf4b2c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
-browser-use>=0.1.18
-langchain-google-genai>=2.0.8
+browser-use==0.1.18
+langchain-google-genai==2.0.8
pyperclip
gradio
langchain-ollama
diff --git a/src/utils/utils.py b/src/utils/utils.py
index 7e05dda..d5a8b25 100644
--- a/src/utils/utils.py
+++ b/src/utils/utils.py
@@ -164,38 +164,39 @@ def get_latest_files(directory: str, file_types: list = ['.webm', '.zip']) -> Di
print(f"Error getting latest {file_type} file: {e}")
return latest_files
-async def capture_screenshot(browser_context) -> str:
+async def capture_screenshot(browser_context):
"""Capture and encode a screenshot"""
+ # Extract the Playwright browser instance
+ playwright_browser = browser_context.browser.playwright_browser # Ensure this is correct.
+
+ # Check if the browser instance is valid and if an existing context can be reused
+ if playwright_browser and playwright_browser.contexts:
+ playwright_context = playwright_browser.contexts[0]
+ else:
+ return None
+
+ # Access pages in the context
+ pages = None
+ if playwright_context:
+ pages = playwright_context.pages
+
+ # Use an existing page or create a new one if none exist
+ if pages:
+ active_page = pages[0]
+ for page in pages:
+ if page.url != "about:blank":
+ active_page = page
+ else:
+ return None
+
+ # Take screenshot
try:
- # Extract the Playwright browser instance
- playwright_browser = browser_context.browser.playwright_browser # Ensure this is correct.
-
- # Check if the browser instance is valid and if an existing context can be reused
- if playwright_browser and playwright_browser.contexts:
- playwright_context = playwright_browser.contexts[0]
-
- # Access pages in the context
- if playwright_context:
- pages = playwright_context.pages
-
- # Use an existing page or create a new one if none exist
- if pages:
- active_page = pages[0]
- for page in pages:
- if page.url != "about:blank":
- active_page = page
-
- # Take screenshot
- try:
- screenshot = await active_page.screenshot(
- type='jpeg',
- quality=75,
- scale="css"
- )
- encoded = base64.b64encode(screenshot).decode('utf-8')
- return f''
- except Exception as e:
- return f"