From 4842593e3cc4c31ed61a3a00caef56218f18c465 Mon Sep 17 00:00:00 2001 From: pearsoj Date: Sat, 20 May 2023 20:17:40 +0100 Subject: [PATCH] fix: issue with missing chrome browser instance during tests --- packages/server/lib/browsers/chrome.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/server/lib/browsers/chrome.ts b/packages/server/lib/browsers/chrome.ts index 8d035f149b74..e529bd821389 100644 --- a/packages/server/lib/browsers/chrome.ts +++ b/packages/server/lib/browsers/chrome.ts @@ -580,11 +580,17 @@ export = { async connectToNewSpec (browser: Browser, options: BrowserNewTabOpts, automation: Automation) { debug('connecting to new chrome tab in existing instance with url and debugging port', { url: options.url }) - const browserCriClient = this._getBrowserCriClient() - - if (!browserCriClient) throw new Error('Missing browserCriClient in connectToNewSpec') + let browserClient = this._getBrowserCriClient(); + + if (!browserClient) { + // create a new instance of the client in case something went wrong + // https://github.com/cypress-io/cypress/issues/24650 + const port = await protocol.getRemoteDebuggingPort() + browserCriClient = await BrowserCriClient.create(['127.0.0.1'], port, browser.displayName, options.onError, onReconnect) + browserClient = browserCriClient; + } - const pageCriClient = browserCriClient.currentlyAttachedTarget + const pageCriClient = browserClient.currentlyAttachedTarget if (!pageCriClient) throw new Error('Missing pageCriClient in connectToNewSpec')