fix: Prevent CDP timeout on empty URL tabs (#102)

When connecting to a browser via CDP, particularly on Android, tabs with an empty URL can cause Playwright commands to hang indefinitely. This leads to a timeout in agent-browser.

This commit fixes the issue by filtering out any pages that have an empty `page.url()` during the CDP connection process. This prevents agent-browser from attempting to interact with these problematic tabs, resolving the timeout while preserving normal pages.

Added a unit test to verify that pages with empty URLs are correctly ignored. Also increased the timeout for a flaky screencast test to improve test suite stability.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: sheing-google <231310897+sheing-google@users.noreply.github.com>
This commit is contained in:
Sheing
2026-01-17 18:16:37 -06:00
committed by GitHub
co-authored by google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> sheing-google
parent e196ed3e35
commit 7aad47d3bd
2 changed files with 37 additions and 3 deletions
+5 -1
View File
@@ -738,7 +738,11 @@ export class BrowserManager {
throw new Error('No browser context found. Make sure the app has an open window.');
}
const allPages = contexts.flatMap((context) => context.pages());
// Filter out pages with empty URLs, which can cause Playwright to hang
const allPages = contexts
.flatMap((context) => context.pages())
.filter((page) => page.url());
if (allPages.length === 0) {
throw new Error('No page found. Make sure the app has loaded content.');
}