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.
This commit is contained in:
zeroaltitude 2026-03-18 20:21:23 -07:00
parent 696dcd5ddd
commit 8eac832ea9
No known key found for this signature in database
GPG Key ID: 77592FB1C703882E

View File

@ -197,19 +197,26 @@ export async function withRouteTabContext<T>(
// 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);