perf: smart-wait — waitForCapture, wait({ selector }), daemon backoff#527
Merged
perf: smart-wait — waitForCapture, wait({ selector }), daemon backoff#527
Conversation
…nterceptedRequests
…/bloomberg/sinablog
Remove redundant command table (already in docs/adapters/index.md). Keep badges, quick-start, and star history only.
- CDPPage.wait(N>=1) now uses waitForDomStableJs instead of fixed sleep, matching Page.wait() behavior and saving unnecessary idle time - waitForSelectorJs switches from 100ms polling to MutationObserver, resolving instantly when the target element appears in the DOM - Update dom-helpers tests to stub MutationObserver for Node eval context
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
Three-layer performance optimization eliminating unnecessary fixed sleeps:
Layer 1 –
waitForCapture(): NewIPagemethod that pollswindow.__opencli_xhrevery 100ms and resolves as soon as the first network capture arrives (instead of blindwait(N)). Fixes a correctness bug where DOM-stable detection would resolve before the API response arrived. Replaceswait(N)in 7 INTERCEPT adapters (36kr, twitter/followers, twitter/following, twitter/notifications, producthunt) and instepInterceptpipeline step.Layer 2 –
wait({ selector }): ExtendsWaitOptionswithselector?: stringand addswaitForSelectorJs()(pollsquerySelectorevery 100ms). Replaces blindwait(5)React hydration waits in 15 Twitter UI adapters and 8 calls across medium/substack/bloomberg/sinablog.Layer 3 – daemon exponential backoff: Replaces fixed 300ms poll in
_ensureDaemon()with[50, 100, 200, 400, 800, 1500, 3000]backoff — a connected extension is detected ~250ms faster on average.Changes
src/browser/dom-helpers.tswaitForCaptureJs(),waitForSelectorJs()src/types.tsselector?toWaitOptions,waitForCapture()toIPagesrc/browser/page.tswaitForCapture(),wait({ selector })src/browser/cdp.tssrc/pipeline/steps/intercept.tsinstallInterceptor+waitForCapture+getInterceptedRequestswait(N)→waitForCapture(N)wait(5)→wait({ selector: '[data-testid="primaryColumn"]' })wait(N)→wait({ selector, timeout: N })src/browser/mcp.tsTest plan
npx vitest run --project unit --project adapter— 91 files, 707 tests, all passnpx tsc --noEmit— zero type errorswaitForCaptureJsandwaitForSelectorJsindom-helpers.test.ts