navigate
Direct a browser to a specified URL for automation tasks, enabling precise control over web navigation within Playwright MCP's browser automation framework.
Instructions
Navigate to a URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_id | No | ||
| url | Yes |
Input Schema (JSON Schema)
{
"properties": {
"page_id": {
"type": "string"
},
"url": {
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- src/playwright_mcp/server.py:228-235 (handler)The core handler logic for the 'navigate' tool within the handle_call_tool function. It retrieves the URL from arguments, validates it, selects the appropriate page, navigates to the URL using Playwright's page.goto(), and returns a confirmation message.if name == "navigate": url = arguments.get("url") if not url: raise ValueError("URL is required") page = get_active_page(arguments.get("page_id")) await page.goto(url) return [types.TextContent(type="text", text=f"Navigated to {url}")]
- src/playwright_mcp/server.py:85-96 (registration)Registration of the 'navigate' tool in the handle_list_tools() function, including name, description, and input schema.types.Tool( name="navigate", description="Navigate to a URL", inputSchema={ "type": "object", "properties": { "url": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["url"], }, ),
- src/playwright_mcp/server.py:88-95 (schema)Input schema definition for the 'navigate' tool, specifying required 'url' parameter and optional 'page_id'.inputSchema={ "type": "object", "properties": { "url": {"type": "string"}, "page_id": {"type": "string"}, }, "required": ["url"], },
- src/playwright_mcp/server.py:200-211 (helper)Helper function get_active_page used by the navigate handler to retrieve the correct Page object based on page_id or default.def get_active_page(page_id: Optional[str] = None) -> Page: """Get the active page based on page_id or current default.""" global current_page_id if page_id is None: page_id = current_page_id if page_id not in pages: raise ValueError(f"Page not found: {page_id}") return pages[page_id]