Files
geo/apps/desktop-client/src/main/playwright-cdp-targets.ts
T
root b48729e4a2 refactor(desktop): extract hidden Playwright CDP target helper
Move CDPTargetDescriptor and the reclaim predicate out of
playwright-cdp.ts into a dedicated module so the reclamation rule can be
unit-tested in isolation and reused without pulling in the whole hidden
browser manager.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 09:39:03 +08:00

30 lines
824 B
TypeScript

export interface CDPTargetDescriptor {
id?: string;
type?: string;
title?: string;
url?: string;
}
const hiddenPlaywrightTargetMarkers = [
"hidden-playwright",
"geo-hidden-playwright-token",
] as const;
export function isReclaimableHiddenPlaywrightTarget(target: CDPTargetDescriptor): boolean {
if ((target.type ?? "").trim() !== "page") {
return false;
}
if (!(target.id ?? "").trim()) {
return false;
}
const title = target.title ?? "";
const url = target.url ?? "";
const haystack = `${title}\n${url}`.toLowerCase();
// Blank Electron page targets can belong to visible BrowserWindow shells.
// Only reclaim targets that we can prove were created by the hidden
// Playwright bootstrap flow.
return hiddenPlaywrightTargetMarkers.some((marker) => haystack.includes(marker));
}