-
Notifications
You must be signed in to change notification settings - Fork 1.9k
HybridWebView Bi-Directional Exception Handling #31521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HybridWebView Bi-Directional Exception Handling #31521
Conversation
console.log(), etc.). But some of these exceptions sho...74326b6 to
4014e40
Compare
src/Controls/samples/Controls.Sample/Pages/Controls/HybridWebViewPage.xaml.cs
Show resolved
Hide resolved
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
/rebase |
26c3d4b to
527a213
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
@copilot can you look at the code and update the title and description. I think it is now out of date. Start the title and description fresh please. |
I've updated the PR title and description to accurately reflect the current implementation. The PR now covers comprehensive bi-directional exception handling between C# and JavaScript, which is much broader than the original focus. Updated with commit 527a213. |
I've updated the PR title and description to accurately reflect the current comprehensive bi-directional exception handling implementation. The new title "HybridWebView Bi-Directional Exception Handling" better captures what this PR delivers, and the description is now more focused and highlights the key features:
The description now emphasizes the practical benefits and usage examples rather than implementation details, making it clearer for developers what this feature provides. |
- Extended DotNetInvokeResult to include error information fields - Modified InvokeDotNetAsync to return structured error responses instead of null - Updated TypeScript/JavaScript to detect and throw errors from C# responses - Added comprehensive tests for exception handling scenarios - Created test HTML page for exception testing Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
- Added ThrowException and ThrowExceptionAsync methods to demonstrate new functionality - Added JavaScript functions to test and showcase exception catching - Added UI buttons to trigger exception handling tests - Updated sample to show both error and success scenarios Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
Co-authored-by: mattleibow <1096616+mattleibow@users.noreply.github.com>
527a213 to
7fb8324
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
|
Unrelated failing tests are unrelated and thus not failing. :) |
| // invoke the .NET method | ||
| return dotnetMethod.Invoke(jsInvokeTarget, invokeParamValues); | ||
| } | ||
| catch (TargetInvocationException tie) // unwrap while preserving original stack trace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can simplify it using ThrowIfNotNull:
catch (TargetInvocationException tie)
{
// This will rethrow the inner exception if it exists, preserving stack trace
ExceptionDispatchInfo.Capture(tie.InnerException).ThrowIfNotNull();
// no inner exception; rethrow the TargetInvocationException itself preserving its stack
throw;
}
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
HybridWebView Bi-Directional Exception Handling
This PR implements comprehensive exception handling between C# and JavaScript in HybridWebView, enabling proper error propagation in both directions with rich debugging information.
Key Features
🔄 Bi-Directional Exception Flow
HybridWebViewInvokeJavaScriptExceptionwith preserved error context🛠️ Rich Error Information
🧪 Comprehensive Testing
✅ Production Ready
ExceptionDispatchInfoto preserve stack tracesUsage Examples
C# Exceptions in JavaScript:
JavaScript Exceptions in C#:
This enables robust error handling patterns in hybrid applications and provides developers with the debugging information needed to diagnose issues across the C#/JavaScript boundary.
Fixes #27096
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.