Skip to main content

Module settle

Module settle 

Source
Expand description

Wait-for-stability / network-idle settle (capability 6 of the browser-bot spec).

Playwright’s actionability contract is the reference: never act on a half-rendered page. chrome-devtools-mcp’s wait_for only resolves on a specific expected string, so it cannot express “wait until the page stops changing”. Acting on an unsettled SPA poisons the whole observe→act→verify loop (a uid grounded on a mid-render snapshot is stale before the click).

This module synthesizes a settle primitive from a cheap, repeatable probe: document.readyState === "complete" plus a DOM-content signature that must stop changing for a configurable idle window. The decision logic is a pure state machine ([step]) folding one Probe at a time with a caller-supplied dt — no wall-clock — so every transition is exhaustively unit-testable. The async settle driver is thin glue over it: call probe, measure elapsed, fold, sleep, repeat.

Network-idle (counting in-flight requests via list_network_requests) is a planned extension; its live output shape is not yet captured, and guessing it would be the exact fabrication this project guards against. v1 settles on DOM-ready + DOM-stability, which already covers the dominant SPA-render case.

Structs§

Probe
One probe reading of page quiescence.
SettleConfig
Tuning for settle.

Enums§

SettleOutcome
Terminal result of settle.

Functions§

parse_dom_ready
Interpret the output of evaluate_script(() => document.readyState) as DOM-readiness. chrome-devtools-mcp returns the JSON result wrapped in text (verified live: a fenced ```json block containing "complete"); only the "complete" readyState is treated as ready ("loading"/"interactive" are not). Matching the quoted token avoids false positives from surrounding prose.
settle
Drive a settle loop: repeatedly call probe, folding each reading via [step] and sleeping poll_interval between calls, until the page settles or the timeout elapses. dt for each fold is the real elapsed time since the previous probe, so the loop is self-pacing.