> ## 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.

# Intercept network requests

## Recipe

This recipe shows how to extract data directly from API responses by intercepting network requests. Use Playwright's response listener with [`withNetworkSettledWait`](/automation-sdks/intuned-sdk/typescript/helpers/functions/withNetworkSettledWait) (TypeScript) or [`wait_for_network_settled`](/automation-sdks/intuned-sdk/python/helpers/functions/wait_for_network_settled) (Python).

<CodeGroup dropdown>
  ```typescript TypeScript theme={null}
  import { BrowserContext, Page, Response } from "playwright";
  import { withNetworkSettledWait } from "@intuned/browser";

  let apiData: any[] = [];

  async function handleResponse(response: Response): Promise<void> {
    if (response.url().includes("/rest/v1/consultations")) {
      try {
        apiData = await response.json();
      } catch (e) {
        // Response might not be JSON
      }
    }
  }

  export default async function handler(
    params: any,
    page: Page,
    context: BrowserContext
  ) {
    apiData = [];

    // Listen for responses matching the pattern
    page.on("response", handleResponse);

    // Wait until the page is fully loaded and in the idle state
    await withNetworkSettledWait(
      async (page) => {
        await page.goto('https://sandbox.intuned.dev/consultations/list');
      },
      {
        page,
        timeoutInMs: 20000,
      }
    );
    console.log(`Captured ${apiData.length} consultations from API`);
    return apiData;
  }
  ```

  ```python Python theme={null}
  from playwright.async_api import Page, Response
  from typing import Any, Dict, List
  from intuned_browser import wait_for_network_settled


  api_data: List[Dict[str, Any]] = []


  async def handle_response(response: Response) -> None:
      if "/rest/v1/consultations" in response.url:
          try:
              data = await response.json()
              api_data.clear()
              api_data.extend(data)
          except Exception:
              # Response might not be JSON
              pass


  async def automation(page: Page, params: Dict[str, Any], **_kwargs):
      api_data.clear()

      # Listen for responses matching the pattern
      page.on("response", handle_response)

      # Navigate and wait until the network is settled
      await wait_for_network_settled(
          page=page,
          func=lambda: page.goto("https://sandbox.intuned.dev/consultations/list"),
          timeout_s=20,
      )

      print(f"Captured {len(api_data)} consultations from API")
      return api_data
  ```
</CodeGroup>

## How it works

1. **Set up response listener** — Use `page.on("response", handler)` to listen for network responses.
2. **Filter by URL** — Check if the response URL matches your target API endpoint.
3. **Capture the data** — Parse the JSON response and store it.
4. **Navigate to the page** — The listener captures API calls triggered during page load.

## Related SDK methods

<CardGroup cols={2}>
  <Card title="withNetworkSettledWait (TypeScript)" icon="js" href="/automation-sdks/intuned-sdk/typescript/helpers/functions/withNetworkSettledWait">
    Wait for network to settle (TypeScript)
  </Card>

  <Card title="wait_for_network_settled (Python)" icon="python" href="/automation-sdks/intuned-sdk/python/helpers/functions/wait_for_network_settled">
    Wait for network to settle (Python)
  </Card>

  <Card title="Cookbook (Python)" icon="github" href="https://github.com/Intuned/cookbook/tree/main/python-examples/network-interception">
    Python network interception example in the Intuned Cookbook
  </Card>

  <Card title="Cookbook (TypeScript)" icon="github" href="https://github.com/Intuned/cookbook/tree/main/typescript-examples/network-interception">
    TypeScript network interception example in the Intuned Cookbook
  </Card>
</CardGroup>
