Skip to main content
This function has multiple overloads
Executes a function and waits for network activity to settle before returning. This helper monitors network requests and waits until all network activity has completed.

wait_for_network_settled vs wait_for_dom_settled

  • Use wait_for_network_settled when watching network requests (API calls, form submissions, resource loading)
  • Use wait_for_dom_settled when watching DOM mutations (elements added/removed/modified, loading spinners, dynamic content injection)
async def wait_for_network_settled(
    *,
    page: Page,
    func: Callable[[], Awaitable[Any]],
    timeout_s: int,
    max_inflight_requests: int,
) -> Any
This pattern executes a function and waits for network activity to settle before returning the result of the function.

Examples

from typing import TypedDict
from playwright.async_api import Page
from intuned_browser import wait_for_network_settled
class Params(TypedDict):
    pass
async def automation(page: Page, params: Params, **_kwargs):
    await page.goto('https://sandbox.intuned.dev/infinite-scroll')
    # Execute action and wait for network to settle
    async def scroll_action():
        # scroll to load more content
        await page.evaluate("() => { window.scrollTo(0, document.body.scrollHeight); }")
        return "scrolled"
    result = await wait_for_network_settled(
        page=page,
        func=scroll_action,
        timeout_s=15,
        max_inflight_requests=0
    )
    print(result)  # "scrolled"
    return result

Arguments

page
Page
required
Playwright Page object to monitor network activity on.
func
Callable[[], Any]
required
The async function to execute before waiting for network to settle. This function should contain the action that triggers network requests.
timeout_s
int
Maximum seconds to wait for network to settle. If timeout is reached, logs a warning and continues. Defaults to 30.
max_inflight_requests
int
Maximum number of ongoing requests to consider network as “settled”. Defaults to 0 (waits for all requests).

Returns: Any

The return value of the executed function.