-
Notifications
You must be signed in to change notification settings - Fork 270
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
Webcontainer => Jasonette IPC #164
Comments
@gliechtenstein I'm happy to work on this as I've just done the work on #162 so am in the webview head space atm. |
@maks sounds great! 👍👍 |
This will be implemented per the doc issue: Jasonette/documentation#66 |
@gliechtenstein I've got an initial working implementation: maks@5ed6938 BUT I haven't done the PR yet due to the interface for objects added to a Webview in Android via |
@maks I was thinking about that issue too. I guess we could do that in the worst case, but it feels a bit too inconvenient because then the user would have to write the code in escaped JSON string everytime and it's really cumbersome and not intuitive. Would it be possible to inject an additional javascript on the Android side so that it automatically interprets a JS object into a JSON string before evaluating? |
@gliechtenstein I guess we can load a bit of JS shim code to do this as long as we DONT target The problem with doing the above is we permentantly stop Jasonette from ever targeting Android An alternative to that is to require webcontainer content that wants to use |
@gliechtenstein I saw you merged the iOS implementation for this. Are you ok then for me todo PR with implementation I have for Andriod with the caveat of needing to |
Oops sorry i totally dropped the ball on this one, shouldn't have merged that iOS one before this issue was resolved in this world. Thankfully an API doesn't exist until it's documented so I think we have some room for now.
Could you elaborate a bit on this? Do you mean like injecting some JavaScript into the webview? And how is this different from the JS shim approach? I guess I didn't fully understand the JS shim approach to begin with... |
@gliechtenstein no worries. and then webview-shim.js would expose whatever API we are going to document and the JS code in that would take care of doing anything needed to make it compatible across iOS and ANdroid, eg. needing to |
@maks I think this is kind of related to Jasonette/Jasonette#4 we're discussing. I guess now that we're going to be injecting JS files into JS execution context I guess there's not much holding us back from doing it this way? |
@gliechtenstein no sorry its different, there we are talking about a webview whos content jasonette "controls" whereas here its any html content supplied be the user. |
@maks OK I've just realized my confusion stems from the fact that the anchor tag part of the link you pasted is broken and simply opens up at the top of the https://developer.android.com/reference/android/webkit/WebView.html page. I didn't understand because I didn't realize you were talking about the valueCallback part specifically. Anyway, now that I understand I can make a more constructive comment hopefully. Basically the way I've implemented this logic on iOS side is
Basically iOS has the same challenge as the challenge you brought up for higher version Androids. There is no way to directly make native calls from webview, and this is how we achieve it. And since this problem is not unique to Android, I was thinking maybe we could do the same thing for Android.
How does that sound? |
@gliechtenstein sorry about the broken link. I think we may have our wires crossed here... On Android you can just "native calls" into Java directly. You use addJavascriptInterace() to inject a Java object into the global JS scope of the webview, then html content can call public methods of that object, there is no need at all for the iframe dance you need to use on iOS. BUT there are constraints on the above, one of them is that the public Java methods you expose can only have "primitives" as parameter types, so you can pass in only numbers, strings, booleans but not JS objects. Hence the need to JSON.stringify(). So on Android its very straightforward to inject a Java object named To be honest to my mind this seems like a very small requirement to place on anyone making use of this interface, its just it would be nice for it to be consistent across iOS and Android. |
Will there are any solution to do calls from JS to JASON? |
Should work the same way it works for the iOS branch
Jasonette/JASONETTE-iOS#253
The text was updated successfully, but these errors were encountered: