-
Notifications
You must be signed in to change notification settings - Fork 42
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
postMessage didn't work in html #79
Comments
@szwang1 jschannel for webview_cef is very similar to webview_flutter, but not really same. we don't need to call postMessage. just use Print("hello-from js") is a true way,when you called it, flutter will print "hello-from js" on console board, and call the jscallback if you set. we can send a callback function use like Print("hello-from js",function abc(e){console.log(e);}) , then you will find 'e' is second param you set at sendJavaScriptChannelCallBack. |
@SinyimZhi > @szwang1 jschannel for webview_cef is very similar to webview_flutter, but not really same. we don't need to call postMessage. just use Print("hello-from js") is a true way,when you called it, flutter will print "hello-from js" on console board, and call the jscallback if you set. we can send a callback function use like Print("hello-from js",function abc(e){console.log(e);}) , then you will find 'e' is second param you set at sendJavaScriptChannelCallBack. yeah! I used Print and it worked before but now nothing happened. No console log and no error. But I found flutter error during macos development below, something wring? Class AXPlatformNodeCocoa is implemented in both /myapppath/Contents/Frameworks/FlutterMacOS.framework/Versions/A/FlutterMacOS (0x109f56fd8) and /myapppath/Contents/Frameworks/Chromium Embedded Framework.framework/Chromium Embedded Framework (0x17f41acc0). One of the two will be used. Which one is undefined. |
@SinyimZhi @hlwhl I am using the latest package of webview_cef on windows ,I tried to post message in JS and get the same error in console "Uncaught ReferenceError: Print is not defined" as shown in the attached snapshot . It would be helpful if you can share code snippet showing how to send message from JS to Flutter and vice versa? Your help is much appreciated. |
@RakshithSarja @szwang1 sry, i was on vacation a while ago. Actually, my code is in example/main.dart. According to the error message, it seems to be a unique issue on the Mac because the v8 engine is not working properly. We will try to fix this issue on Mac, but it may take a lot of time as our technology stack is mostly on Windows and Linux. |
HI @SinyimZhi Thanks for your response. The issue what I am facing is on windows only. |
@RakshithSarja if you change the url , you should excute jschannels or any js code you want to provide to web agin. |
I got same error, and I think this error is came from
|
I have conducted an in-depth investigation into the error message you mentioned and found that the error message may be caused by various issues. 1. As the Pod-related frameworks introduce parameters that are automatically generated, there may be a formatting issue that requires adjustments to the automation script.Reference document:https://developer.apple.com/forums/thread/47579、https://developer.apple.com/forums/thread/698628. |
is there any solution about this issue ,i found same issue on my mac |
请问这个问题修复了嘛,目前我使用了最新代码,js不能通,控制台打印了undefined,我是在windows上 Flutter 3.7.3 • channel stable • https://github.com/flutter/flutter.git |
你这不是没通啊,你没写回调函数啊。。。undifined代表你Print函数没有任何返回值。这个Print函数的功能是在flutter的控制台输出你在js控制台传给Print函数的第一个参数,第二个参数可选参数,是你要在js侧定义的回调函数。sendJavaScriptChannelCallBack传递回去的参数是需要你在js测定义的函数来处理的。你看看我截图里是如何调用Print函数的,我在调用Print函数时也是输出undefined的,我的message输出是我传递的回调函数里的console.log(e)输出的。e就是sendJavaScriptChannelCallBack传递回js侧的参数。 |
|
我研究一下。。 @903531306 |
能分享一下你对插件本身代码的所有改动么?比如一个diff文件或截图。 @903531306 |
webview_textinput 这个文件我目前的flutter的版本低,所有我把这个也屏蔽了 download.cmake 这个文件里边我修改了下载zip的地址, 只是把gitHub的下载下来传到我的文件服务器了,这个应该不影响吧 Flutter 3.7.3 • channel stable • https://github.com/flutter/flutter.git |
你截图的地方影响的,这个是把cef的回调从cef消息循环线程传递到flutter engine线程的PostMessage.因为flutter官方不建议method channel的invoke在非flutter engine线程调用,所以这里做了个传递。你这行注释掉就没有cef消息循环线程到flutter engine线程间的通讯了 @903531306 这里不应该报错的,你把报错信息详细点的发我看看。 |
不对啊。。看你这个代码不是最新的啊。。。 |
G:\Demo\webview_cef\example\windows\flutter\ephemeral.plugin_symlinks\webview_cef\windows\webview_cef_plugin.cpp(211,73): error C3481: ��hwnd��: δ�ҵ� lambda ������� [G:\Demo\webview_cef\example\build\windows\plugins\webview_cef\webview_cef_plugin.vcxproj] 如果打开屏蔽的代码,就报这个错误 |
我就是github下载最新的,main分支,上周拉的代码 |
我的我的,这台设备上的版本不对,我再看下。。 |
|
是的,是要这么改,我刚也验证了下,这个属于之前合并代码的时候自动合并出的问题,感谢你帮我们找到问题。我把代码推上去吧。 |
好的,感谢帮忙解决问题! |
再次感谢,如果你后续有发现问题并且我们可能没有及时回复,也欢迎你尝试解决并提交PR。 @903531306 |
@uppet 感谢 几乎和我们同时发现并解决了问题。 |
目前我有遇到一个问题,昨天使用github的项目测试js都可以了, 依赖方式: 我在控制台输入 Print ReferenceError: Printis not defined 没有报这个错误,说明也是注册成功的,但是目前就是没有回调。 |
我找到问题了,在main里边有加这一段代码,应该在文档要注明下,
|
是的要加上,这块我写一下吧 之前是直接在cef事件循环线程直接发methodchannel invoke的。 |
我发现如果是同域名的链接,使用同时注入js,_controller2找不到Print,我还试了使用不同的链接注入都可以正常的,这是为啥, |
我研究下,不应该出现这个问题。 |
我尝试调整了setJavaScriptChannels的调用时机,发现可能是由于同时加载两个页面,第二个页面的某些加载流程可能需要等第一个页面完全加载完成才能继续(尤其是第二个页面的url和第一个相同时)。目前我们example的写法并没有等待页面加载完成之后(或者说js引擎加载完成之后)才注入jschannel,实际上是不合适的,建议在onurlchanged的回调里去注入jschannel,这样能保证我们的jschannel注入成功,我这边也会调整example的写法。 |
好的,我试下 |
`
<title>Web</title> <script> function send(){ Print("hello-from js"); // Print.postMessage("hello-from js"); } </script>Web Page
Click the button to send a message to the embedded app:
Send Message ` in flutter,final Set<JavascriptChannel> jsChannels = [ JavascriptChannel( name: 'Print', onMessageReceived: (JavascriptMessage message) { print(message.message); _controller.sendJavaScriptChannelCallBack( false, "{'code':'200','message':'print succeed!'}", message.callbackId, message.frameId); }), ].toSet(); //normal JavaScriptChannels await _controller.setJavaScriptChannels(jsChannels);
if use Print.postMessage, it shows 'Uncaught ReferenceError: Print.postMessage is not defined'
if use Print("hello-from js"), nothing happened.
so how to call js in flutter?
The text was updated successfully, but these errors were encountered: