Open BennyKok opened 5 years ago
Good question, I don't know. Does onError
return an error message? The async is a relatively new feature in JavaScript, so it may not be supported by older versions of Android.
Hey man, @evgenyneu I got it working by adding a custom JS interface to the webview
in the webviewwrapper
and callback from my javascript to return the custom value.
I'm glad that you found a solution. 👍
Hey man, @evgenyneu I got it working by adding a custom JS interface to the
webview
in thewebviewwrapper
and callback from my javascript to return the custom value.
Hii Kindly can you share any example how you solved your problem?
@bilalilyas90 Hey, I have the project that I was originally working on GitHub, I basically injected custom js scripts to the web view to interact with the other js scripts and then call back the result via the interface
Setting interface https://github.com/BennyKok/River/blob/14833add1fddf50a81f8f544c5c418e63e5b9f14/app/src/main/java/com/bennyv17/river/activity/RiveScriptPlayground.kt#L84
Injected scripts https://github.com/BennyKok/River/blob/14833add1fddf50a81f8f544c5c418e63e5b9f14/app/src/main/assets/rsrunner2_0.js
@bilalilyas90 Hey, I have the project that I was originally working on GitHub, I basically injected custom js scripts to the web view to interact with the other js scripts and then call back the result via the interface
Setting interface https://github.com/BennyKok/River/blob/14833add1fddf50a81f8f544c5c418e63e5b9f14/app/src/main/java/com/bennyv17/river/activity/RiveScriptPlayground.kt#L84
Injected scripts https://github.com/BennyKok/River/blob/14833add1fddf50a81f8f544c5c418e63e5b9f14/app/src/main/assets/rsrunner2_0.js
@BennyKok Thank you very much for your help ... it helped me a lot. One more question if you can help me in this too ... I want to pass file to javascript method parameter as file but I cannot find a solution how to pass it to a method param just like we pass strings, integers etc in callFunction method last parameter .. Please can you help me in this also?
this is a sample function in javascript receiving a file object async function encryptfile(objFile, r) { //my code here }
now I want to call this from android and pass a file from android to this method which in return will give a blob object
@bilalilyas90 I am not sure if passing a file to the js side will work easily, since I'm not sure if the js runtime in the webview has fs access? What about you reading the file data and passing them as a string/byte etc to the js side?
@bilalilyas90 I am not sure if passing a file to the js side will work easily, since I'm not sure if the js runtime in the webview has fs access? What about you reading the file data and passing them as a string/byte etc to the js side?
@BennyKok Yes I have tried to convert image to base64 and trying to implement it on js side but one issue I have faced here is that if file size is greater than it gives error when passing too long string to the method ... also one main issue now I am facing is a method giving undefined value for crypto ....
var passphrasekey=await window.crypto.subtle.importKey('raw', passphrasebytes, {name: 'PBKDF2'}, false, ['deriveBits']) .catch(function(err){ console.error(err); });
this is the place where I am having following error :
Uncaught (in promise) TypeError: Cannot read property 'importKey' of undefined"
can you help me solve this one too?
@bilalilyas90 from the error, seems like window.crypto.subtle is null
@BennyKok yes this is correct .. and question is this that why is it giving null as it works fine in browsers but here when using js evaluator which uses webview to execute our js code here it couldn't run and give null value ... so how can I solve this issue here ?
@BennyKok Any suggesstion how I can make it work here?
Im not really sure, it could be that window.crypto.subtle is not support in the webview?
Im not really sure, it could be that window.crypto.subtle is not support in the webview?
I think its because of secure contexts in browsers ... I think as we are using local files it doesn't have ssl which causes this issue ... do you have any idea how we can forcefully enable secure contexts in webview so we can run our local scripts as https?
I am trying to pass data to javascript and return the value using
return await sth
in that async function. But I am getting theundefined
valuefor the context, I am using a chatbot library
the result in the
JsCallback
returnedundefined