Skip to main content
This function has multiple overloads
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 when watching network requests (API calls, form submissions, resource loading)
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

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

Arguments

source
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.
settle_duration
float
Duration in seconds that the DOM must remain stable (no mutations) to be considered “settled”. Defaults to 0.5.
timeout_s
float
Maximum seconds to wait for DOM to settle before raising an error. Defaults to 30.0.

Returns: bool

True if DOM settled successfully within timeout.

Raises

TimeoutError

If DOM doesn’t settle within timeout_s.