Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/strands_tools/browser/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,10 @@ async def _async_get_text(self, action: GetTextAction) -> Dict[str, Any]:
return {"status": "error", "content": [{"text": "Error: No active page for session"}]}

try:
text = await page.text_content(action.selector)
if action.method == "inner_text":
Comment thread
zastrowm marked this conversation as resolved.
text = await page.inner_text(action.selector)
else:
text = await page.text_content(action.selector)
return {"status": "success", "content": [{"text": f"Text content: {text}"}]}
except Exception as e:
logger.debug("exception=<%s> | get text action failed on selector '%s'", str(e), action.selector)
Expand Down Expand Up @@ -584,9 +587,9 @@ 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}]}
if action.max_length 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)}"}]}
Expand Down
9 changes: 9 additions & 0 deletions src/strands_tools/browser/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ class GetTextAction(BaseModel):
type: Literal["get_text"] = Field(description="Get text content from an element")
session_name: str = Field(description="Required session name from a previous init_session call")
selector: str = Field(description="CSS selector for the element")
method: Literal["inner_text", "text_content"] = Field(
default="inner_text",
description="Text extraction method: 'inner_text' (default) excludes script/style/hidden content, "
"'text_content' returns all raw text including scripts and styles",
)


class GetHtmlAction(BaseModel):
Expand All @@ -159,6 +164,10 @@ 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 character length of returned HTML. None (default) returns full content without truncation",
)


class ScreenshotAction(BaseModel):
Expand Down
Loading