Fix WebResource handler matching/unregister semantics and harden WebView defaults - #57
#57Merged
XuanchenLin merged 1 commit intoJul 13, 2026
masterXuanchenLin/WinFormedge:masterfrom
copilot/analyze-project-issuesXuanchenLin/WinFormedge:copilot/analyze-project-issuesCopy head branch name to clipboard
Merged
Fix WebResource handler matching/unregister semantics and harden WebView defaults#57XuanchenLin merged 1 commit intomasterXuanchenLin/WinFormedge:masterfrom copilot/analyze-project-issuesXuanchenLin/WinFormedge:copilot/analyze-project-issuesCopy head branch name to clipboard
XuanchenLin merged 1 commit into
masterXuanchenLin/WinFormedge:masterfrom
copilot/analyze-project-issuesXuanchenLin/WinFormedge:copilot/analyze-project-issuesCopy head branch name to clipboard
Conversation
Copilot created this pull request from a session on behalf of
XuanchenLin
July 13, 2026 10:07
View session
XuanchenLin
marked this pull request as ready for review
July 13, 2026 10:14
There was a problem hiding this comment.
Pull request overview
This PR improves WinFormedge’s WebResource routing/unregistration correctness, makes WebView2 initialization failures observable to app startup hooks, and hardens default WebView2 security settings while aligning README examples with the current public API entrypoint.
Changes:
- WebResource handler selection now prefers the most specific (longest) path-prefix match; unregister removes all matching handlers and removes filters using each handler’s original
WebResourceContext. - WebView2 initialization is now awaited via
CreateWebView2Async, with captured exceptions surfaced throughStartup.OnApplicationException(...)and via a more descriptiveControlleraccessor. - Security defaults tightened (tracking prevention + reputation checking enabled), and README examples updated to
WinFormedgeApp.CreateAppBuilder().
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/WinFormedge/WebResource/base/WebResourceManager.cs | Fixes handler selection specificity and improves unregister/filter removal behavior. |
| src/WinFormedge/WebResource/base/WebResourceHandler.cs | Hardens 500 responses to avoid leaking exception details. |
| src/WinFormedge/Classes.WebView/WebViewCore.cs | Makes WebView2 initialization awaitable and exceptions observable; updates controller access semantics. |
| src/WinFormedge/Classes.Startup/WinFormedgeApp.cs | Enables tracking prevention by default in environment options. |
| README.md | Updates public docs to the current WinFormedgeApp builder API. |
| src/WinFormedge/README.md | Updates package-level README examples to the current WinFormedgeApp builder API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
78
to
+80
| matchedHandlers = matchedHandlers.Where(x => uri.AbsolutePath.StartsWith(x.Uri.AbsolutePath)); | ||
|
|
||
| var targetHandler = matchedHandlers.OrderBy(x => x.Uri.AbsolutePath.Length).FirstOrDefault(); | ||
| var targetHandler = matchedHandlers.OrderByDescending(x => x.Uri.AbsolutePath.Length).FirstOrDefault(); |
Comment on lines
+163
to
+167
| if (_initialized) | ||
| { | ||
| var url = GetFilterUrl(handler.Scheme, handler.HostName); | ||
| _webView2!.RemoveWebResourceRequestedFilter(url + "*", handler.WebResourceContext); | ||
| } |
Comment on lines
+980
to
983
| catch (Exception) | ||
| { | ||
| args.Response = webview.Environment.CreateWebResourceResponse(null, StatusCodes.Status500InternalServerError, ex.Message, string.Empty); | ||
| args.Response = webview.Environment.CreateWebResourceResponse(null, StatusCodes.Status500InternalServerError, StatusCodes.GetStatusPhrase(StatusCodes.Status500InternalServerError), string.Empty); | ||
|
|
Comment on lines
132
to
+133
| /// <exception cref="NullReferenceException">Thrown if the controller is not initialized.</exception> | ||
| internal CoreWebView2Controller Controller => _controller ?? throw new NullReferenceException(nameof(Controller)); | ||
| internal CoreWebView2Controller Controller => _controller ?? throw new InvalidOperationException("WebView2 controller is not initialized.", _initializationException); |
Comment on lines
+408
to
412
| catch (Exception ex) | ||
| { | ||
| CreateWebView2(); | ||
| _initializationException = ex; | ||
| WinFormedgeApp.Current.Startup?.OnApplicationException(ex); | ||
| } |
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.
This PR addresses multiple correctness and hardening issues in WinFormedge’s WebResource and WebView initialization paths. It fixes incorrect handler resolution/unregistration behavior, makes WebView initialization failures observable, tightens default security posture, and aligns README API examples with the current public entrypoint.
WebResource routing correctness
AbsolutePath) instead of the least specific one./api/vs/api/v1/).WebResource unregister correctness
WebResourceContextinstead of hardcodedAll, preventing stale filters.WebView initialization failure handling
CreateWebView2async voidflow withCreateWebView2Async(Task) and awaited it from handle creation.Startup.OnApplicationException(...).Controlleraccess now throws a descriptiveInvalidOperationExceptionwith captured initialization exception context.Security baseline hardening
CoreWebView2EnvironmentOptions.CoreWebView2Settings.Documentation/API alignment
WinFormedgeApp.CreateAppBuilder()and consistentWinFormedgeAppnaming instead of outdatedFormedgeApp.CreateBuilder()references.