browser_navigate
Navigate to a specified URL and wait for the page to load using Playwright MCP Server, enabling automation of web tasks like navigation, HTML extraction, and screenshots.
Instructions
Navigate to a specified URL and wait for page load
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | ||
| waitUntil | No | domcontentloaded |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"url": {
"format": "uri",
"type": "string"
},
"waitUntil": {
"default": "domcontentloaded",
"enum": [
"networkidle",
"domcontentloaded",
"load"
],
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- src/server.ts:33-59 (handler)Handler function that executes the browser_navigate tool: validates input, connects to browser if needed, navigates to URL using page.goto, returns success/error text response.async (params: any) => { try { const input = z.object({ url: z.string().url(), waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('domcontentloaded') }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.goto(input.url, { waitUntil: input.waitUntil }); return { content: [{ type: 'text', text: `Successfully navigated to ${page.url()}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Navigation failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/server.ts:23-32 (registration)Registers the 'browser_navigate' tool with the MCP server, providing name, metadata (title, description), and input schema.this.server.registerTool( 'browser_navigate', { title: 'Navigate to URL', description: 'Navigate to a specified URL and wait for page load', inputSchema: { url: z.string().url(), waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('domcontentloaded') } },
- src/types.ts:13-16 (schema)Zod schema defining the input structure for the browser_navigate tool (url required, waitUntil optional).export const BrowserNavigateInputSchema = z.object({ url: z.string().url(), waitUntil: z.enum(['networkidle', 'domcontentloaded', 'load']).optional().default('domcontentloaded') });
- src/playwright.ts:111-117 (helper)Helper method ensureConnected() called by the handler to verify and establish Playwright browser connection if necessary.async ensureConnected(): Promise<void> { const connected = await this.isConnected(); if (!connected) { await this.cleanup(); await this.connect(); } }
- src/playwright.ts:73-78 (helper)Helper method getPage() called by the handler to retrieve the current Playwright Page instance.getPage(): Page { if (!this.page) { throw new Error('Playwright not connected. Call connect() first.'); } return this.page; }