browse_to
Navigate to any URL and retrieve the full HTML content for web scraping, data extraction, or automated browsing tasks.
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 |
|---|---|---|---|
| url | Yes | ||
| context | No |
Implementation Reference
- src/mcp_web_browser/server.py:84-132 (handler)The core handler function for the 'browse_to' tool. Uses Playwright to launch a browser (if needed), 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
- src/mcp_web_browser/server.py:84-84 (registration)The @mcp.tool() decorator registers the browse_to function as an MCP tool.@mcp.tool()
- src/mcp_web_browser/server.py:21-35 (helper)Helper function to ensure the Playwright Chromium browser and context are initialized, with HTTPS errors ignored.async def _ensure_browser(): """Ensure a browser instance is available with SSL validation disabled""" global _browser, _browser_context, _playwright_instance if _browser is None: playwright_module = _import_playwright() _playwright_instance = await playwright_module().start() _browser = await _playwright_instance.chromium.launch() # Create a browser context that ignores HTTPS errors _browser_context = await _browser.new_context( ignore_https_errors=True, # Ignore SSL certificate errors ) return _browser, _browser_context
- src/mcp_web_browser/server.py:36-45 (helper)Helper to close the current browser page before navigating to a new URL.async def _close_current_page(): """Close the current page if it exists""" global _current_page if _current_page: try: await _current_page.close() except Exception: pass _current_page = None