From 8eac832ea9bfda6774bf91dd647ba825e4b451d7 Mon Sep 17 00:00:00 2001 From: zeroaltitude Date: Wed, 18 Mar 2026 20:21:23 -0700 Subject: [PATCH] fix(browser): skip CDP URL lookup for existing-session profiles existing-session profiles set cdpUrl to '' (Chrome MCP auto-connect, no CDP port). Passing an empty cdpUrl to getPageForTargetId would always fail silently, leaving postRunUrl undefined and falling back to the stale pre-run tab.url. Explicitly skip the Playwright lookup when cdpUrl is empty and rely on tab.url, which the relay keeps updated via tabs.onUpdated. --- src/browser/routes/agent.shared.ts | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/browser/routes/agent.shared.ts b/src/browser/routes/agent.shared.ts index 028fe6de8ed..08e0ec8ede4 100644 --- a/src/browser/routes/agent.shared.ts +++ b/src/browser/routes/agent.shared.ts @@ -197,19 +197,26 @@ export async function withRouteTabContext( // Note: cross-site navigations that trigger a renderer swap may // invalidate tab.targetId; in that case getPageForTargetId returns // null and we fall back to the (possibly stale) tab.url. - try { - const pwMod = await getPwAiModuleBase({ mode: "soft" }); - if (pwMod?.getPageForTargetId) { - const page = await pwMod.getPageForTargetId({ - cdpUrl: profileCtx.profile.cdpUrl, - targetId: tab.targetId, - }); - if (page) { - postRunUrl = page.url(); + // existing-session profiles set cdpUrl to "" (Chrome MCP auto-connect, + // no CDP port). Passing an empty cdpUrl to getPageForTargetId would + // always fail, so skip the Playwright lookup for those profiles and + // rely on tab.url (updated by the relay on each tabs.onUpdated event). + const cdpUrl = profileCtx.profile.cdpUrl; + if (cdpUrl) { + try { + const pwMod = await getPwAiModuleBase({ mode: "soft" }); + if (pwMod?.getPageForTargetId) { + const page = await pwMod.getPageForTargetId({ + cdpUrl, + targetId: tab.targetId, + }); + if (page) { + postRunUrl = page.url(); + } } + } catch { + // Playwright unavailable — fall back to tab.url } - } catch { - // Playwright unavailable — fall back to tab.url } } enrichTabResponseBody(interceptedBody, tab, postRunUrl);