From 19c62a84b0472a425f39cba66337afbd339f9451 Mon Sep 17 00:00:00 2001 From: yicheng <928596708@qq.com> Date: Tue, 16 Jun 2026 10:48:06 +0800 Subject: [PATCH] fix(browser): make get_html truncation configurable instead of hard-coded 1000 chars - Add optional max_length parameter to GetHtmlAction (defaults to None = full HTML) - Remove hard-coded 1000-char truncation, return full HTML by default - Fixes #407 --- src/strands_tools/browser/browser.py | 7 ++++--- src/strands_tools/browser/models.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/strands_tools/browser/browser.py b/src/strands_tools/browser/browser.py index 03d44808..644ea4d9 100644 --- a/src/strands_tools/browser/browser.py +++ b/src/strands_tools/browser/browser.py @@ -594,9 +594,10 @@ async def _async_get_html(self, action: GetHtmlAction) -> Dict[str, Any]: ], } - # Truncate long HTML content - truncated_result = result[:1000] + "..." if len(result) > 1000 else result - return {"status": "success", "content": [{"text": truncated_result}]} + # Optionally truncate HTML content + if action.max_length is not None and len(result) > action.max_length: + result = result[:action.max_length] + "..." + return {"status": "success", "content": [{"text": result}]} except Exception as e: logger.debug("exception=<%s> | get HTML action failed", str(e)) return {"status": "error", "content": [{"text": f"Error: {str(e)}"}]} diff --git a/src/strands_tools/browser/models.py b/src/strands_tools/browser/models.py index 82ab32cb..c395e623 100644 --- a/src/strands_tools/browser/models.py +++ b/src/strands_tools/browser/models.py @@ -159,6 +159,7 @@ class GetHtmlAction(BaseModel): type: Literal["get_html"] = Field(description="Get HTML content") session_name: str = Field(description="Required session name from a previous init_session call") selector: Optional[str] = Field(default=None, description="CSS selector for specific element (optional)") + max_length: Optional[int] = Field(default=None, description="Maximum characters to return. None returns full HTML.") class ScreenshotAction(BaseModel):