Git Product home page Git Product logo

Comments (9)

flofis avatar flofis commented on August 16, 2024

Hi,
just a quick question regarding this issue.
I am aware of some work in that direction based on windows.external.notify / executeScriptAsync.
(eg https://github.com/daserge/manifold-win10-patch)
Has this enhancement already been merged or is there no interest in this functionality anymore?

from manifoldcordova.

boyofgreen avatar boyofgreen commented on August 16, 2024

Hi Sergey,
We do have a way to add JavaScript to the into the webview now
https://github.com/manifoldjs/ManifoldJS/wiki/Using%20Cordova%20Plugins%20in%20Hosted%20Web%20Apps#importing-scripts
This works on the windows version inside the cordova platforms, is this not what you were looking for? LMK> Jeff

from manifoldcordova.

flofis avatar flofis commented on August 16, 2024

Hi,
sorry to get back to this so late.
What I mean is the following setup for Windows:

  • Content / Scripts that use Cordova Plugin functionality (i.e. only invoke plugin APIs)
  • This is includes via the x-ms-webview object. No Cordova specific code is directly included in the remote content.
  • Cordova itself (and plugin scripts) are included in client mode.
    According to the wiki entry this should be possible, and I have also set up my manifest as required (i.e. by allowing mjs_api_access).

Content displays fine, but then apparently APIs are not accessible within the x-ms-webview object (and also not injected there? I have not been able to absolutely verify this).

Communication from x-ms-webview with the wrapper (where the plugins are available) ought to work via window.external.notify / scriptNotify. At least this is the way things work in the above repo (which btw is not mine ;)).
Among other things this also involves a patched cordova.js (see commit daserge/manifold-win81-patch@e4b0bda).

So at this point I am not sure, if what specically I am attempting to do is just not supported, or not working for some reason.
Is hostedapp-bridge.js supposed to handle i) communication, ii) injection of a suitable cordova.js in the x-ms-webview object?

from manifoldcordova.

boyofgreen avatar boyofgreen commented on August 16, 2024

Hi @flofis What your doing should work fine. There are basically a few steps you'll want to take. In order to be able to access the APIs, you 'll need to enable the access for them:
https://github.com/manifoldjs/ManifoldJS/wiki/Using%20Cordova%20Plugins%20in%20Hosted%20Web%20Apps#enabling-api-access

then, you'll want to identify the js files that you want to inject into the page:
https://github.com/manifoldjs/ManifoldJS/wiki/Using%20Cordova%20Plugins%20in%20Hosted%20Web%20Apps#importing-scripts

These go into your manifest, so when the app is built, it will build out your project with the api access. This allows you to keep all your code inside the package instead of adding to your website. When you launch and the page loades, we'll inject the needed js for both the plugin, and your specified js files. So what your saying should work without issue and you shouldn't need to add in your own js injection. Can you share your manifest?

from manifoldcordova.

flofis avatar flofis commented on August 16, 2024

Hi,
sure, although the manifest only points to an internal staging server for now and the manifest it very bare-bones.

{
"icons": [],
"display": "fullscreen",
"orientation": "any",
"name": "MANIFOLDTEST",
"short_name": "MANIFOLDTESTSHORT",
"start_url": "https://internalteststage.localdomain/application/login",
"mjs_cordova": {
"plugin_mode": "client"
},
"mjs_api_access": [
{ "match": "https://internalteststage.localdomain/*", "platform": "android, ios, windows", "access": "cordova" }
],
"scope": "/"
}

Using this manifest we also get console entries, that basically say that deviceready, etc. have not fired. Presumeably this is a problem since initializationcode in hostedapp-bridge.js does not run?
A very simplified testcase that only uses invokeScriptAsync / window.external.notify works (see attached file [1]). In this example we explicitely trigger deviceready via

var deviceReady = "$(document).trigger('deviceready');";
_mainView.invokeScriptAsync("eval", deviceReady).start();

Is this possibly related to #62 ?

Many thanks for your help

[1]
msxwebviewcommunication.txt

from manifoldcordova.

flofis avatar flofis commented on August 16, 2024

I just realized that hostedapp-bridge.js and its proxy implementation do not make use of scriptNotify for communication at all, but rather use navigationStartingEvent and and pass special URIs of the form
http://.cordova/exec?service=' + service + '&action=' + action + '&args=' + JSON Arguments via window.location.href.

We make use of https://github.com/browserstate/history.js/ and I am not ruling out some weird interaction here...
Are you using this approach to communicate between the webview and native for some specific reason?

from manifoldcordova.

flofis avatar flofis commented on August 16, 2024

Interesting fact: Removing all plugins and readding only the device plugin (for now) gets rid of error messages wrt cordova deviceready not firing etc. In this case also subsequent API access works fine.

I will now gradually readd plugins and look when exactly things break.

from manifoldcordova.

EL-Greco-Domi avatar EL-Greco-Domi commented on August 16, 2024

Hi @boyofgreen
I'm a co-worker of @flofis and we finally got it to work . Maybe an old plugin was taking too long or cordova to initialize correctly, we don't know exactly what went wrong.

Is there a reason you're using navigation and its events to communicate with the wrapper?
I adapted the code to use the "MSWebViewScriptNotify"-Event and window.external.notify() instead and it worked fine for me when adapting the content-URI in the project manifext (.appxmanifest) to allow notifications from our url.

BTW: I noticed that sometimes this content uri was prefilled with "https://internalteststage.localdomain/" which didn't work due to the ''. According to visual studio the wildcard is only allowed for subdomains. Is this an error in the generation of the project?

Cheers,
Domi

from manifoldcordova.

boyofgreen avatar boyofgreen commented on August 16, 2024

Hi domi. I'll expound more when I'm back to my computer but the reason why we went with the navigation event was because the script notify only works with https and we wanted to support http as well

from manifoldcordova.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.