-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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] Support calling void and "no return" functions in JS #27094
Open
mattleibow
wants to merge
2
commits into
main
Choose a base branch
from
dev/hybridwebview-void-return
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
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.
Copilot reviewed 4 out of 20 changed files in this pull request and generated 2 comments.
Files not reviewed (16)
- src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/net-tizen/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/net-windows/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/net/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/src/Core/PublicAPI/netstandard/PublicAPI.Unshipped.txt: Language not supported
- src/Controls/tests/DeviceTests/Resources/Raw/HybridTestRoot/index.html: Language not supported
- src/Core/src/PublicAPI/net-android/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/net-ios/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/net-tizen/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/net-windows/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/net/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/netstandard/PublicAPI.Unshipped.txt: Language not supported
- src/Core/src/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt: Language not supported
Comments suppressed due to low confidence (1)
src/Controls/src/Core/HybridWebView/HybridWebView.cs:84
- Ensure that the new method InvokeJavaScriptAsync in HybridWebView is covered by tests.
public async Task InvokeJavaScriptAsync(string methodName, object?[]? paramValues = null, JsonTypeInfo?[]? paramJsonTypeInfos = null)
mattleibow
commented
Jan 13, 2025
mattleibow
changed the title
Support calling void and "no return" functions in JS
[HybridWebView] Support calling void and "no return" functions in JS
Jan 15, 2025
mattleibow
commented
Jan 16, 2025
mattleibow
force-pushed
the
dev/hybridwebview-void-return
branch
from
January 17, 2025 12:35
984dd0e
to
e7ec0f0
Compare
mattleibow
force-pushed
the
dev/hybridwebview-void-return
branch
from
January 17, 2025 18:08
03b2d48
to
b2e89c6
Compare
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.
Description of Change
Currently, the HybridWebView assumes that all functions return a value and immediately tries to deserialize the result.
This PR changes that to first check to see if the value is "null" / "undefined" and then skips the deserialization since those values represent null in .NET.
There is also a new API in the HybridWebView control that provides a way to avoid having to provide a type and type info that will just be ignored.
After this PR, there will be 3 ways to invoke a void function:
hybridWebView.InvokeJavaScriptAsync<TReturn>(name, TReturn info, ...)
This is the current way, we just no longer crash if the return value is null.
hybridWebView.InvokeJavaScriptAsync<TReturn>(name, null, ...)
This is a better way, we allow passing null as the type info, but we still need the generic argument - which can be anything, object, string, etc
hybridWebView.InvokeJavaScriptAsync(name, ...)
This is the new API where it is not generic and does not have a return type info parameter
Issues Fixed
Fixes #26766
Outstanding Work
Since the API can't be changed for .NET 9, we will need to delay the one small part: #27191
Void methods can still be run, just not with the new API.