mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 03:01:50 +03:00
Browser: avoid single-page target lookup hang under blocked CDP attach
This commit is contained in:
@@ -388,13 +388,25 @@ async function findPageByTargetId(
|
|||||||
cdpUrl?: string,
|
cdpUrl?: string,
|
||||||
): Promise<Page | null> {
|
): Promise<Page | null> {
|
||||||
const pages = await getAllPages(browser);
|
const pages = await getAllPages(browser);
|
||||||
|
let resolvedViaCdp = false;
|
||||||
// First, try the standard CDP session approach
|
// First, try the standard CDP session approach
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
const tid = await pageTargetId(page).catch(() => null);
|
let tid: string | null = null;
|
||||||
|
try {
|
||||||
|
tid = await pageTargetId(page);
|
||||||
|
resolvedViaCdp = true;
|
||||||
|
} catch {
|
||||||
|
tid = null;
|
||||||
|
}
|
||||||
if (tid && tid === targetId) {
|
if (tid && tid === targetId) {
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Extension relays can block CDP attachment APIs entirely. If that happens and
|
||||||
|
// Playwright only exposes one page, return it as the best available mapping.
|
||||||
|
if (!resolvedViaCdp && pages.length === 1) {
|
||||||
|
return pages[0];
|
||||||
|
}
|
||||||
// If CDP sessions fail (e.g., extension relay blocks Target.attachToBrowserTarget),
|
// If CDP sessions fail (e.g., extension relay blocks Target.attachToBrowserTarget),
|
||||||
// fall back to URL-based matching using the /json/list endpoint
|
// fall back to URL-based matching using the /json/list endpoint
|
||||||
if (cdpUrl) {
|
if (cdpUrl) {
|
||||||
|
|||||||
Reference in New Issue
Block a user