puppeteer_connect_active_tab
Connect to an active Chrome tab for debugging or automation tasks. Specify a target URL or use the first available tab, and set a custom debugging port if needed. Ideal for Puppeteer-based workflows.
Instructions
Connect to an existing Chrome instance with remote debugging enabled
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| debugPort | No | Optional Chrome debugging port (default: 9222) | |
| targetUrl | No | Optional URL of the target tab to connect to. If not provided, connects to the first available tab. |
Implementation Reference
- src/tools/handlers.ts:23-64 (handler)Executes the puppeteer_connect_active_tab tool by connecting to an existing Chrome debugging instance and handling success/error responses.case "puppeteer_connect_active_tab": try { const wsEndpoint = await getDebuggerWebSocketUrl(args.debugPort); const connectedPage = await connectToExistingBrowser( wsEndpoint, args.targetUrl, (logEntry) => { state.consoleLogs.push(logEntry); notifyConsoleUpdate(server); } ); const url = await connectedPage.url(); const title = await connectedPage.title(); return { content: [{ type: "text", text: `Successfully connected to browser\nActive webpage: ${title} (${url})`, }], isError: false, }; } catch (error) { const errorMessage = (error as Error).message; const isConnectionError = errorMessage.includes('connect to Chrome debugging port') || errorMessage.includes('Target closed'); return { content: [{ type: "text", text: `Failed to connect to browser: ${errorMessage}\n\n` + (isConnectionError ? "To connect to Chrome:\n" + "1. Close Chrome completely\n" + "2. Reopen Chrome with remote debugging enabled:\n" + " Windows: chrome.exe --remote-debugging-port=9222\n" + " Mac: /Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --remote-debugging-port=9222\n" + "3. Navigate to your desired webpage\n" + "4. Try the operation again" : "Please check if Chrome is running and try again.") }], isError: true, }; }
- src/tools/definitions.ts:4-22 (schema)Tool schema definition including name, description, and input schema for puppeteer_connect_active_tab.{ name: "puppeteer_connect_active_tab", description: "Connect to an existing Chrome instance with remote debugging enabled", inputSchema: { type: "object", properties: { targetUrl: { type: "string", description: "Optional URL of the target tab to connect to. If not provided, connects to the first available tab." }, debugPort: { type: "number", description: "Optional Chrome debugging port (default: 9222)", default: 9222 } }, required: [], }, },
- src/server.ts:34-41 (registration)Registers the MCP server request handlers for listing tools (using definitions) and calling tools (using handlers).// Setup tool handlers server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS, })); server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, state, server) );