From 1cba11d86174c315b0f1264736fcd5122b44cd78 Mon Sep 17 00:00:00 2001 From: Asijit Manna Date: Mon, 6 Jul 2026 19:59:39 +0530 Subject: [PATCH] fix: prefer chromedriverPorts pool over single chromedriverPort when both are set When a caller supplies both the deprecated single `chromedriverPort` and the `chromedriverPorts` pool/range, the single port currently wins and the pool is silently ignored. That makes it impossible to guarantee a free port is picked from the configured pool (e.g. when several parallel sessions share a host). Prefer the `chromedriverPorts` pool when both are provided; behavior is unchanged when only one of them is set. Co-Authored-By: Claude Opus 4.8 --- lib/commands/context/helpers.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/commands/context/helpers.ts b/lib/commands/context/helpers.ts index 435e2fb9..54ed4abc 100644 --- a/lib/commands/context/helpers.ts +++ b/lib/commands/context/helpers.ts @@ -248,7 +248,17 @@ export async function setupNewChromedriver( opts.chromedriverPort = (opts as any).chromeDriverPort; } - if (opts.chromedriverPort) { + if (opts.chromedriverPort && opts.chromedriverPorts) { + // If both the single 'chromedriverPort' and the 'chromedriverPorts' pool are provided, prefer + // the pool. Otherwise the explicitly configured range would be silently bypassed by the single + // port, which is surprising and makes it impossible to guarantee a per-session port is picked + // from the pool (e.g. when several parallel sessions share the same host). + this.log.info( + `Both 'chromedriverPort' (${opts.chromedriverPort}) and 'chromedriverPorts' were provided; ` + + `preferring a free port from the 'chromedriverPorts' pool and ignoring 'chromedriverPort'`, + ); + opts.chromedriverPort = await getChromedriverPort.bind(this)(opts.chromedriverPorts); + } else if (opts.chromedriverPort) { this.log.debug(`Using user-specified port ${opts.chromedriverPort} for chromedriver`); } else { // if a single port wasn't given, we'll look for a free one