openBrowser
Launch a new browser instance for web scraping, testing, and interaction using Playwright. Configure headless mode and debugging options to automate tasks efficiently.
Instructions
Launch a new browser instance
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| debug | No | ||
| headless | No |
Implementation Reference
- src/controllers/playwright.ts:25-57 (handler)The main handler function that launches a Chromium browser instance using Playwright, handling headless mode and debug logging.async openBrowser(headless: boolean = false, debug: boolean = false): Promise<void> { try { this.state.debug = debug; this.log('Attempting to launch browser'); if (this.state.browser?.isConnected()) { this.log('Browser already running'); return; } this.log('Launching new browser instance', { headless }); this.state.browser = await chromium.launch({ headless, args: ['--no-sandbox'] }); this.log('Creating browser context'); this.state.context = await this.state.browser.newContext({ viewport: { width: 1280, height: 720 } }); this.log('Creating new page'); this.state.page = await this.state.context.newPage(); this.log('Browser successfully launched'); } catch (error: any) { console.error('Browser launch error:', error); throw new BrowserError( 'Failed to launch browser', `Technical details: ${error?.message || 'Unknown error'}` ); } }
- src/server.ts:6-17 (schema)Input schema definition for the openBrowser tool, specifying optional boolean parameters for headless and debug modes.const OPEN_BROWSER_TOOL: Tool = { name: "openBrowser", description: "Launch a new browser instance", inputSchema: { type: "object", properties: { headless: { type: "boolean" }, debug: { type: "boolean" } }, required: [] } };
- src/server.ts:515-515 (registration)Registration of the openBrowser tool in the tools object provided to the MCP server capabilities.openBrowser: OPEN_BROWSER_TOOL,
- src/server.ts:576-584 (registration)Dispatch handler in callTool request handler that invokes the openBrowser controller method with parsed arguments.case 'openBrowser': { await playwrightController.openBrowser( args.headless as boolean, args.debug as boolean ); return { content: [{ type: "text", text: "Browser opened successfully" }] }; }