diff --git a/AGENTS.md b/AGENTS.md index ee5efaf..a513af9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -586,3 +586,26 @@ const jsonSchema = toJSONSchema(mySchema, { ``` github.md + + + +## Source Code Reference + +Source code for dependencies is available in `opensrc/` for deeper understanding of implementation details. + +See `opensrc/sources.json` for the list of available packages and their versions. + +Use this source code when you need to understand how a package works internally, not just its types/interface. + +### Fetching Additional Source Code + +To fetch source code for a package or repository you need to understand, run: + +```bash +npx opensrc # npm package (e.g., npx opensrc zod) +npx opensrc pypi: # Python package (e.g., npx opensrc pypi:requests) +npx opensrc crates: # Rust crate (e.g., npx opensrc crates:serde) +npx opensrc / # GitHub repo (e.g., npx opensrc vercel/ai) +``` + + \ No newline at end of file diff --git a/playwriter/src/prompt.md b/playwriter/src/prompt.md index 2169d2b..d7264a2 100644 --- a/playwriter/src/prompt.md +++ b/playwriter/src/prompt.md @@ -37,7 +37,7 @@ console.log('url:', page.url()); console.log(await accessibilitySnapshot({ page For visually complex pages (grids, galleries, dashboards), use `screenshotWithAccessibilityLabels({ page })` instead to understand spatial layout. -If nothing changed, try `await page.waitForLoadState('networkidle', {timeout: 3000})` or you may have clicked the wrong element. +If nothing changed, try `await waitForPageLoad({ page, timeout: 3000 })` or you may have clicked the wrong element. ## accessibility snapshots diff --git a/playwriter/src/resource.md b/playwriter/src/resource.md index 782ed46..309f452 100644 --- a/playwriter/src/resource.md +++ b/playwriter/src/resource.md @@ -26,7 +26,7 @@ console.log('Heading text:', headingText) await page.getByRole('button', { name: 'Submit Form' }).click() console.log('Clicked submit button') -await page.waitForLoadState('networkidle') +await waitForPageLoad({ page }) console.log('Form submitted successfully') ``` @@ -74,8 +74,9 @@ await page.locator('//div[@class="content"]') ```javascript await page.goto('https://example.com') -// Wait for network idle (no requests for 500ms) -await page.goto('https://example.com', { waitUntil: 'networkidle' }) +// Wait for page load (smart detection that ignores analytics/ads) +await page.goto('https://example.com', { waitUntil: 'domcontentloaded' }) +await waitForPageLoad({ page }) ``` ### Navigate Back/Forward @@ -345,8 +346,8 @@ await page.waitForFunction( // Wait for navigation await page.waitForURL('**/success') -// Wait for page load -await page.waitForLoadState('networkidle') +// Wait for page load (smart detection that ignores analytics/ads) +await waitForPageLoad({ page }) // Wait for specific condition await page.waitForFunction( diff --git a/playwriter/src/wait-for-page-load.ts b/playwriter/src/wait-for-page-load.ts index 4b84856..ba7ca0a 100644 --- a/playwriter/src/wait-for-page-load.ts +++ b/playwriter/src/wait-for-page-load.ts @@ -131,6 +131,25 @@ export async function waitForPageLoad(options: WaitForPageLoadOptions): Promise< return result } + // Fast path: check immediately first. If already ready, return without waiting. + try { + const firstCheck = await checkPageReady() + if (firstCheck.ready) { + return { + success: true, + readyState: firstCheck.readyState, + pendingRequests: [], + waitTimeMs: Date.now() - startTime, + timedOut: false, + } + } + lastReadyState = firstCheck.readyState + lastPendingRequests = firstCheck.pendingRequests + } catch (e) { + // First check failed, continue with polling + } + + // Not ready yet - wait minWait to let JS settle and catch late-starting requests await sleep(minWait) while (Date.now() - startTime < timeout) { diff --git a/skills/playwriter/SKILL.md b/skills/playwriter/SKILL.md index 2450e80..336c388 100644 --- a/skills/playwriter/SKILL.md +++ b/skills/playwriter/SKILL.md @@ -10,10 +10,12 @@ If `playwriter` command is not found, install globally or use npx/bunx: ```bash npm install -g playwriter@latest # or use without installing: -npx playwriter session new -bunx playwriter session new +npx playwriter@latest session new +bunx playwriter@latest session new ``` +If using npx or bunx always use @latest for the first session command. so we are sure of using the latest version of the package + ### Session management Each session runs in an **isolated sandbox** with its own `state` object. Use sessions to: @@ -132,7 +134,7 @@ console.log('url:', page.url()); console.log(await accessibilitySnapshot({ page For visually complex pages (grids, galleries, dashboards), use `screenshotWithAccessibilityLabels({ page })` instead to understand spatial layout. -If nothing changed, try `await page.waitForLoadState('networkidle', {timeout: 3000})` or you may have clicked the wrong element. +If nothing changed, try `await waitForPageLoad({ page, timeout: 3000 })` or you may have clicked the wrong element. ## accessibility snapshots