playwright_navigate
Automate browser navigation by visiting a specified URL with a session automatically created, ideal for web testing and interaction tasks within browser automation workflows.
Instructions
Navigate to a URL,thip op will auto create a session
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes |
Implementation Reference
- src/playwright_server/server.py:205-218 (handler)The NavigateToolHandler class provides the core implementation for the 'playwright_navigate' tool. It ensures an active browser session exists (creating one if necessary), navigates the page to the specified URL, fetches the page's text content using another tool, and returns a confirmation with a preview of the text content.class NavigateToolHandler(ToolHandler): async def handle(self, name: str, arguments: dict | None) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: if not self._sessions: await NewSessionToolHandler().handle("",{}) # return [types.TextContent(type="text", text="No active session. Please create a new session first.")] session_id = list(self._sessions.keys())[-1] page = self._sessions[session_id]["page"] url = arguments.get("url") if not url.startswith("http://") and not url.startswith("https://"): url = "https://" + url await page.goto(url) text_content=await GetTextContentToolHandler().handle("",{}) return [types.TextContent(type="text", text=f"Navigated to {url}\npage_text_content[:200]:\n\n{text_content[:200]}")]
- Defines the tool schema returned by list_tools(), including name, description, and JSON input schema requiring a 'url' string parameter.types.Tool( name="playwright_navigate", description="Navigate to a URL,thip op will auto create a session", inputSchema={ "type": "object", "properties": { "url": {"type": "string"} }, "required": ["url"] } ),
- src/playwright_server/server.py:334-344 (registration)Registers the NavigateToolHandler instance in the tool_handlers dictionary, which is used by the @server.call_tool() handler to dispatch tool calls to the appropriate implementation.tool_handlers = { "playwright_navigate": NavigateToolHandler(), "playwright_screenshot": ScreenshotToolHandler(), "playwright_click": ClickToolHandler(), "playwright_fill": FillToolHandler(), "playwright_evaluate": EvaluateToolHandler(), "playwright_click_text": ClickTextToolHandler(), "playwright_get_text_content": GetTextContentToolHandler(), "playwright_get_html_content": GetHtmlContentToolHandler(), "playwright_new_session":NewSessionToolHandler(), }