Expose app variable/object to webview JS

Hi there,

Is there any way to expose an object from app javascript to the code inside webview?
Like, if i want to access some functions of FuseJS inside webview code.


See EvaluateJS, which should allow you to do what you’re after.

All the examples show me how to return a variable from webview to app, i need the opposite.
To send an app object to be used inside EvaluateJS, i couldn’t find anything about that.
An way to execute custom JS inside app code from an variable could help me too.

Interesting. It seems to me that the Example on the link I shared does exactly what you’re after: “a way to execute custom JS inside app code from webview”.

First, thanks for your effort on help me.
But we are not there yet. I will show you an example to explain better.

    var vgeoApi = require("FuseJS/GeoLocation");
    module.exports = {
        geoApi: vgeoApi //create an object to be used inside EvaluateJS
<Text Value="webview example" Alignment="Center" />
    <WebView Url="https://www.fusetools.com">
                var position = geoApi.location  // direct access to an app variable object from here????
                // or even access geoApi from a JS inside webview resources or <script>

Would you mind explaining what are you trying to do and why do you think you need what you describe? A particular, detailed use case description might help explain the challenge.

Well… i really wanted the advantages of progressive apps (especially the easiness to update, despite of the slow performance).

And i saw fuse as an alternative to have critical code in native togheter with remote updated areas with less need of performance.

I’ve found this guy doing something similar https://synchro.io/

I was looking at fuse source code, and i think is currently not possible. Is not that hard to implement in android code, in iOS you probaly must use (https://github.com/sua8051/JavaScriptInterface). And i could not find a easy way to translate the JS object to java and then being inserted in the webview context.

Thanks anyway

Yeah, that won’t currently be possible, unfortunately. Fuse excels at delivering excellent performance for OpenGL graphics, and WebView is just a thing that helps solve very particular, limited use cases.

If you want to use a WebView for things it’s not designed to handle in Fuse, you would probably be better off choosing another tool.