refactor(browser): scope CDP sessions and harden stale target recovery

This commit is contained in:
Peter Steinberger
2026-03-08 19:52:23 +00:00
parent a6131438ea
commit a075baba84
15 changed files with 469 additions and 99 deletions

View File

@@ -86,16 +86,7 @@ export function createProfileSelectionOps({
return page ?? candidates.at(0) ?? null;
};
let chosen = targetId ? resolveById(targetId) : pickDefault();
if (
!chosen &&
(profile.driver === "extension" || !profile.cdpIsLoopback) &&
candidates.length === 1
) {
// If an agent passes a stale/foreign targetId but only one candidate remains,
// recover by using that tab instead of failing hard.
chosen = candidates[0] ?? null;
}
const chosen = targetId ? resolveById(targetId) : pickDefault();
if (chosen === "AMBIGUOUS") {
throw new Error("ambiguous target id prefix");