playwright_navigate
Direct a browser to a specified URL using Playwright automation, enabling web page interaction, content retrieval, and testing within an automated environment.
Instructions
Navigate to a URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes |
Implementation Reference
- src/toolsHandler.ts:63-88 (handler)The core handler logic for the 'playwright_navigate' tool. It navigates the Playwright page to the specified URL with optional timeout and waitUntil options, returning success or error message.case "playwright_navigate": try { await page!.goto(args.url, { timeout: args.timeout || 30000, waitUntil: args.waitUntil || "load" }); return { toolResult: { content: [{ type: "text", text: `Navigated to ${args.url} with ${args.waitUntil || "load"} wait`, }], isError: false, }, }; } catch (error) { return { toolResult: { content: [{ type: "text", text: `Navigation failed: ${(error as Error).message}`, }], isError: true, }, }; }
- src/tools.ts:5-15 (schema)The tool schema definition for 'playwright_navigate', including name, description, and input schema requiring a 'url' string.{ name: "playwright_navigate", description: "Navigate to a URL", inputSchema: { type: "object", properties: { url: { type: "string" }, }, required: ["url"], }, },
- src/requestHandler.ts:64-67 (registration)Registration of the MCP CallTool request handler, which routes tool calls (including 'playwright_navigate') to the handleToolCall function in toolsHandler.ts.// Call tool handler server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, server) );
- src/requestHandler.ts:60-62 (registration)Registration of the MCP ListTools request handler, which provides the list of available tools including 'playwright_navigate'.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, }));
- src/toolsHandler.ts:15-32 (helper)Helper function to ensure the Playwright browser and page are launched, used by browser-requiring tools like 'playwright_navigate'.async function ensureBrowser() { if (!browser) { browser = await chromium.launch({ headless: false }); const context = await browser.newContext({ viewport: { width: 1920, height: 1080 }, deviceScaleFactor: 1, }); page = await context.newPage(); page.on("console", (msg) => { const logEntry = `[${msg.type()}] ${msg.text()}`; consoleLogs.push(logEntry); // Note: server.notification is assumed to be passed in from the main server }); } return page!; }