browse_to
Extract HTML content from any webpage by navigating to a specified URL using a headless browser interface. This tool simplifies web data retrieval for analysis or processing.
Instructions
Navigate to a specific URL and return the page's HTML content.
Args:
url: The full URL to navigate to
context: Optional context object for logging (ignored)
Returns:
The full HTML content of the page
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | ||
| url | Yes |
Implementation Reference
- src/mcp_web_browser/server.py:84-132 (handler)The main handler function for the 'browse_to' tool. It uses Playwright to launch a Chromium browser (if not already), create a new page, navigate to the given URL with networkidle wait and 30s timeout, ignoring HTTPS errors, and returns the full HTML content of the page.@mcp.tool() async def browse_to(url: str, context: Optional[Any] = None) -> str: """ Navigate to a specific URL and return the page's HTML content. Args: url: The full URL to navigate to context: Optional context object for logging (ignored) Returns: The full HTML content of the page """ global _current_page, _browser, _browser_context # Ensure browser is launched with SSL validation disabled _, browser_context = await _ensure_browser() # Close any existing page await _close_current_page() # Optional logging, but do nothing with context print(f"Navigating to {url}", file=sys.stderr) try: # Create a new page and navigate _current_page = await browser_context.new_page() # Additional options to handle various SSL/security issues await _current_page.goto(url, wait_until='networkidle', timeout=30000, # 30 seconds timeout ) # Get full page content including dynamically loaded JavaScript page_content = await _current_page.content() # Optional: extract additional metadata try: title = await _current_page.title() print(f"Page title: {title}", file=sys.stderr) except Exception: pass return page_content except Exception as e: print(f"Error navigating to {url}: {e}", file=sys.stderr) raise