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

# wait_for_dom_settled

<Info>This function has multiple overloads</Info>

<Tabs>
  <Tab title="Direct Function Call (Callable Pattern)">
    Waits for DOM mutations to settle. This helper uses a MutationObserver to monitor DOM changes and waits until the DOM has been stable (no mutations) for the specified settle\_duration.

    ## `wait_for_dom_settled` vs `wait_for_network_settled`

    * Use `wait_for_dom_settled` when watching **DOM mutations** (elements added/removed/modified, loading spinners, dynamic content injection)
    * Use [wait\_for\_network\_settled](../functions/wait_for_network_settled) when watching **network requests** (API calls, form submissions, resource loading)

    ```python theme={null}
    async def wait_for_dom_settled(
        source: Page | Locator,
        *,
        settle_duration: float,
        timeout_s: float,
    ) -> bool
    ```

    This pattern waits for existing DOM changes to complete without triggering any new actions. Useful after navigation or for waiting for animations.

    ## Examples

    <CodeGroup>
      ```python Wait After Navigation theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          # Navigate to page with dynamic content
          await page.goto('https://sandbox.intuned.dev/lists/table')
          # Wait for all DOM mutations to complete
          settled = await wait_for_dom_settled(
              source=page,
              settle_duration=1.0,
              timeout_s=20
          )
          if settled:
              # DOM is stable, safe to extract data
              rows = await page.locator('table tr').all()
              return len(rows)
          return 0
      ```

      ```python Watch Specific Container theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          await page.goto("https://sandbox.intuned.dev/lists/table")
          # Only watch table container (ignore header/footer changes)
          table = page.locator("table")
          settled = await wait_for_dom_settled(
              source=table,
              settle_duration=0.8,
              timeout_s=15,
          )
          if settled:
              # Table has finished loading
              rows = await table.locator('tr').count()
              return rows
          return 0
      ```
    </CodeGroup>

    ## Arguments

    <ResponseField name="source" type="Page | Locator" required>
      Playwright Page or Locator object to monitor for DOM changes. Can be passed as positional or keyword argument. Use Page to monitor entire document, or Locator to watch specific element.
    </ResponseField>

    <ResponseField name="settle_duration" type="float">
      Duration in seconds that the DOM must remain stable (no mutations) to be considered "settled". Defaults to 0.5.
    </ResponseField>

    <ResponseField name="timeout_s" type="float">
      Maximum seconds to wait for DOM to settle before raising an error. Defaults to 30.0.
    </ResponseField>
  </Tab>

  <Tab title="Wrapper Function Pattern">
    Waits for DOM mutations to settle. This helper uses a MutationObserver to monitor DOM changes and waits until the DOM has been stable (no mutations) for the specified settle\_duration.

    ## `wait_for_dom_settled` vs `wait_for_network_settled`

    * Use `wait_for_dom_settled` when watching **DOM mutations** (elements added/removed/modified, loading spinners, dynamic content injection)
    * Use [wait\_for\_network\_settled](../functions/wait_for_network_settled) when watching **network requests** (API calls, form submissions, resource loading)

    ```python theme={null}
    async def wait_for_dom_settled(
        *,
        source: Page | Locator,
        func: Callable[[], Awaitable[Any]],
        settle_duration: float,
        timeout_s: float,
    ) -> Any
    ```

    This pattern executes a function and waits for DOM mutations to settle before returning.

    ## Examples

    <CodeGroup>
      ```python Wrapper with Inline Function theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          await page.goto("https://sandbox.intuned.dev/lists/table")
          # Define action inline
          async def select_card():
              await page.locator("xpath=//button[@id='radix-:r0:-trigger-card']").click()
              return "card selected"
          # Execute and wait for DOM to settle
          result = await wait_for_dom_settled(
              source=page,
              func=select_card,
              settle_duration=1.0,
              timeout_s=15
          )
          return result
      ```

      ```python Wrapper with Specific Element theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          await page.goto("https://sandbox.intuned.dev")
          # Monitor only the data table, not the entire page
          data_table = page.locator("table")
          async def click_list_extractors():
              await page.get_by_text("List Extractors").click()
              return "list extractors clicked"
          await wait_for_dom_settled(
              source=data_table,  # Only watch this element
              func=click_list_extractors,
              settle_duration=0.8,
              timeout_s=10
          )
          # Table has finished updating
          rows = await data_table.locator("tr").count()
          return rows
      ```

      ```python Wrapper with Lambda theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          await page.goto("https://sandbox.intuned.dev/load-more")
          # Quick one-off action
          await wait_for_dom_settled(
              source=page,
              func=lambda: page.locator("main main button").click(),
              settle_duration=0.5,
              timeout_s=10
          )
          # More items loaded
          items = await page.locator(".item").count()
          return items
      ```
    </CodeGroup>

    ## Arguments

    <ResponseField name="source" type="Page | Locator" required>
      Playwright Page or Locator object to monitor for DOM changes. Use Page for entire document, Locator for specific element.
    </ResponseField>

    <ResponseField name="func" type="Callable[[], Any]" required>
      The async function to execute before waiting for DOM to settle. This function should contain the action that triggers DOM changes.
    </ResponseField>

    <ResponseField name="settle_duration" type="float">
      Duration in seconds that the DOM must remain stable (no mutations) to be considered "settled". Defaults to 0.5.
    </ResponseField>

    <ResponseField name="timeout_s" type="float">
      Maximum seconds to wait for DOM to settle before raising an error. Defaults to 30.0.
    </ResponseField>
  </Tab>

  <Tab title="Decorator">
    Waits for DOM mutations to settle. This helper uses a MutationObserver to monitor DOM changes and waits until the DOM has been stable (no mutations) for the specified settle\_duration.

    ## `wait_for_dom_settled` vs `wait_for_network_settled`

    * Use `wait_for_dom_settled` when watching **DOM mutations** (elements added/removed/modified, loading spinners, dynamic content injection)
    * Use [wait\_for\_network\_settled](../functions/wait_for_network_settled) when watching **network requests** (API calls, form submissions, resource loading)

    ```python theme={null}
    def wait_for_dom_settled(
        func: Callable[..., Awaitable[Any]],
    ) -> Callable[..., Awaitable[Any]]
    ```

    This pattern decorates a function to automatically wait for DOM to settle after execution.

    ## Examples

    <CodeGroup>
      ```python Simple Decorator theme={null}
      from typing import TypedDict
      from playwright.async_api import Page
      from intuned_browser import wait_for_dom_settled
      class Params(TypedDict):
          pass
      async def automation(page: Page, params: Params, **_kwargs):
          await page.goto("https://sandbox.intuned.dev/load-more")
          # Decorator without arguments (uses settle_duration=0.5, timeout_s=30.0)
          @wait_for_dom_settled
          async def load_more_content(page):
              await page.locator("main main button").click()
          # Automatically waits for DOM to settle after clicking
          await load_more_content(page)
          # DOM has settled, new content is loaded
      ```
    </CodeGroup>

    ## Arguments

    <ResponseField name="func" type="Callable[[Page], Any] | Callable[[Locator], Any]" required>
      The async function to decorate. Must accept a Page or Locator object as a parameter. If not provided, returns a parameterized decorator.
    </ResponseField>

    <ResponseField name="settle_duration" type="float">
      Duration in seconds that the DOM must remain stable (no mutations) to be considered "settled". Increase for slow animations. Defaults to 0.5.
    </ResponseField>

    <ResponseField name="timeout_s" type="float">
      Maximum seconds to wait for DOM to settle before timing out. Raises an error if timeout is reached. Defaults to 30.0.
    </ResponseField>
  </Tab>
</Tabs>

## Returns: `bool`

True if DOM settled successfully within timeout.

## Raises

### TimeoutError

If DOM doesn't settle within timeout\_s.
