Make waitUntilLoaded best-effort: one deadline, no throwing, report each signal (#87) - #90
Merged
Merged
Conversation
…ult (#87) kdriver's Tab.waitForReadyState throws TimeoutWaitingForReadyStateException at its cap, so a page whose document fully arrived but whose load event never fires (one sub-resource never answered) made waitUntilLoaded throw instead of returning false. Catch it and report best-effort false, matching the network and DOM waiters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
waitUntilLoaded polls document.readyState itself instead of calling kdriver's waitForReadyState, which checks its cap only between evaluations. All three steps now share the single timeout: the network and DOM waiters get what the readyState poll left, and each is cut off at the deadline, so the call returns within timeout (it took 2x before). A step failing because of the page (a navigation destroying the JS context, a CDP command timeout, an evaluation error) is retried against the new document instead of escaping; only a closed connection throws. It now returns PageLoad (last readyState, networkIdle, domIdle) instead of a Boolean: settled is the old result, and parsed tells a merely busy page apart from a document that never finished parsing, whose capture would be truncated. Capture.kt warns in that case. Tests assert that the Fetch interception actually paused the request and disable it afterwards, and cover a parser-blocked document, a page navigating during the wait, and the shared budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
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.
Fixes #87.
Tab.waitUntilLoaded()threwTimeoutWaitingForReadyStateExceptionwhen a page'sloadevent never fired. For example, one sub-resource the server never answers.It now stays best-effort in every case.
Changes
waitUntilLoadedpollsdocument.readyStateitself instead of calling kdriver'swaitForReadyState.If a step fails because of the page (a navigation destroys the JS context, a CDP command times out, an evaluation errors), it is retried against the new document instead of escaping.
Only a closed browser connection still throws.
The readyState poll and the network and DOM waiters share a single
timeout, and each is cut off at it.Before, the worst case was about 2×
timeout(6 s on a 3 s timeout in the new test).PageLoadresult instead ofBoolean(public API change, API dump updated).It reports the last
readyStateseen and whether the network and DOM went quiet.settledis the old boolean.parsedtells a merely busy page apart from a document that never finished parsing, whose capture would be truncated.Capture.ktwarns in that case.Tests that stall a request via the Fetch domain now assert the request was actually paused and disable interception afterwards.
New tests cover a parser-blocked document (
blocked.html), a page reloading itself during the wait (navigating.html), and the shared budget.The budget test is the one wall-clock assertion: under 4.5 s for a 3 s timeout.
Testing
./gradlew :markanywhere-browse:buildpasses (19 browser tests plusapiCheck), andmarkanywhere-html's test sources compile.Before the fix, the navigation test threw
CDPException: Inspected target navigated or closedand the budget test took 6.07 s.The wait tests passed four times in a row at 3.8–3.9 s for the budget case.
🤖 Generated with Claude Code