From fd9ed12d2499c022b45ba30703c75082dc743a78 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Sat, 18 Apr 2026 12:06:28 +0800 Subject: [PATCH] fix: respect connectTimeoutMs when waiting for first top-level page (fixes #1287) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On slow machines Chrome may still be setting up the first page after the CDP WebSocket handshake completes. The previous code always used a fixed 5-second timeout (DEFAULT_FIRST_TOP_LEVEL_PAGE_TIMEOUT_MS) regardless of any user-supplied timeout. Now V3Context.create() takes the *maximum* of connectTimeoutMs and the env-var/CI-derived default, so users who already bump connectTimeoutMs for a slow environment automatically get the same patience when waiting for the first page to appear—without any new API. --- packages/core/lib/v3/understudy/context.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/core/lib/v3/understudy/context.ts b/packages/core/lib/v3/understudy/context.ts index f1c70e16f..fca58500e 100644 --- a/packages/core/lib/v3/understudy/context.ts +++ b/packages/core/lib/v3/understudy/context.ts @@ -174,7 +174,14 @@ export class V3Context { opts?.localBrowserLaunchOptions ?? null, ); await ctx.bootstrap(); - await ctx.ensureFirstTopLevelPage(getFirstTopLevelPageTimeoutMs()); + // Allow connectTimeoutMs to also govern how long we wait for the first + // top-level page to appear. On slow machines the browser may need more + // time after the CDP socket is open before the initial page registers. + const firstPageTimeoutMs = Math.max( + opts?.localBrowserLaunchOptions?.connectTimeoutMs ?? 0, + getFirstTopLevelPageTimeoutMs(), + ); + await ctx.ensureFirstTopLevelPage(firstPageTimeoutMs); return ctx; };