Executes a callback function and waits for network activity to settle before returning.
export declare function withNetworkSettledWait<T>(callback: (page: Page) => Promise<T>,
options?: {
page: Page;
timeoutInMs?: number;
maxInflightRequests?: number;
}): Promise<T>;
withNetworkSettledWait vs waitForDomSettled
- Use
withNetworkSettledWait when watching network requests (API calls, form submissions, resource loading)
- Use waitForDomSettled when watching DOM mutations (elements added/removed/modified, loading spinners, dynamic content injection)
Examples
import { withNetworkSettledWait } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";
interface Params {}
export default async function handler(
params: Params,
page: Page,
context: BrowserContext
) {
await page.goto("https://sandbox.intuned.dev/infinite-scroll");
// Execute action and wait for network to settle
const result = await withNetworkSettledWait(
async (page) => {
// scroll to load more content
await page.evaluate(() => {
window.scrollTo(0, document.body.scrollHeight);
});
return "scrolled";
},
{
page,
timeoutInMs: 15000,
maxInflightRequests: 0,
}
);
console.log(result); // "scrolled"
return result;
}
Arguments
The callback function to execute. Receives the page object as parameter
Configuration options for network monitoring
The Playwright page object to monitor for network activity
Maximum time to wait in milliseconds before timing out. Defaults to 30000
options.maxInflightRequests
Maximum number of pending requests to consider as “settled”. Defaults to 0 (waits for all requests to complete)
Returns: Promise<T>
Promise that resolves to the callback’s return value after network settles