-
Notifications
You must be signed in to change notification settings - Fork 27.7k
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
Allow postMessage to return a JS promise to send a message from JS running in a WebView to the application's Dart code #34594
Comments
Some additional thoughts: Naively I'd think that we want the JS We could potentially have 2 "types" of channels(with/without a return value) but it feels like it complicates the API. We may consider implementing this as helper methods that live outside of WebView/WebViewController and ship the common functionality with the plugin. Another alternative which I think is reasonable is to completely leave it up to the app developers, we can probably provide sample code that can be reused(in this issue/API docs/codelabs). |
While I agree that not having this feature doesn't block any use case, having to use evaluateJavascript every time you need an answer from the Dart side is a bit clunky in my opinion. Having the standard JS promise as an option would make it easier to have a Client <-> Server kind of communication between the Webview and the Dart code. I hope you can work on this issue, it would be really nice for my project! |
+1 I also hope to return promise,I don't want to evaluateJavascript callback function,is there another way todo for now? |
Hey, I understand that this issue might not be of high priority. However, @amirh you wrote:
And I'd just would like to have some pointers on how to do this externally to the webview plugin, I don't really know where to start. Thanks in advance. |
Are there any plans for this to be implemented? I have a use case in our current app which relies on being able to define a Promise visible to JS which should execute Dart code and return the result values in the Promise. That pretty much seems to rely on the ability for There are also other users interested in this. See this StackOverFlow post. In case anyone's interested in implementing this, here are some details that might help —
EDIT: I managed to implement the Promise by combining |
Internal: b/343558780
Currently the way to send a message from JS running in a WebView to the application's Dart code is by calling t JavaScriptChannel's
postMessage
method which has no return value. A response can be sent back from the Dart code to the JS code by calling evaluateJavascript.User's have expressed interest in making it easier to get a response from a
postMessage
, the propose solution would be to have thepostMessage
return a javascript promise and have some convenient wrapper code on the Dart side that takes and return value and callsevaluateJavascript
to complete the returned promise.Not having this feature isn't blocking any use case(users can still explicitly call
evaluateJavascript
to "return" a value, and users an even implement the mechanism described above externally to the webview plugin).Availability of JS Promise
According to https://caniuse.com/#feat=promises promise is available starting iOS 8.0 which is what Flutter supports, and starting Android API 20(which is what webview currently support, though technically we can make it support API 19).
The text was updated successfully, but these errors were encountered: