Skip to main content
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

callback
Function
required
The callback function to execute. Receives the page object as parameter
options
Object
Configuration options for network monitoring

Returns: Promise<T>

Promise that resolves to the callback’s return value after network settles