browser_get_visible_text
Extract visible text from web pages using an automation tool designed to bypass anti-bot detection, enabling reliable scraping and testing on protected sites.
Instructions
Get the visible text of the current page
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "browser_get_visible_text"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The handler function for 'browser_get_visible_text' tool. It is registered via @mcp.tool() decorator. Executes JavaScript to collect and join visible text content from all elements on the page that are not hidden.
@mcp.tool() async def browser_get_visible_text(): """Get the visible text of the current page""" async def get_visible_text_handler(driver: uc.Chrome): # 使用JavaScript获取页面中所有可见文本内容 script = """ return Array.from(document.body.querySelectorAll('*')) .filter(el => { const style = window.getComputedStyle(el); return !!(el.textContent.trim()) && style.display !== 'none' && style.visibility !== 'hidden' && style.opacity !== '0'; }) .map(el => el.textContent.trim()) .filter(text => text) .join('\\n'); """ visible_text = driver.execute_script(script) return await create_success_response(visible_text) return await tool.safe_execute( ToolContext(webdriver=await ensure_browser()), get_visible_text_handler ) - src/mcp_server_undetected_chromedriver/server.py:300-300 (registration)Registration of the 'browser_get_visible_text' tool using FastMCP's @mcp.tool() decorator.
@mcp.tool()