* Initializes the Chrome DevTools MCP server and establishes connection. * * @param options - Configuration options * @param options.headless - Run browser in headless mode (default: true) * @returns This wrapper instance for chaining * @throws Error if connection fails
(options?: { headless?: boolean })
| 268 | * @throws Error if connection fails |
| 269 | */ |
| 270 | async connect(options?: { headless?: boolean }): Promise<this> { |
| 271 | const headless = options?.headless ?? true; |
| 272 | |
| 273 | cli.info("Starting Chrome DevTools MCP server..."); |
| 274 | |
| 275 | const transport = new StdioClientTransport({ |
| 276 | command: "npx", |
| 277 | args: [ |
| 278 | "@mcp-b/chrome-devtools-mcp@latest", |
| 279 | ...(headless ? ["--headless"] : []), |
| 280 | ], |
| 281 | }); |
| 282 | |
| 283 | this.client = new Client({ |
| 284 | name: "benchmark-client", |
| 285 | version: "1.0.0", |
| 286 | }); |
| 287 | |
| 288 | await this.client.connect(transport); |
| 289 | cli.success("MCP client connected"); |
| 290 | |
| 291 | const tools = await this.client.listTools(); |
| 292 | cli.info(`Available MCP tools: ${tools.tools.length}`); |
| 293 | |
| 294 | // Set viewport to 14-inch MacBook size for realistic screenshots |
| 295 | await this.callTool("resize_page", { width: 1512, height: 982 }); |
| 296 | cli.info("Browser viewport set to 1512x982"); |
| 297 | |
| 298 | return this; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Executes an MCP tool call with type-safe arguments. |