feat(preview): report failed navigations to the MCP tools - #350
Merged
Conversation
A navigation that fails (untrusted certificate, dead port) leaves the
previous document on screen, so the JavaScript status probe cannot see
it and the agent is left guessing. Observe the platform's own navigation
callbacks instead: on macOS add didStart/didFail methods to wry's
navigation delegate class at runtime, on Windows hook WebView2's
NavigationStarting/NavigationCompleted. Keep the last failure per native
webview; preview_status reports it as load_error {url, code, message}
and preview_wait_for fails with it instead of waiting out its timeout.
Reporting only. No TLS bypass, no settings.
Tryanks
force-pushed
the
preview-load-error
branch
from
September 7, 2026 03:16
a28d55b to
656d8fc
Compare
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.
Why
When the preview browser cannot load a page (typically a dev server with a self-signed certificate), WebKit and WebView2 keep the previous document on screen.
preview_statusis computed by JavaScript inside that page, so it keeps reporting the old URL and the agent cannot distinguish "untrusted certificate" from "slow server".preview_wait_forjust burns its timeout.What
crates/ui/src/preview_panel/load_error.rs: keeps the last failed navigation per native webview as{ url, code, message }, cleared when a navigation starts.WryNavigationDelegateimplements neitherdidStartProvisionalNavigationnordidFail(Provisional)Navigation. After the webview is built we add those three methods to its class once viaclass_addMethod(skipping any selector a future wry defines itself), then re-assign the delegate because WKWebView caches the delegate's method set at assignment time.codeis"<NSError.domain> <code>",messageislocalizedDescription,urlcomes fromNSURLErrorFailingURLErrorKey.add_NavigationStarting/add_NavigationCompletedon theICoreWebView2;codeis theWebErrorStatusSDK name such asCertificateIsInvalid. Addswebview2-com(pinned to the version lb-wry resolves) andwindows-coreas optional Windows-target deps.preview_statusmergesload_errorinto its JSON when present.preview_wait_forfails immediately withnavigation to <url> failed: <message> (<code>)when a failure is recorded. tcode-initiated navigations clear the record synchronously so a wait issued right after a navigate cannot trip on the old one.preview_statustool description; open/navigate reply notes mentionload_error.No TLS bypass and no settings. This is reporting only; trusting a dev certificate is still done at the OS level (mkcert or the keychain).
Verification
openssl s_server -www -accept 8443with a fresh self-signed cert, navigated a real webview through the--preview-smokeharness. Recorded:Noneafter the next successful navigation. The temporary probe was removed; the full pre-existing smoke suite passes with the change.cargo clippy --workspace --all-targetsclean,cargo test -p tcode-ui preview(7, incl. 2 new),cargo test -p preview-mcp(4).webview2-com0.38.2 in the registry and modelled on lb-wry's own usage. Needs acargo checkon Windows before trusting it. One known soft spot: the record is keyed by theICoreWebView2raw pointer fromWebViewExtWindows::webview()and from the event sender; these should be the same interface pointer for the same object but that is not a COM guarantee.Touches the same
preview_statusdescription line as #348; expect a one-hunk trivial conflict whichever merges second.