launch_browser
Launch a new browser instance (Chromium, Firefox, or WebKit) with headless mode and custom viewport support for web automation tasks via the MCP Browser Server.
Instructions
Launch a new browser instance (chromium, firefox, or webkit)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| browser | No | Browser engine to use | chromium |
| headless | No | Run browser in headless mode | |
| viewport | No |
Implementation Reference
- src/index.ts:411-456 (handler)Implements the launch_browser tool handler: parses input schema, closes existing browser if any, launches new Playwright browser (chromium/firefox/webkit) with specified options, creates context and page, sets up console logging, and returns success message.case 'launch_browser': { const params = LaunchBrowserSchema.parse(args); // Close existing browser if any if (currentBrowser) { await currentBrowser.close(); } // Clear console logs consoleLogs = []; // Launch new browser const browserType = params.browser === 'firefox' ? firefox : params.browser === 'webkit' ? webkit : chromium; currentBrowser = await browserType.launch({ headless: params.headless }); currentContext = await currentBrowser.newContext({ viewport: params.viewport ? { width: params.viewport.width, height: params.viewport.height } : undefined }); currentPage = await currentContext.newPage(); // Set up console event listener currentPage.on('console', (msg) => { consoleLogs.push({ level: msg.type(), message: msg.text(), timestamp: new Date() }); }); return { content: [ { type: 'text', text: `Browser ${params.browser} launched successfully ${params.headless ? '(headless)' : '(headed)'}` } ] }; }
- src/index.ts:14-21 (schema)Zod schema defining input parameters for launch_browser: browser type (default chromium), headless mode (default true), optional viewport dimensions.const LaunchBrowserSchema = z.object({ browser: z.enum(['chromium', 'firefox', 'webkit']).default('chromium'), headless: z.boolean().default(true), viewport: z.object({ width: z.number().default(1280), height: z.number().default(1024) }).optional() });
- src/index.ts:131-157 (registration)Registers the launch_browser tool in the ListTools response, providing name, description, and JSON schema matching the Zod schema.{ name: 'launch_browser', description: 'Launch a new browser instance (chromium, firefox, or webkit)', inputSchema: { type: 'object', properties: { browser: { type: 'string', enum: ['chromium', 'firefox', 'webkit'], default: 'chromium', description: 'Browser engine to use' }, headless: { type: 'boolean', default: true, description: 'Run browser in headless mode' }, viewport: { type: 'object', properties: { width: { type: 'number', default: 1280 }, height: { type: 'number', default: 720 } } } } } },