feat: smart settle detection for CLI --snap#4
Open
404khai wants to merge 1 commit into
Open
Conversation
Replace blind --wait sleeps with deterministic readiness checks (load, network-idle, selector) so dashboard and SPA screenshots capture fully rendered content instead of loading skeletons. Co-authored-by: Cursor <cursoragent@cursor.com>
Greptile SummaryThis PR adds smarter readiness waits for CLI snapshots.
Confidence Score: 4/5The snapshot readiness path needs fixes before merging.
main.swift Important Files Changed
Reviews (1): Last reviewed commit: "feat: add --wait-for settle detection fo..." | Re-trigger Greptile |
Comment on lines
+873
to
+879
| let snapTimeout: TimeInterval = { | ||
| guard let snap = launchOptions.snap else { return 30 } | ||
| switch snap.settle { | ||
| case .sleep: return snap.wait + 15 | ||
| default: return 30 + snap.wait + 5 | ||
| } | ||
| }() |
There was a problem hiding this comment.
Watchdog Starts Before Navigation
This timeout is scheduled from application launch, while runSnapJob only starts after webView(_:didFinish:). With the default --snap path, a page that takes more than about 15 seconds to finish loading now exits with chromeless: --snap timed out before the snapshot wait even starts, even though the previous 30-second watchdog still allowed that navigation.
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
CLI
--snappreviously relied on a blind--waitsleep after navigation finished. That fails for dashboards, charts, and SPAs that keep rendering afterdidFinish— the screenshot captures a loading skeleton instead of the final page.This adds
--wait-forwith three settle modes:loaddocument.readyState === 'complete'(HTML + subresources)network-idlefetch/XHR activity for 500 ms (injected tracker at document start)selector:CSSdocument.querySelectormatches--waitstill adds extra seconds after the condition is met (use--wait 0to skip). Existing behavior is unchanged when--wait-foris omitted.Test Plan
Built with
./build.shon macOS 26 (arm64, 2x Retina):./Chromeless.app/Contents/MacOS/Chromeless --helplists--wait-formodestests/fixtures/chart.htmlwith--wait 0.5→ 9 KB PNG (loading skeleton)--wait-for selector:.chart-ready --wait 0→ 42 KB PNG (rendered chart)https://example.com --wait-for load --wait 0→ snapshot succeeds--snapwithout--wait-forstill uses blind--wait(default 1 s)--wait-fortimes out after 30 s (exit code 4)