From 44243a1b979ed5ee11a4d88085aea439494b611e Mon Sep 17 00:00:00 2001 From: Sheng Fan Date: Wed, 19 Mar 2025 16:57:12 +0800 Subject: [PATCH] fix(browser_use_tool): reimplement screenshot logics to get JPEG data --- app/tool/browser_use_tool.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/tool/browser_use_tool.py b/app/tool/browser_use_tool.py index 7fe8f16..0158e07 100644 --- a/app/tool/browser_use_tool.py +++ b/app/tool/browser_use_tool.py @@ -1,4 +1,5 @@ import asyncio +import base64 import json from typing import Generic, Optional, TypeVar @@ -552,7 +553,16 @@ Page content: viewport_height = ctx.config.browser_window_size.get("height", 0) # Take a screenshot for the state - screenshot = await ctx.take_screenshot(full_page=True) + page = await ctx.get_current_page() + + await page.bring_to_front() + await page.wait_for_load_state() + + screenshot = await page.screenshot( + full_page=True, animations="disabled", type="jpeg", quality=100 + ) + + screenshot = base64.b64encode(screenshot).decode("utf-8") # Build the state info with all required fields state_info = {