Skip to content

fix: wait for DOM readiness after MCP navigation#10

Merged
skulidropek merged 5 commits into
mainfrom
fix/mcp-navigation-dom-ready
May 25, 2026
Merged

fix: wait for DOM readiness after MCP navigation#10
skulidropek merged 5 commits into
mainfrom
fix/mcp-navigation-dom-ready

Conversation

@skulidropek
Copy link
Copy Markdown
Member

Summary

  • make browser_navigate wait until document.body exists and document.readyState is interactive/complete
  • prevent immediate browser_evaluate calls from racing navigation
  • add unit coverage for the navigation readiness predicate

Verification

  • cargo test --locked
  • cargo clippy --locked --all-targets -- -D warnings
  • runtime smoke: /tmp/dg-rust-browser-smoke-202651-proof with MCP/CDP/noVNC/RFB/X11 proof

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 24, 2026

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • docker-git-ui-auth-proof.png is excluded by !**/*.png

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 67949763-0e01-4f28-94f2-d67ac6296cbe

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR adds an explicit post-navigation readiness gate to the CDP-driven browser automation flow. After page navigation, a new polling mechanism waits until the DOM is ready (document.body exists and readyState is interactive or complete) before returning, with a 10-second timeout and detailed error reporting.

Changes

Navigation Readiness Gate

Layer / File(s) Summary
DOM readiness criteria and validation
src/cdp.rs
NAVIGATION_READY_EXPRESSION constant defines a CDP Runtime JavaScript probe returning document.body presence and readyState. navigation_ready() helper interprets the probe result and requires both hasBody=true and readyState being interactive or complete.
Navigation readiness polling with deadline
src/cdp.rs
std::time::Instant import added for deadline tracking. wait_for_navigation_ready() function implements a polling loop that repeatedly evaluates the readiness expression via CDP, sleeps between attempts, and returns a detailed error if the ~10-second deadline is exceeded.
Unit tests for readiness validation
src/cdp.rs
New test validates navigation_ready() correctly gates on both hasBody and readyState, including the critical case where readyState=complete but hasBody=false must still be treated as not ready.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through the DOM today,
Waiting for the page to settle its way,
Body and state must both align—
Ten seconds to find that readiness sign!
With careful polls and errors so clear,
Navigation's now safer, no reason to fear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding DOM readiness waiting after MCP navigation, which aligns with the primary modification in src/cdp.rs.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about DOM readiness checks, race condition prevention, and test coverage additions mentioned in the code summary.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-navigation-dom-ready

Comment @coderabbitai help to get the list of available commands and usage tips.

@skulidropek
Copy link
Copy Markdown
Member Author

skulidropek commented May 25, 2026

AI Session Backup

Commit: 8ce9deb
Status: success
Files: 15 (1.66 MB)
Links: README | Manifest

git status

On branch fix/mcp-navigation-dom-ready
Your branch is up to date with 'origin/fix/mcp-navigation-dom-ready'.

nothing to commit, working tree clean

@skulidropek skulidropek merged commit 3745470 into main May 25, 2026
1 check passed
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