Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Switch all to jpeg
Magnus Müllera8e6af254e30
diff --git a/browser_use/agent/cloud_events.py b/browser_use/agent/cloud_events.pyindex ed7b3c4b3..4ff893df4 100644--- a/browser_use/agent/cloud_events.py+++ b/browser_use/agent/cloud_events.py@@ -155,7 +155,7 @@ class CreateAgentStepEvent(BaseEvent):# Capture screenshot as base64 data URL if availablescreenshot_url = Noneif browser_state_summary.screenshot:- screenshot_url = f'data:image/png;base64,{browser_state_summary.screenshot}'+ screenshot_url = f'data:image/jpeg;base64,{browser_state_summary.screenshot}'import logginglogger = logging.getLogger(__name__)diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex 42ef64926..2ea6cfa0d 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -367,8 +367,8 @@ Available tabs:content_parts.append(ContentPartImageParam(image_url=ImageURL(- url=f'data:image/png;base64,{screenshot}',- media_type='image/png',+ url=f'data:image/jpeg;base64,{screenshot}',+ media_type='image/jpeg',detail=self.vision_detail_level,),)diff --git a/browser_use/llm/google/serializer.py b/browser_use/llm/google/serializer.pyindex 2e85e580d..ff8dce6d0 100644--- a/browser_use/llm/google/serializer.py+++ b/browser_use/llm/google/serializer.py@@ -101,13 +101,13 @@ class GoogleMessageSerializer:# Handle imagesurl = part.image_url.url- # Format: data:image/png;base64,<data>+ # Format: data:image/jpeg;base64,<data>header, data = url.split(',', 1)# Decode base64 to bytesimage_bytes = base64.b64decode(data)# Add image part- image_part = Part.from_bytes(data=image_bytes, mime_type='image/png')+ image_part = Part.from_bytes(data=image_bytes, mime_type='image/jpeg')message_parts.append(image_part)diff --git a/browser_use/llm/ollama/serializer.py b/browser_use/llm/ollama/serializer.pyindex f7e0740da..afaf838a7 100644--- a/browser_use/llm/ollama/serializer.py+++ b/browser_use/llm/ollama/serializer.py@@ -47,7 +47,7 @@ class OllamaMessageSerializer:url = part.image_url.urlif url.startswith('data:'):# Handle base64 encoded images- # Format: data:image/png;base64,<data>+ # Format: data:image/jpeg;base64,<data>_, data = url.split(',', 1)# Decode base64 to bytesimage_bytes = base64.b64decode(data)diff --git a/browser_use/llm/tests/test_gemini_image.py b/browser_use/llm/tests/test_gemini_image.pyindex 75c3e6e73..5d7dcbcc5 100644--- a/browser_use/llm/tests/test_gemini_image.py+++ b/browser_use/llm/tests/test_gemini_image.py@@ -42,10 +42,10 @@ def create_random_text_image(text: str = 'hello world', width: int = 4000, heigh# Convert to base64buffer = io.BytesIO()- image.save(buffer, format='PNG')+ image.save(buffer, format='JPEG')img_data = base64.b64encode(buffer.getvalue()).decode()- return f'data:image/png;base64,{img_data}'+ return f'data:image/jpeg;base64,{img_data}'async def test_gemini_image_vision():diff --git a/examples/features/add_image_context.py b/examples/features/add_image_context.pyindex 0ec9875cc..2f759c8b6 100644--- a/examples/features/add_image_context.py+++ b/examples/features/add_image_context.py@@ -77,8 +77,8 @@ def create_sample_images() -> list[ContentPartTextParam | ContentPartImageParam]content_parts.append(ContentPartImageParam(image_url=ImageURL(- url=f'data:image/png;base64,{item["value"]}',- media_type='image/png',+ url=f'data:image/jpeg;base64,{item["value"]}',+ media_type='image/jpeg',),))