> ## Documentation Index
> Fetch the complete documentation index at: https://intunedhq.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# withNetworkSettledWait

Executes a callback function and waits for network activity to settle before returning.

```typescript theme={null}
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](../functions/waitForDomSettled) when watching **DOM mutations** (elements added/removed/modified, loading spinners, dynamic content injection)

## Examples

<CodeGroup>
  ```typescript Wrapper with Inline Function theme={null}
  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;
  }
  ```

  ```typescript Click Link with Network Wait theme={null}
  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/");

    // Click Object Extractors link and wait for page to load
    await withNetworkSettledWait(
      async (page) => {
        await page.getByText("Object Extractors").click();
      },
      {
        page,
        timeoutInMs: 10000,
        maxInflightRequests: 0,
      }
    );
    // Object Extractors page loaded
    const title = await page.locator("div h2").innerText();
    return title;
  }
  ```
</CodeGroup>

## Arguments

<ResponseField name="callback" type="Function" required>
  The callback function to execute. Receives the page object as parameter
</ResponseField>

<ResponseField name="options" type="Object">
  Configuration options for network monitoring

  <Expandable title="properties" defaultOpen>
    <ResponseField name="options.page" type="Page" required>
      The Playwright page object to monitor for network activity
    </ResponseField>

    <ResponseField name="options.timeoutInMs" type="number">
      Maximum time to wait in milliseconds before timing out. Defaults to 30000
    </ResponseField>

    <ResponseField name="options.maxInflightRequests" type="number">
      Maximum number of pending requests to consider as "settled". Defaults to 0 (waits for all requests to complete)
    </ResponseField>
  </Expandable>
</ResponseField>

## Returns: `Promise<T>`

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