perf: smart pre-navigation, DOM-stable waits, in-memory URL tracking#524
Merged
perf: smart pre-navigation, DOM-stable waits, in-memory URL tracking#524
Conversation
…oded 2s wait - Add `getCurrentUrl()` to IPage, Page, and CDPPage to check current browser URL - Skip pre-navigation entirely if the browser is already on the target domain - Remove the hardcoded `page.wait(2)` after pre-navigation — `page.goto()` already includes smart DOM-settle detection via `waitForDomStable`, making the fixed 2-second sleep redundant - Saves ~2s per browser command in the common case (consecutive commands on the same site), and ~1-2s even on cold navigation
For page.wait(N) where N >= 1 second, use DOM MutationObserver-based stability detection instead of a fixed sleep. The original wait time becomes a hard cap, but the call returns as soon as the DOM stops mutating (500ms quiet period). This benefits ~200 hardcoded sleep calls across ~40 adapters without changing any adapter code. A typical page.wait(5) now completes in <1s when the page is already stable, instead of always waiting 5s. Short waits (< 1s) are kept as fixed sleeps — these are typically UI animation delays or anti-bot throttling where DOM-ready is irrelevant.
Replace the sendCommand('exec', 'window.location.href') call with a
local _lastUrl field set during goto(). This eliminates a daemon HTTP
round-trip for the domain check, making isAlreadyOnDomain() zero-cost.
On fresh tabs (about:blank), _lastUrl is null so we correctly fall
through to navigation — no special-casing needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
preNavUrl, skip thegoto()call entirely — avoids unnecessary page reload and DOM-settle round-tripwait(2):page.goto()already includes DOM-stable waiting; the extra 2s sleep was pure wastewait(): waits ≥ 1s now check DOM stability first and resolve as soon as the page settles (up to 5s max), rather than always sleeping the full durationgetCurrentUrl()readsthis._currentUrl(set on everygoto()) instead of issuing a CDP round-trip — zero network overheadTest plan
npx vitest run --project unit --project adapter