use waitForPageLoad inall examples
This commit is contained in:
@@ -586,3 +586,26 @@ const jsonSchema = toJSONSchema(mySchema, {
|
|||||||
```
|
```
|
||||||
|
|
||||||
github.md
|
github.md
|
||||||
|
|
||||||
|
<!-- opensrc:start -->
|
||||||
|
|
||||||
|
## 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 <package> # npm package (e.g., npx opensrc zod)
|
||||||
|
npx opensrc pypi:<package> # Python package (e.g., npx opensrc pypi:requests)
|
||||||
|
npx opensrc crates:<package> # Rust crate (e.g., npx opensrc crates:serde)
|
||||||
|
npx opensrc <owner>/<repo> # GitHub repo (e.g., npx opensrc vercel/ai)
|
||||||
|
```
|
||||||
|
|
||||||
|
<!-- opensrc:end -->
|
||||||
@@ -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.
|
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
|
## accessibility snapshots
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ console.log('Heading text:', headingText)
|
|||||||
await page.getByRole('button', { name: 'Submit Form' }).click()
|
await page.getByRole('button', { name: 'Submit Form' }).click()
|
||||||
console.log('Clicked submit button')
|
console.log('Clicked submit button')
|
||||||
|
|
||||||
await page.waitForLoadState('networkidle')
|
await waitForPageLoad({ page })
|
||||||
console.log('Form submitted successfully')
|
console.log('Form submitted successfully')
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -74,8 +74,9 @@ await page.locator('//div[@class="content"]')
|
|||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
await page.goto('https://example.com')
|
await page.goto('https://example.com')
|
||||||
// Wait for network idle (no requests for 500ms)
|
// Wait for page load (smart detection that ignores analytics/ads)
|
||||||
await page.goto('https://example.com', { waitUntil: 'networkidle' })
|
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' })
|
||||||
|
await waitForPageLoad({ page })
|
||||||
```
|
```
|
||||||
|
|
||||||
### Navigate Back/Forward
|
### Navigate Back/Forward
|
||||||
@@ -345,8 +346,8 @@ await page.waitForFunction(
|
|||||||
// Wait for navigation
|
// Wait for navigation
|
||||||
await page.waitForURL('**/success')
|
await page.waitForURL('**/success')
|
||||||
|
|
||||||
// Wait for page load
|
// Wait for page load (smart detection that ignores analytics/ads)
|
||||||
await page.waitForLoadState('networkidle')
|
await waitForPageLoad({ page })
|
||||||
|
|
||||||
// Wait for specific condition
|
// Wait for specific condition
|
||||||
await page.waitForFunction(
|
await page.waitForFunction(
|
||||||
|
|||||||
@@ -131,6 +131,25 @@ export async function waitForPageLoad(options: WaitForPageLoadOptions): Promise<
|
|||||||
return result
|
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)
|
await sleep(minWait)
|
||||||
|
|
||||||
while (Date.now() - startTime < timeout) {
|
while (Date.now() - startTime < timeout) {
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ If `playwriter` command is not found, install globally or use npx/bunx:
|
|||||||
```bash
|
```bash
|
||||||
npm install -g playwriter@latest
|
npm install -g playwriter@latest
|
||||||
# or use without installing:
|
# or use without installing:
|
||||||
npx playwriter session new
|
npx playwriter@latest session new
|
||||||
bunx playwriter 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
|
### Session management
|
||||||
|
|
||||||
Each session runs in an **isolated sandbox** with its own `state` object. Use sessions to:
|
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.
|
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
|
## accessibility snapshots
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user