Fix networkidle timeouts and Firefox cookie domain normalization
- Replace networkidle with domcontentloaded + 5s race in goto, click, and session_restore — SPAs with persistent connections (LinkedIn, Gmail) never reach networkidle - Normalize .www. cookie domains in Firefox importer — Playwright silently drops cookies with .www.example.com domains Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+9
-2
@@ -394,7 +394,12 @@ export class ClaudeBrowser {
|
||||
|
||||
async goto(url: string): Promise<{ url: string; title: string }> {
|
||||
const page = this.ensurePage();
|
||||
await page.goto(url, { waitUntil: 'networkidle' });
|
||||
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
||||
// Best-effort wait for network to settle — SPAs with persistent connections
|
||||
// (LinkedIn, Twitter, Gmail) never reach networkidle, so cap at 5s
|
||||
await Promise.race([page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]).catch(
|
||||
() => {}
|
||||
);
|
||||
return { url: page.url(), title: await page.title() };
|
||||
}
|
||||
|
||||
@@ -402,7 +407,9 @@ export class ClaudeBrowser {
|
||||
const page = this.ensurePage();
|
||||
await this.previewAction(selector, 'CLICK');
|
||||
await page.click(selector);
|
||||
await page.waitForLoadState('networkidle').catch(() => {});
|
||||
await Promise.race([page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]).catch(
|
||||
() => {}
|
||||
);
|
||||
return { url: page.url() };
|
||||
}
|
||||
|
||||
|
||||
+8
-1
@@ -283,10 +283,17 @@ export function toPlaywrightCookie(cookie: FirefoxCookie): {
|
||||
expires = -1;
|
||||
}
|
||||
|
||||
// Normalize domain: Firefox sometimes stores ".www.example.com" which Playwright
|
||||
// won't match for "www.example.com". Strip ".www." prefix to ".example.com".
|
||||
let domain = cookie.domain;
|
||||
if (domain.startsWith('.www.')) {
|
||||
domain = domain.slice(4); // ".www.example.com" -> ".example.com"
|
||||
}
|
||||
|
||||
return {
|
||||
name: cookie.name,
|
||||
value: cookie.value,
|
||||
domain: cookie.domain,
|
||||
domain,
|
||||
path: cookie.path,
|
||||
expires,
|
||||
secure: cookie.secure,
|
||||
|
||||
+4
-1
@@ -665,7 +665,10 @@ server.tool(
|
||||
|
||||
// Navigate to saved URL
|
||||
if (data.url) {
|
||||
await page.goto(data.url, { waitUntil: 'networkidle' });
|
||||
await page.goto(data.url, { waitUntil: 'domcontentloaded' });
|
||||
await Promise.race([page.waitForLoadState('networkidle'), page.waitForTimeout(5000)]).catch(
|
||||
() => {}
|
||||
);
|
||||
}
|
||||
|
||||
// Restore storage (runs in browser context)
|
||||
|
||||
Reference in New Issue
Block a user