-
Notifications
You must be signed in to change notification settings - Fork 234
Open
Description
Problem
getAISnapshot() can hang indefinitely on pages with heavy JavaScript execution or anti-bot measures. There's no timeout mechanism, so scripts calling this function may never complete.
Reproduction
const client = await connect();
const page = await client.page("test");
await page.goto("https://some-heavy-js-site.com");
// This may hang forever
const snapshot = await getAISnapshot(page);Proposed Solution
Add timeout handling with a fast health check:
- Health check first: Run a quick 3-second
page.evaluate(() => true)to detect unresponsive pages early - Configurable timeout: Add optional
timeoutparameter (default 10s) - Clear error messages: Explain why the page might be unresponsive
async function getAISnapshot(page: Page, timeout = 10000): Promise<string> {
// Quick health check
const healthCheck = page.evaluate(() => true);
const healthy = await Promise.race([
healthCheck.then(() => true),
new Promise(r => setTimeout(() => r(false), 3000))
]);
if (!healthy) {
throw new Error('Page unresponsive - may have anti-bot measures');
}
// Actual snapshot with timeout
return Promise.race([
actualSnapshotLogic(page),
new Promise((_, reject) =>
setTimeout(() => reject(new Error(`Timeout after ${timeout}ms`)), timeout)
)
]);
}Working Implementation
I have this fix in my fork:
- https://github.com/parkerhancock/dev-browser
- Commit
52c26d4- Add timeout handling to getAISnapshot for heavy JS sites
Happy to submit a PR if there's interest.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels