From f8491f01aeb60449ec89056d55028097766917b4 Mon Sep 17 00:00:00 2001 From: jackwener Date: Mon, 16 Mar 2026 01:51:22 +0800 Subject: [PATCH] fix: add 5s timeout for initial tabs fetch during CDP connect CDP mode on @playwright/mcp v0.0.68 hangs on browser_tabs calls. This timeout prevents the entire connect() from blocking for 30s. --- src/browser.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/browser.ts b/src/browser.ts index 09e0488..7367a1e 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -636,9 +636,9 @@ export class PlaywrightMCP { debugLog(`SEND: ${initializedMsg.trim()}`); this._proc?.stdin?.write(initializedMsg); - // Get initial tab count for cleanup + // Get initial tab count for cleanup (with timeout — CDP mode may hang on browser_tabs) debugLog('Fetching initial tabs count...'); - page.tabs().then((tabs: any) => { + withTimeout(page.tabs(), 5000, 'Timed out fetching initial tabs').then((tabs: any) => { debugLog(`Tabs response: ${typeof tabs === 'string' ? tabs : JSON.stringify(tabs)}`); this._initialTabIdentities = extractTabIdentities(tabs); settleSuccess(page);