Skip to content

perf: smart page settle via DOM stability detection#271

Merged
jackwener merged 1 commit intomainfrom
perf/smart-page-settle
Mar 22, 2026
Merged

perf: smart page settle via DOM stability detection#271
jackwener merged 1 commit intomainfrom
perf/smart-page-settle

Conversation

@jackwener
Copy link
Owner

Changes

  • Replace fixed 1000ms settleMs sleep in goto() with a smart waitForDomStable() method.
  • Uses MutationObserver to detect when the page stops changing (no mutations for 300ms, capped at 3000ms).
  • Reduces daemon startup poll interval from 300ms to 100ms.
  • Applies smart settle to both Page (HTTP/WS daemon) and CDPPage (direct CDP connection).

This significantly speeds up command execution for fast SPA pages (like Twitter, which render in 200ms) by avoiding unnecessary waiting, while still correctly waiting for slower pages to fully render.

Replace fixed settleMs sleep in goto() with MutationObserver-based DOM
stability detection. The page is considered settled when no DOM mutations
occur for quietMs (default 500ms), with settleMs as a hard timeout cap.

Changes:
- Add waitForDomStableJs() shared helper to dom-helpers.ts
- Update Page.goto() and CDPPage.goto() to use smart settle
- No IPage interface changes (implementation detail only)

Key improvements over naive approach:
- Timer starts AFTER MutationObserver.observe() to avoid race condition
- Falls back to sleep(maxMs) if document.body is not available
- Monitors attributes in addition to childList/subtree
- quietMs defaults to 500ms (conservative) for async request buffering
@jackwener jackwener force-pushed the perf/smart-page-settle branch from 59fc888 to 5f3b31c Compare March 22, 2026 16:21
@jackwener jackwener merged commit 4b976da into main Mar 22, 2026
12 checks passed
@jackwener jackwener deleted the perf/smart-page-settle branch March 22, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant