hlwhl / webview_cef

WebView for Flutter Desktop Apps using CEF(Chromium Embedded Framework) [Work in Progress]
Apache License 2.0
158 stars 44 forks source link

Response payload (JS answer) in executeJavaScript #94

Closed alldev closed 5 months ago

alldev commented 6 months ago

First of all, I would like to thank you for the great lib you are currently working on. You are doing an awesome job implementing proper WebView for Flutter on desktop platforms.

But unfortunately, I faced an issue. Sometimes, when working with WebView, it is necessary not only to send a JS request but also to receive an answer. And this is the exact case I am currently stuck in.

As for popular WebView library flutter_inappwebview, suitable for Android and iOS, we do have such way:

webViewController.evaluateJavascript(source: '''callSomeJS()''').then((value) {
      // the 'value' is dynamic, we can work with it as with string, parse as json, etc...
      }
});

However, as for webview_cef, I can't see any related feature. Yes, we can use 'then(value)' construction with the 'executeJavaScript'. But this function returns Future<void>, not Future<dynamic>. I didn't succeed rewriting this stuff inside lib either. If I missed something and there is already an opportunity to solve this task, please point me in the right direction. If not, then it would be awesome to implement this feature.

Thanks!

SinyimZhi commented 6 months ago

Well, thank you for your using. I understand that your problem is that you need to set a callback function when actively calling the webview method on the flutter side (or injecting code, data, etc. into the page). "executeJavaScript" returns Future<void> now is because we did't afford the callback at native side, so it will send nothing back.I‘m not sure what type callback params would be returned when i bulit this function.(I wasn't used to the feature of variable type parameters at that time between native side and flutter side) But, i think there is a way can help you to solve this problem.JavascriptChannel is design for JS side call Flutter side, but it can used as what you want to do, it just need some skills to build JS codes. @alldev

SinyimZhi commented 6 months ago

And, i think it's time to me to rebuild 'executeJavaScript' at native side, we have already know about how to handle variable type parameters between native side and flutter side.

alldev commented 6 months ago

Hi, @SinyimZhi, many thanks for your responsiveness. I'm happy to see you have ideas and good will to implement this feature. Tracking JS request response relates to fundamental concepts of working with WebView and therefore much needed. Looking forward to further progress 👍.

Few improvements and webview_cef can become absolutely awesome library with all necessary basic features.

fufylev commented 6 months ago

@SinyimZhi Hi there! Looking forward to fixing this issue. Would be very appreciated for the answer!

SinyimZhi commented 6 months ago

I have been busy with project delivery recently, and this part of the work is expected to be completed in mid-January next year。

alldev commented 5 months ago

Hey @SinyimZhi, many thanks for implementing console message output, this feature already heavily in use. Glad to see you continue working on webview_cef. One more step on the way of WebView library usefulness and perfection is done.

Waiting a lot for JS request answer tracking feature. Receiving JS callbacks is musthave and so much needed. It will fulfill library as well. Currently I am stuck because our backend sends payload after JS function execution and I need to receive this stuff. With flutter_inappwebview on mobile platforms this process is easy, hope it will be possible also on desktop.

SinyimZhi commented 5 months ago

After studying flutter_inappwebview's interface evaluateJavascript , I think there is currently a misunderstanding about our interface excuteJavaScript. The evaluateJavascript interface is commonly used to make a web page run certain JavaScript functions and return the result. But the excuteJavaScript that we afford is focusing on injecting code,data or something else into web pages, and most of them need not for a return value. For example, we can declare certain functions and variables to certain pages(Injecting JavaScript channels actually relies on it). Based on the above analysis, I cannot transform excuteJavaScript to evaluateJavascript, but I will provide a evaluateJavascript function to make its effect similar to that of the flutter_inappwebview’s evaluateJavascript function, @alldev @fufylev

SinyimZhi commented 5 months ago

And now new newest version has supported evaluateJavascript. @fufylev @alldev